libanim
changeset 60:8f7193d00555
set/get currently active animation name and minor enhancements in the example
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 27 Dec 2013 11:29:42 +0200 |
parents | dae22390c34c |
children | 29946a9423a4 |
files | example/test.c src/anim.c src/anim.h |
diffstat | 3 files changed, 53 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- a/example/test.c Fri Dec 27 10:58:23 2013 +0200 1.2 +++ b/example/test.c Fri Dec 27 11:29:42 2013 +0200 1.3 @@ -128,6 +128,7 @@ 1.4 int i; 1.5 1.6 anm_use_animation(root, idx); 1.7 + anm_set_active_animation_name(root, "walk"); 1.8 1.9 for(i=0; i<NUM_NODES; i++) { 1.10 anm_set_position(nodes[i], parts[i].pos, 0); 1.11 @@ -192,6 +193,7 @@ 1.12 int i; 1.13 1.14 anm_use_animation(root, idx); 1.15 + anm_set_active_animation_name(root, "jump"); 1.16 1.17 for(i=0; i<NUM_NODES; i++) { 1.18 anm_set_position(nodes[i], parts[i].pos, 0); 1.19 @@ -251,9 +253,14 @@ 1.20 glRotatef(cam_phi, 1, 0, 0); 1.21 glRotatef(cam_theta, 0, 1, 0); 1.22 1.23 + /* animation blending if we're in transition */ 1.24 if(cur_anim != next_anim) { 1.25 float t = (msec - trans_start_tm) / 1500.0; 1.26 1.27 + struct anm_animation *from, *to; 1.28 + from = anm_get_animation(root, cur_anim); 1.29 + to = anm_get_animation(root, next_anim); 1.30 + 1.31 if(t >= 1.0) { 1.32 t = 1.0; 1.33 cur_anim = next_anim; 1.34 @@ -261,6 +268,12 @@ 1.35 } else { 1.36 anm_use_animations(root, cur_anim, next_anim, t); 1.37 } 1.38 + 1.39 + printf("transitioning from \"%s\" to \"%s\": %.2f \r", from->name, to->name, t); 1.40 + if(cur_anim == next_anim) { 1.41 + putchar('\n'); 1.42 + } 1.43 + fflush(stdout); 1.44 } 1.45 1.46 /* first render a character with bottom-up lazy matrix calculation */
2.1 --- a/src/anim.c Fri Dec 27 10:58:23 2013 +0200 2.2 +++ b/src/anim.c Fri Dec 27 11:29:42 2013 +0200 2.3 @@ -44,6 +44,8 @@ 2.4 char *newname = malloc(strlen(name) + 1); 2.5 if(!newname) return; 2.6 2.7 + strcpy(newname, name); 2.8 + 2.9 free(anim->name); 2.10 anim->name = newname; 2.11 } 2.12 @@ -413,6 +415,36 @@ 2.13 invalidate_cache(node); 2.14 } 2.15 2.16 +void anm_set_node_active_animation_name(struct anm_node *node, const char *name) 2.17 +{ 2.18 + struct anm_animation *anim = anm_get_active_animation(node, 0); 2.19 + if(!anim) return; 2.20 + 2.21 + anm_set_animation_name(anim, name); 2.22 +} 2.23 + 2.24 +void anm_set_active_animation_name(struct anm_node *node, const char *name) 2.25 +{ 2.26 + struct anm_node *child; 2.27 + 2.28 + anm_set_node_active_animation_name(node, name); 2.29 + 2.30 + child = node->child; 2.31 + while(child) { 2.32 + anm_set_active_animation_name(child, name); 2.33 + child = child->next; 2.34 + } 2.35 +} 2.36 + 2.37 +const char *anm_get_active_animation_name(struct anm_node *node) 2.38 +{ 2.39 + struct anm_animation *anim = anm_get_active_animation(node, 0); 2.40 + if(anim) { 2.41 + return anim->name; 2.42 + } 2.43 + return 0; 2.44 +} 2.45 + 2.46 void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm) 2.47 { 2.48 struct anm_animation *anim = anm_get_active_animation(node, 0);
3.1 --- a/src/anim.h Fri Dec 27 10:58:23 2013 +0200 3.2 +++ b/src/anim.h Fri Dec 27 11:29:42 2013 +0200 3.3 @@ -128,6 +128,14 @@ 3.4 /* set the extrapolator for the (first) currently active animation */ 3.5 void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex); 3.6 3.7 +/* set the name of the currently active animation of this node only */ 3.8 +void anm_set_node_active_animation_name(struct anm_node *node, const char *name); 3.9 +/* recursively set the name of the currently active animation for this node 3.10 + * and all it's descendants */ 3.11 +void anm_set_active_animation_name(struct anm_node *node, const char *name); 3.12 +/* get the name of the currently active animation of this node */ 3.13 +const char *anm_get_active_animation_name(struct anm_node *node); 3.14 + 3.15 void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm); 3.16 vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm); 3.17