libanim

changeset 9:710658962108

simplified the matrix calculation and removed two quaternion normalizations that were probably not needed
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 08 Mar 2013 04:54:05 +0200
parents 2fe32e62e2a7
children b408f3f655e9
files src/anim.c
diffstat 1 files changed, 19 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/src/anim.c	Fri Mar 01 09:46:53 2013 +0200
     1.2 +++ b/src/anim.c	Fri Mar 08 04:54:05 2013 +0200
     1.3 @@ -269,6 +269,9 @@
     1.4  	q2.z = track_z->keys[idx1].val;
     1.5  	q2.w = track_w->keys[idx1].val;
     1.6  
     1.7 +	/*q1 = quat_normalize(q1);
     1.8 +	q2 = quat_normalize(q2);*/
     1.9 +
    1.10  	return quat_slerp(q1, q2, t);
    1.11  #endif
    1.12  }
    1.13 @@ -342,32 +345,32 @@
    1.14  
    1.15  void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm)
    1.16  {
    1.17 -	mat4_t tmat, rmat, smat, pivmat, neg_pivmat;
    1.18 +	int i;
    1.19 +	mat4_t rmat;
    1.20  	vec3_t pos, scale;
    1.21  	quat_t rot;
    1.22  
    1.23 -	m4_identity(tmat);
    1.24 -	/*no need to m4_identity(rmat); quat_to_mat4 sets this properly */
    1.25 -	m4_identity(smat);
    1.26 -	m4_identity(pivmat);
    1.27 -	m4_identity(neg_pivmat);
    1.28 -
    1.29  	pos = anm_get_node_position(node, tm);
    1.30  	rot = anm_get_node_rotation(node, tm);
    1.31  	scale = anm_get_node_scaling(node, tm);
    1.32  
    1.33 -	m4_translate(pivmat, node->pivot.x, node->pivot.y, node->pivot.z);
    1.34 -	m4_translate(neg_pivmat, -node->pivot.x, -node->pivot.y, -node->pivot.z);
    1.35 +	m4_set_translation(mat, node->pivot.x, node->pivot.y, node->pivot.z);
    1.36  
    1.37 -	m4_translate(tmat, pos.x, pos.y, pos.z);
    1.38  	quat_to_mat4(rmat, rot);
    1.39 -	m4_scale(smat, scale.x, scale.y, scale.z);
    1.40 +	for(i=0; i<3; i++) {
    1.41 +		mat[i][0] = rmat[i][0];
    1.42 +		mat[i][1] = rmat[i][1];
    1.43 +		mat[i][2] = rmat[i][2];
    1.44 +	}
    1.45 +	/* this loop is equivalent to: m4_mult(mat, mat, rmat); */
    1.46  
    1.47 -	/* ok this would look nicer in C++ */
    1.48 -	m4_mult(mat, pivmat, tmat);
    1.49 -	m4_mult(mat, mat, rmat);
    1.50 -	m4_mult(mat, mat, smat);
    1.51 -	m4_mult(mat, mat, neg_pivmat);
    1.52 +	mat[0][0] *= scale.x; mat[0][1] *= scale.y; mat[0][2] *= scale.z; mat[0][3] += pos.x;
    1.53 +	mat[1][0] *= scale.x; mat[1][1] *= scale.y; mat[1][2] *= scale.z; mat[1][3] += pos.y;
    1.54 +	mat[2][0] *= scale.x; mat[2][1] *= scale.y; mat[2][2] *= scale.z; mat[2][3] += pos.z;
    1.55 +
    1.56 +	m4_translate(mat, -node->pivot.x, -node->pivot.y, -node->pivot.z);
    1.57 +
    1.58 +	/* that's basically: pivot * rotation * translation * scaling * -pivot */
    1.59  }
    1.60  
    1.61  void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm)