• 9
• 9
• 9
• 10
• 10

# Advanced Animation - problem with body part rotation

This topic is 4572 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
shouldnt each frame of the animation be stored in the .x file prior to loading, then u manipulate which frame you want displayed at run time? i dunno maybe im chattin s**t

##### Share on other sites
I don't load animation from X file. Just sleketal object - frames (bones) and mesh itself.

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

Regards,