Sign in to follow this  

Quaternion and Matricies

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

(DirectX 9.0 Summer 2004 Update) I am trying to convert a bone offset matrix into scaling, rotation, and transformation and back into a bone offset matrix... the reason is that I am trying to update the bone offset matrix to a new offset matrix using d3dxmatrix3 scalling vector, d3dxquaternion rotation, and d3dxvector3 transformation. To test my code - I am just getting the bone offset matrix (ID3DXSkinInfo::GetBoneOffsetMatrix) and then get the scalling, rotation and transformation info with D3DXMatrixDecompose(). Just to test things out, I use the same information to convert back into a matrix - but the matricies values don't match - here is what I am doing to convert back to the same matrix... D3DXMATRIX matRotation; D3DXMATRIX matScale; D3DXMATRIX matTranslation; // Build Scale Matrix D3DXMatrixScaling( &matScale, vecScale.x, vecScale.y, cScale.z ); // Build Rotation Matrix D3DXQuaternionIdentity( &Quarternion ); D3DXQuaternionRotationAxis( &Quarternion, &vecRotationAxis, fRotationAngle ); D3DXQuaternionNormalize( &Quarternion, &Quarternion ); D3DXMatrixRotationQuaternion( &matRotation, &Quarternion ); D3DXMatrixTranspose( &matRotation, &matRotation ); // Build Translation Matrix D3DXMatrixTranslation( &matTranslation, vecTranslation.x, vecTranslation.y, vecTranslation.z ); // Build new bone Offset Matrix Matrix = matScale * matRotation * matTranslation; Even though the Quaternion and vecScale scale vector and vecTranslation vector match the values returned from D3DXMatrixDecompose() for the bone offset matrix, the bone offset matrix does not match the matrikx that is build up top. I beleive the problem is in the Quaternion. I also tryed using the function: D3DXMATRIX *WINAPI D3DXMatrixTransformation( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pScalingCenter, CONST D3DXQUATERNION *pScalingRotation, CONST D3DXVECTOR3 *pScaling, CONST D3DXVECTOR3 *pRotationCenter, CONST D3DXQUATERNION *pRotation, CONST D3DXVECTOR3 *pTranslation ); But it does not work correctly. How do you transform a rotation Quaternion, scale vector, and transform vector into a matrix?

Share this post


Link to post
Share on other sites
When you decompose a matrix, you get the components in world coordinates- not in the coordinate system you built the matrix in which is relative to that model. I am not sure what the D3DX decompose function does internally but it might be trying to give ya back a rotation matrix rolling back through YPR (yaw - pitch - roll). So anyway the rotation coming back will look different from the rotation you input. It should be the same rotation for the most part.

It's generally just a bad idea to decompose a matrix. What you need is access to the original animation data so you can smoothly lerp between the rotations. But I suppose the D3DX provides good alternatives. you should look at the directx sdk skinning samples. Ya can copy their code verbatim and it should work just fine.

Share this post


Link to post
Share on other sites
I may be missing something but can you not multiply your new matrix with the bone offset matrix? This should give you a relative transform (shouldnt that be ok for tweening?)

Unless you want to make absolute changes in which case you should probably be taking the animation data directly in the first place (as sugested by vajuras)..

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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