# HG changeset patch # User John Tsiombikas # Date 1388136582 -7200 # Node ID 203c11299586e7d97070250c41da2a9c0fe61013 # Parent 9758004136f80cb707c544a3d14f1eae23487c0b set/get currently active animation name and minor enhancements in the example diff -r 9758004136f8 -r 203c11299586 example/test.c --- a/example/test.c Fri Dec 27 10:58:23 2013 +0200 +++ b/example/test.c Fri Dec 27 11:29:42 2013 +0200 @@ -128,6 +128,7 @@ int i; anm_use_animation(root, idx); + anm_set_active_animation_name(root, "walk"); for(i=0; i= 1.0) { t = 1.0; cur_anim = next_anim; @@ -261,6 +268,12 @@ } else { anm_use_animations(root, cur_anim, next_anim, t); } + + printf("transitioning from \"%s\" to \"%s\": %.2f \r", from->name, to->name, t); + if(cur_anim == next_anim) { + putchar('\n'); + } + fflush(stdout); } /* first render a character with bottom-up lazy matrix calculation */ diff -r 9758004136f8 -r 203c11299586 src/anim.c --- a/src/anim.c Fri Dec 27 10:58:23 2013 +0200 +++ b/src/anim.c Fri Dec 27 11:29:42 2013 +0200 @@ -44,6 +44,8 @@ char *newname = malloc(strlen(name) + 1); if(!newname) return; + strcpy(newname, name); + free(anim->name); anim->name = newname; } @@ -413,6 +415,36 @@ invalidate_cache(node); } +void anm_set_node_active_animation_name(struct anm_node *node, const char *name) +{ + struct anm_animation *anim = anm_get_active_animation(node, 0); + if(!anim) return; + + anm_set_animation_name(anim, name); +} + +void anm_set_active_animation_name(struct anm_node *node, const char *name) +{ + struct anm_node *child; + + anm_set_node_active_animation_name(node, name); + + child = node->child; + while(child) { + anm_set_active_animation_name(child, name); + child = child->next; + } +} + +const char *anm_get_active_animation_name(struct anm_node *node) +{ + struct anm_animation *anim = anm_get_active_animation(node, 0); + if(anim) { + return anim->name; + } + return 0; +} + void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm) { struct anm_animation *anim = anm_get_active_animation(node, 0); diff -r 9758004136f8 -r 203c11299586 src/anim.h --- a/src/anim.h Fri Dec 27 10:58:23 2013 +0200 +++ b/src/anim.h Fri Dec 27 11:29:42 2013 +0200 @@ -128,6 +128,14 @@ /* set the extrapolator for the (first) currently active animation */ void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex); +/* set the name of the currently active animation of this node only */ +void anm_set_node_active_animation_name(struct anm_node *node, const char *name); +/* recursively set the name of the currently active animation for this node + * and all it's descendants */ +void anm_set_active_animation_name(struct anm_node *node, const char *name); +/* get the name of the currently active animation of this node */ +const char *anm_get_active_animation_name(struct anm_node *node); + void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm); vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm);