Horde3D
http://horde3d.org/forums/

transformation calculation, change parent keep position
http://horde3d.org/forums/viewtopic.php?f=2&t=505
Page 1 of 1

Author:  jimbo [ 18.09.2008, 08:08 ]
Post subject:  transformation calculation, change parent keep position

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

Author:  Volker [ 18.09.2008, 17:04 ]
Post subject:  Re: transformation calculation, change parent keep position

If you want to keep the previous absolute transformation you should do the following:

Code:

float nodeAbsMat[16];
// get the abs transformation of the node to reparent
Horde3D::getNodeTransformMatrices( node, 0, &nodeAbsMat );

float newParentAbsMat[16];
// get the abs transformation  of the new parent
Horde3D::getNodeTransformMatrices(newParent, 0, &newParentAbsMat);      

// reparent the child
Horde3D::setNodeParent( node, newParent );

// set the new relative transformation of the reparented child
Horde3D::setNodeTransformMatrix( node, (Matrix4f(newParentAbsMat).inverted() * Matrix4f(nodeAbsMat)).x );


I didn't tested it, but if it works, feel free to write a short tutorial page in the wiki about it. I guess it's a common problem, and a nice wiki article could be helpful for other people, too.

Author:  jimbo [ 18.09.2008, 20:44 ]
Post subject:  Re: transformation calculation, change parent keep position

Thanks, but this works only for one animation frame, so the node's parent needs to change back to the former parent again each frame. That's a bit of a problem in my situation. Is there a more "permanent" solution? Reparent once, recalculate transformation each frame?

Author:  swiftcoder [ 18.09.2008, 21:13 ]
Post subject:  Re: transformation calculation, change parent keep position

jimbo wrote:
Thanks, but this works only for one animation frame, so the node's parent needs to change back to the former parent again each frame. That's a bit of a problem in my situation. Is there a more "permanent" solution? Reparent once, recalculate transformation each frame?
What is wrong with reparent once, recalculate once? I don't understand why you would need to do it each frame - once you recalculate and set the transform, it will stay put.

Author:  jimbo [ 18.09.2008, 21:40 ]
Post subject:  Re: transformation calculation, change parent keep position

The animation data provides new transformations for the node each frame, so re-parent once, re-calculate once will only
work for nodes that aren't animated.

Author:  Volker [ 18.09.2008, 22:16 ]
Post subject:  Re: transformation calculation, change parent keep position

Maybe you then should change the animation and not the joint transformations after applying an animation that seems not to fit your needs. Can you describe a little bit more, what you are trying to do?

Author:  AcidFaucet [ 19.09.2008, 00:08 ]
Post subject:  Re: transformation calculation, change parent keep position

If you don't want it to animate then why don't you parent it to the root of the joint tree? Parenting something to a joint obviously should cause children to move with that joint.

An explanation of what you're trying to do (in practice) not in technique would be helpful.

Author:  jimbo [ 19.09.2008, 07:02 ]
Post subject:  Re: transformation calculation, change parent keep position

Ok, it's a bit tricky. My character has a gun, the gun is a child of the main joint (Bip01).
When firing I play an animation that starts at the spine (so this excludes the gun).
I want the gun to animate too, so making it a child of the spine does this, only the relative
transformation to the spine changes the absolute transformation of the gun. Changing the character
and all animations is an option, but then I need to rework/export/convert over 30 files.
So if it's possible to recalculate the relative transformation each frame to the spine joint I would be so happy ;)

Author:  Volker [ 19.09.2008, 07:28 ]
Post subject:  Re: transformation calculation, change parent keep position

Sorry, I can't imagine it. Is the gun at the back or is it attached to the hand? I wonder why it is attached to the main joint or what this main joint is representing. If I have to make something like that, a straight forward approach would be to create an animation including the gun in the modelling software and would just play it like it was exported.
If you reparent the gun, it's relative transformation won't be adjusted if it is not part of the animation. So of course it will be transformed by the animated parent joint (that's why we have the scene graph) and the gun's absolute transformation will change. If you don't want the absolute transformation of the gun to be changed (although I wonder why) you shouldn't parent it to an animated joint node. You could just parent it to the model node.

Author:  kal [ 19.09.2008, 10:21 ]
Post subject:  Re: transformation calculation, change parent keep position

You should attach the gun to the hand bone(or a tag/dummy bone attached to the hand bone). Every game I know do it that way. Sorry I know it is not the answer to your question, but a suggestion

Author:  AcidFaucet [ 19.09.2008, 15:22 ]
Post subject:  Re: transformation calculation, change parent keep position

So is the gun playing an animation also, something sort of like a sync-kill in DoW, only with a gun? I can't get my head around what you're trying to do either.

Author:  jimbo [ 21.09.2008, 07:30 ]
Post subject:  Re: transformation calculation, change parent keep position

I'll be changing the gun to be a child of the right hand, and do a reworking of the animations. Thanks for the help!

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/