libanim

diff src/anim.c @ 43:a720e8d7023d

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
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