Sign in to follow this  

Advanced Animation - problem with body part rotation

Recommended Posts

Sample 4. Working with Skeletal Mesh To rotate a bone you need to use following code: ======================================== // pRootframe = D3DXFRAME_EX root frame pointer D3DXFRAME_EX *Frame = FindFrame(pRootFrame, "Leg"); if (Frame) { // Do something with frame, like changing the // D3DXFRAME_EX::TransformationMatrix to something // you want. For here, let's rotate the bone a little D3DXMatrixRotationY(&Frame−>TransformationMatrix, 1.57f); } ======================================== I add this code to my application, after it I do ======================================== // Rebuild the frame hierarchy transformations if(g_Frame) g_Frame->UpdateHierarchy(); // Rebuild the mesh UpdateMesh(g_Mesh); ======================================== I loaded standart X Object - TINY.X, used this code (different body part name and angle) and my body part made crazy rotation. And it is doesn't matter what body part or angle - the result is the same - body parts rotates in the same crazy way. If anybody can help me, I would be very happy.

Share this post

Link to post
Share on other sites
You can't just set D3DXFRAME::TransformationMatrix to a simple rotation. You need to post-multiply by the bone's bind-pose local transform.

D3DXMATRIX mBoundFrameToBoundParent; // bind-pose local transform
D3DXMATRIX mRotation;

D3DXMatrixRotationY(&mRotation, 1.57f);

D3DXMatrixMultiply(&TransformationMatrix, &mRotation, &mBoundFrameToBoundParent);

See the thread Getting the bind pose on Skinned mesh for information on how to calculate mBoundFrameToBoundParent (Bi) using ID3DXSkinInfo::GetBoneOffsetMatrix.

Hope this saves you and others some time. It took a bit of head-scratching to work out the math because I haven't seen it documented anywhere, though obviously many people must have had to work it out for writing modeling tools, Poser etc. All of the keyframes stored in Tiny.x already have this post-multiplication done, a fact which I hope a next edition of Adams' Advanced Animation might mention. Excellent book notwithstanding this omission.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this