I was wondering if anyone could help with some matrix math. I have a node which is child of a joint node.
I want to change the parent of this node to another joint, but the absolute transformation must stay the same during animations. So I tried:
Code:
Horde3D::setNodeParent(node_gun, node_spine_new);
Then before each render I try to convert coordinates to the new relative position:
Code:
float relMat[16];
float absMat[16];
// get the transformations of the gun node
Horde3D::getNodeTransformMatrices( node_gun, &relMat, &absMat );
Matrix4f mat_gun_rel(relMat);
Matrix4f mat_gun_abs(absMat);
// get the transformations of the old parent spine
Horde3D::getNodeTransformMatrices( node_spine_old, &relMat, &absMat );
Matrix4f mat_spine_old_rel(relMat);
Matrix4f mat_spine_old_abs(absMat);
// get the transformations of the new parent spine
Horde3D::getNodeTransformMatrices( node_spine_new, &relMat, &absMat );
Matrix4f mat_spine_new_rel(relMat);
Matrix4f mat_spine_new_abs(absMat);
// create new relative transformation but keep original position
Matrix4f mat_gun_rel_new = mat_spine_old_rel.inverted() * mat_gun_rel * mat_spine_new_rel;
// set the new transformation to the node
Horde3D::setNodeTransformMatrix( node_gun, mat_gun_rel_new.x );
Now that doesn't work. I've been puzzling a bit on how to do this, or if it's even possible...