skeletal animation sort of working

Started by
8 comments, last by supagu 20 years, 3 months ago
well, i have the weights and indices for each vertex being sent to my shader and it all seems to work fine. I have a few issues with getting the matrices right though. What i have for my bones is a position, and angle/rotation the problem is combining these into a matrix, and then combining it with the parent matrix. should it go like for the bones matrix: boneMatrix = translate matrix * rotation matrix boneMatrix = boneMatrix * parent matrix and my position for my bones should be relative to the parent? what if i just used a distance? how would i create a translation from that?
Advertisement
Actually I think you want to do rotation on the left. Translation will most likely always be the last thing you do.

So,

boneMatrix = rotation_matrix * translate_matrix;
boneMatrix = boneMatrix * parent_matrix;

If you are using code from the Advanced animations book, you may have to invert the quaternion rotation when importing it from the x file. If not, forget I said anything. Otherwise refer to the thread "Problems with Advanced Animation Book" or something like that. Search for D3DXQuaternionInverse.

Chris
Chris ByersMicrosoft DirectX MVP - 2005
hrmm im actually not using quaterions.... but maybe i should as nothing i do seems to be working :-/

should the very first bone''s parent be an identity matrix?

the way i have done my shader is to have the shader find the average from the local matrix array, then that is multiplied with the worldViewPorjection matrix, so i dont know if i have to do anything special there?

if i must use quaterions, any tutorials as to what they are how to use them etc?

thanks
*bump* still stuck on this
Don''t use quaternions for this. They are simply an alternative to multiple-axis rotations.

I''m not sure what you mean by taking the average of the local matrix array. Perhaps some code would help, if you can provide it.

Are you loading the mesh from an X-file? Are you updating hierarchies, re-structuring mesh data, etc?

Chris

*Life is like the rock in a sling-shot. Pick a good target, take good aim, and get there as soon as possible!*
Chris ByersMicrosoft DirectX MVP - 2005
no xfile stuffs, i use my own file formats and model formats, and use a shader to do the work.

i managed to get it to sort of work, but rotating a bone causes its vertices to be rotated around the model axis, not the origin of the bone, i tried to do a transform to get them to rotate around the bone, but this does truley weird things.

[cpp]
void Model::UpdateSkeleton()
{
//go through and update all bones
int i = 0;
for( int i = 0; i < boneKeys.size(); i++ )
{
D3DXMATRIXA16 parent;
D3DXMATRIXA16 matRotation;
D3DXMATRIXA16 matTranslation;

Transform();
D3DXMATRIX viewProjection;
viewProjection = matWorld * ENGINE.GetRenderMgr()->GetCamera()->matView * ENGINE.GetRenderMgr()->GetCamera()->matProjection;
//D3DXMatrixTranspose( &viewProjection, &viewProjection] );
KeyFrame boneKey = boneKeys;
Bone boneBone = modelData->skeleton;<br><br><br> if( modelData-&gt;skeleton.parentId != -1 )<br> {<br> parent = boneArray[ modelData-&gt;skeleton.parentId ];<br> }<br> else<br> {<br> D3DXMatrixIdentity( &amp;parent );<br> }<br><br> D3DXMatrixIdentity( &amp;boneArray );<br> //D3DXMatrixTranslation( &amp;matTranslation, modelData-&gt;skeleton.position.x, modelData-&gt;skeleton.position.y, modelData-&gt;skeleton.position.z);<br> //D3DXMatrixTranslation( &amp;matTranslation, 0, 0, 0);<br><br> D3DXMatrixRotationYawPitchRoll( &amp;matRotation, boneKeys.rotation.x, boneKeys.rotation.y, boneKeys.rotation.z);<br><br><br> //D3DXMatrixRotationYawPitchRoll( &amp;matRotation, 0, D3DXToRadian(90), 0);<br> //D3DXMatrixMultiply( &amp;boneArray, &amp;matRotation, &amp;matTranslation );<br> D3DXMatrixMultiply( &amp;boneArray, &amp;boneArray, &amp;matRotation );<br> //D3DXMatrixMultiply( &amp;boneArray, &amp;boneArray, &amp;matWorld );<br> D3DXMatrixMultiply( &amp;boneArray, &amp;boneArray, &amp;parent );<br> }<br><br>}<br>[/cpp]<br><br>thats the code to transform my bones, i do a rotation, and then multiply it with the bones parent. Doing any translation other than 0,0,0 causes weird results.<br> </i>
*bmp* stupid gamedev forgot to login *sigh*
Hi, supagu!
From what I observed, I think you''re not very sure of how to obtain the position of the child bone with respect to the parent bone. In my opinion, this is how you do it.
1. Get the position of the child bone. Let it be vChild.
2. Get the position of the parent bone. Let it be vParent.
3. Get the translation vector. Let it be vTranslate, and so
we have vTranslate = vChild - vParent.
4. Get the translation matrix using vTranslate. Eg. D3DXMatrixTranslation( &matTranslate, vTranslate.x, vTranslate.y, vTranslate.z ). Use this matrix as the child translation matrix.
5. Then, multiply them like what Supernat02 has explained to you.
Hope this helps!
o/QueSerraSerraBoY /
problem is, when i apply any transformation to my bone matrices, i get weird results?!

is there any one that has skinning working with thier own transforms? sure would like to get thier icq and have a chat.
How is your model stored?

If you have one bone per vertex, you can store the vertices in "bone space". Your bone transformation will put it back into model space.

Another method is the have the vertices in model space all the time. This also allows multi-bone influences per vertex.

Now, this step is neglected in almost everything that talks about bones. Your mesh has a certain pose when exported. Record the translation and orientation of each bone in addition to vertex position when it is exported. This is your reference pose. Calculate your bone transform hierarchy for the reference pose. Find and store the inverse of each of these matrices. This is done once, on initialization.

Now, for the actual bone pose (every time you have a new keyframe), calculate the bone transform hierarchy. Multiply each matrix by it''s inversee reference pose matrix. Transpose these, store them in constant registers, and you should be good to go.

I don''t remember off hand which order you should translate or rotate, but it takes seconds to try it the opposite way.

This topic is closed to new replies.

Advertisement