vec3_t anm_get_position(struct anm_node *node, anm_time_t tm) { mat4_t xform; vec3_t pos = {0.0, 0.0, 0.0}; if(!node->parent) { return anm_get_node_position(node, tm); } anm_get_matrix(node, xform, tm); return v3_transform(pos, xform); }
void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm) { int i; mat4_t rmat; vec3_t pos, scale; quat_t rot; pos = anm_get_node_position(node, tm); rot = anm_get_node_rotation(node, tm); scale = anm_get_node_scaling(node, tm); m4_set_translation(mat, node->pivot.x, node->pivot.y, node->pivot.z); quat_to_mat4(rmat, rot); for(i=0; i<3; i++) { mat[i][0] = rmat[i][0]; mat[i][1] = rmat[i][1]; mat[i][2] = rmat[i][2]; } /* this loop is equivalent to: m4_mult(mat, mat, rmat); */ mat[0][0] *= scale.x; mat[0][1] *= scale.y; mat[0][2] *= scale.z; mat[0][3] += pos.x; mat[1][0] *= scale.x; mat[1][1] *= scale.y; mat[1][2] *= scale.z; mat[1][3] += pos.y; mat[2][0] *= scale.x; mat[2][1] *= scale.y; mat[2][2] *= scale.z; mat[2][3] += pos.z; m4_translate(mat, -node->pivot.x, -node->pivot.y, -node->pivot.z); /* that's basically: pivot * rotation * translation * scaling * -pivot */ }
vec3_t psys_get_pos(struct psys_emitter *em, float tm) { return anm_get_node_position(&em->prs, ANM_SEC2TM(tm)); }