libanim

changeset 6:b3312cf87715

fixed a bug in the manual slerping in anm_get_node_rotation
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 01 Mar 2013 08:21:19 +0200
parents 2cf7284d2bbb
children ffe668a61bca
files src/anim.c src/track.c
diffstat 2 files changed, 30 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/src/anim.c	Wed Feb 27 21:38:33 2013 +0200
     1.2 +++ b/src/anim.c	Fri Mar 01 08:21:19 2013 +0200
     1.3 @@ -200,6 +200,13 @@
     1.4  
     1.5  quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm)
     1.6  {
     1.7 +	/*quat_t q;
     1.8 +	q.x = anm_get_value(node->tracks + ANM_TRACK_ROT_X, tm);
     1.9 +	q.y = anm_get_value(node->tracks + ANM_TRACK_ROT_Y, tm);
    1.10 +	q.z = anm_get_value(node->tracks + ANM_TRACK_ROT_Z, tm);
    1.11 +	q.w = anm_get_value(node->tracks + ANM_TRACK_ROT_W, tm);
    1.12 +	return q;*/
    1.13 +
    1.14  	int idx0, idx1, last_idx;
    1.15  	anm_time_t tstart, tend;
    1.16  	float t, dt;
    1.17 @@ -223,12 +230,29 @@
    1.18  
    1.19  	tstart = track_x->keys[0].time;
    1.20  	tend = track_x->keys[last_idx].time;
    1.21 +
    1.22 +	if(tstart == tend) {
    1.23 +		q.x = track_x->keys[0].val;
    1.24 +		q.y = track_y->keys[0].val;
    1.25 +		q.z = track_z->keys[0].val;
    1.26 +		q.w = track_w->keys[0].val;
    1.27 +		return q;
    1.28 +	}
    1.29 +
    1.30  	tm = anm_remap_time(track_x, tm, tstart, tend);
    1.31  
    1.32  	idx0 = anm_get_key_interval(track_x, tm);
    1.33  	assert(idx0 >= 0 && idx0 < track_x->count);
    1.34  	idx1 = idx0 + 1;
    1.35  
    1.36 +	if(idx0 == last_idx) {
    1.37 +		q.x = track_x->keys[idx0].val;
    1.38 +		q.y = track_y->keys[idx0].val;
    1.39 +		q.z = track_z->keys[idx0].val;
    1.40 +		q.w = track_w->keys[idx0].val;
    1.41 +		return q;
    1.42 +	}
    1.43 +
    1.44  	dt = (float)(track_x->keys[idx1].time - track_x->keys[idx0].time);
    1.45  	t = (float)(tm - track_x->keys[idx0].time) / dt;
    1.46  
     2.1 --- a/src/track.c	Wed Feb 27 21:38:33 2013 +0200
     2.2 +++ b/src/track.c	Fri Mar 01 08:21:19 2013 +0200
     2.3 @@ -284,9 +284,13 @@
     2.4  
     2.5  static anm_time_t remap_repeat(anm_time_t tm, anm_time_t start, anm_time_t end)
     2.6  {
     2.7 -	anm_time_t interv = end - start;
     2.8 -	anm_time_t x = (tm - start) % interv;
     2.9 +	anm_time_t x, interv = end - start;
    2.10  
    2.11 +	if(interv == 0) {
    2.12 +		return start;
    2.13 +	}
    2.14 +
    2.15 +	x = (tm - start) % interv;
    2.16  	if(x < 0) {
    2.17  		x += interv;
    2.18  	}