libanim

diff example/test.c @ 61:29946a9423a4

implemented high-level animation blending interface
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 30 Dec 2013 15:20:31 +0200
parents 203c11299586
children
line diff
     1.1 --- a/example/test.c	Fri Dec 27 11:29:42 2013 +0200
     1.2 +++ b/example/test.c	Mon Dec 30 15:20:31 2013 +0200
     1.3 @@ -23,7 +23,7 @@
     1.4  	{{0, -2.1, 0},		{0, 1, 0},		{0.8, 2, 0.8},	{1, 0.5, 0.5}},	/* left-lower leg */
     1.5  	{{0, -2.1, 0},		{0, 1, 0},		{0.8, 2, 0.8},	{0.5, 1, 0.5}},	/* right-lower leg */
     1.6  
     1.7 -	{{0, 2.6, 0},		{0, -0.5, 0},	{1.2, 1.2, 1.2},{0, 1, 1}},	/* head */
     1.8 +	{{0, 2.6, 0},		{0, -0.5, 0},	{1.2, 1.2, 1.2},{0, 1, 1}},		/* head */
     1.9  
    1.10  	{{-1.3, 0.4, 0},		{0, 1, 0},		{0.8, 2, 0.8},	{0, 0, 1}},	/* left-upper arm */
    1.11  	{{1.3, 0.4, 0},		{0, 1, 0},		{0.8, 2, 0.8},	{1, 1, 0}},		/* right-upper arm */
    1.12 @@ -253,29 +253,6 @@
    1.13  	glRotatef(cam_phi, 1, 0, 0);
    1.14  	glRotatef(cam_theta, 0, 1, 0);
    1.15  
    1.16 -	/* animation blending if we're in transition */
    1.17 -	if(cur_anim != next_anim) {
    1.18 -		float t = (msec - trans_start_tm) / 1500.0;
    1.19 -
    1.20 -		struct anm_animation *from, *to;
    1.21 -		from = anm_get_animation(root, cur_anim);
    1.22 -		to = anm_get_animation(root, next_anim);
    1.23 -
    1.24 -		if(t >= 1.0) {
    1.25 -			t = 1.0;
    1.26 -			cur_anim = next_anim;
    1.27 -			anm_use_animation(root, cur_anim);
    1.28 -		} else {
    1.29 -			anm_use_animations(root, cur_anim, next_anim, t);
    1.30 -		}
    1.31 -
    1.32 -		printf("transitioning from \"%s\" to \"%s\": %.2f    \r", from->name, to->name, t);
    1.33 -		if(cur_anim == next_anim) {
    1.34 -			putchar('\n');
    1.35 -		}
    1.36 -		fflush(stdout);
    1.37 -	}
    1.38 -
    1.39  	/* first render a character with bottom-up lazy matrix calculation */
    1.40  	glPushMatrix();
    1.41  	glTranslatef(-2.5, 0, 0);
    1.42 @@ -358,8 +335,10 @@
    1.43  		exit(0);
    1.44  
    1.45  	case ' ':
    1.46 +		cur_anim = anm_get_active_animation_index(root, 0);
    1.47  		next_anim = (cur_anim + 1) % 2;
    1.48  		trans_start_tm = glutGet(GLUT_ELAPSED_TIME);
    1.49 +		anm_transition(root, next_anim, trans_start_tm, 1500);
    1.50  		break;
    1.51  	}
    1.52  }