libanim
changeset 5:2cf7284d2bbb
added anm_get_node_matrix and anm_get_node_inv_matrix functions to calculate
node matrices without taking the hierarchy into account...
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 27 Feb 2013 21:38:33 +0200 |
parents | 1ce7e250bae3 |
children | b3312cf87715 |
files | src/anim.c src/anim.h |
diffstat | 2 files changed, 46 insertions(+), 26 deletions(-) [+] |
line diff
1.1 --- a/src/anim.c Wed Feb 27 20:54:19 2013 +0200 1.2 +++ b/src/anim.c Wed Feb 27 21:38:33 2013 +0200 1.3 @@ -312,6 +312,43 @@ 1.4 return node->pivot; 1.5 } 1.6 1.7 +void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm) 1.8 +{ 1.9 + mat4_t tmat, rmat, smat, pivmat, neg_pivmat; 1.10 + vec3_t pos, scale; 1.11 + quat_t rot; 1.12 + 1.13 + m4_identity(tmat); 1.14 + /*no need to m4_identity(rmat); quat_to_mat4 sets this properly */ 1.15 + m4_identity(smat); 1.16 + m4_identity(pivmat); 1.17 + m4_identity(neg_pivmat); 1.18 + 1.19 + pos = anm_get_node_position(node, tm); 1.20 + rot = anm_get_node_rotation(node, tm); 1.21 + scale = anm_get_node_scaling(node, tm); 1.22 + 1.23 + m4_translate(pivmat, node->pivot.x, node->pivot.y, node->pivot.z); 1.24 + m4_translate(neg_pivmat, -node->pivot.x, -node->pivot.y, -node->pivot.z); 1.25 + 1.26 + m4_translate(tmat, pos.x, pos.y, pos.z); 1.27 + quat_to_mat4(rmat, rot); 1.28 + m4_scale(smat, scale.x, scale.y, scale.z); 1.29 + 1.30 + /* ok this would look nicer in C++ */ 1.31 + m4_mult(mat, pivmat, tmat); 1.32 + m4_mult(mat, mat, rmat); 1.33 + m4_mult(mat, mat, smat); 1.34 + m4_mult(mat, mat, neg_pivmat); 1.35 +} 1.36 + 1.37 +void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm) 1.38 +{ 1.39 + mat4_t tmp; 1.40 + anm_get_node_matrix(node, tmp, tm); 1.41 + m4_inverse(mat, tmp); 1.42 +} 1.43 + 1.44 void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm) 1.45 { 1.46 struct mat_cache *cache = pthread_getspecific(node->cache_key); 1.47 @@ -330,32 +367,7 @@ 1.48 } 1.49 1.50 if(cache->time != tm) { 1.51 - mat4_t tmat, rmat, smat, pivmat, neg_pivmat; 1.52 - vec3_t pos, scale; 1.53 - quat_t rot; 1.54 - 1.55 - m4_identity(tmat); 1.56 - /*no need to m4_identity(rmat); quat_to_mat4 sets this properly */ 1.57 - m4_identity(smat); 1.58 - m4_identity(pivmat); 1.59 - m4_identity(neg_pivmat); 1.60 - 1.61 - pos = anm_get_node_position(node, tm); 1.62 - rot = anm_get_node_rotation(node, tm); 1.63 - scale = anm_get_node_scaling(node, tm); 1.64 - 1.65 - m4_translate(pivmat, node->pivot.x, node->pivot.y, node->pivot.z); 1.66 - m4_translate(neg_pivmat, -node->pivot.x, -node->pivot.y, -node->pivot.z); 1.67 - 1.68 - m4_translate(tmat, pos.x, pos.y, pos.z); 1.69 - quat_to_mat4(rmat, rot); 1.70 - m4_scale(smat, scale.x, scale.y, scale.z); 1.71 - 1.72 - /* ok this would look nicer in C++ */ 1.73 - m4_mult(cache->matrix, pivmat, tmat); 1.74 - m4_mult(cache->matrix, cache->matrix, rmat); 1.75 - m4_mult(cache->matrix, cache->matrix, smat); 1.76 - m4_mult(cache->matrix, cache->matrix, neg_pivmat); 1.77 + anm_get_node_matrix(node, cache->matrix, tm); 1.78 1.79 if(node->parent) { 1.80 mat4_t parent_mat;
2.1 --- a/src/anim.h Wed Feb 27 20:54:19 2013 +0200 2.2 +++ b/src/anim.h Wed Feb 27 21:38:33 2013 +0200 2.3 @@ -95,6 +95,14 @@ 2.4 void anm_set_pivot(struct anm_node *node, vec3_t pivot); 2.5 vec3_t anm_get_pivot(struct anm_node *node); 2.6 2.7 +/* these calculate the matrix and inverse matrix of this node alone */ 2.8 +void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm); 2.9 +void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm); 2.10 + 2.11 +/* These calculate the matrix and inverse matrix of this node taking hierarchy 2.12 + * into account. The results are cached in thread-specific storage and returned 2.13 + * if there's no change in time or tracks from the last query... 2.14 + */ 2.15 void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm); 2.16 void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm); 2.17