Horde3D

Next-Generation Graphics Engine
It is currently 22.11.2024, 07:57

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: 18.09.2008, 08:08 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
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...


Top
 Profile  
Reply with quote  
PostPosted: 18.09.2008, 17:04 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
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.


Top
 Profile  
Reply with quote  
PostPosted: 18.09.2008, 20:44 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
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?


Top
 Profile  
Reply with quote  
PostPosted: 18.09.2008, 21:13 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
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.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 18.09.2008, 21:40 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
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.


Top
 Profile  
Reply with quote  
PostPosted: 18.09.2008, 22:16 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
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?


Top
 Profile  
Reply with quote  
PostPosted: 19.09.2008, 00:08 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
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.


Top
 Profile  
Reply with quote  
PostPosted: 19.09.2008, 07:02 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
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 ;)


Top
 Profile  
Reply with quote  
PostPosted: 19.09.2008, 07:28 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
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.


Top
 Profile  
Reply with quote  
PostPosted: 19.09.2008, 10:21 
Offline

Joined: 18.05.2008, 17:47
Posts: 96
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


Top
 Profile  
Reply with quote  
PostPosted: 19.09.2008, 15:22 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
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.


Top
 Profile  
Reply with quote  
PostPosted: 21.09.2008, 07:30 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
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!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Majestic-12 [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group