# SOLVED: Exporting .x files and getting odd rotations in the matrix.

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

## Recommended Posts

Ok, not sure if this belongs in Math and Physics or not because it deals with that and possibly a DirectX problem on my side. Here is the story... The values that are being exported from Max on a model are not accurate when I decompose that matrix. However, they do DISPLAY the model properly, which is why this is even more confusing to me. Say for example I export a rotation value of 45 degrees. The model shows up as intended, but when I do the math to get the rotation out of the matrix it comes back at around 65 degrees. Scale and translation work ok (I just discovered that if there are more than one axis for rotation, the scale also starts to become off), it is only the rotation values that come out differently. It also seems that there is no uniform to how wrong it is, as 90 degree angles are working fine and return the proper value. Any help would be appreciated, especially if anyone has had this problem before. I have tried this on panda and q3d exporters with the same results. EDIT: I just did a couple more tests and figured something out. I am posting my equation for decomposing a matrix in hope somebody will notice something. I also didn't create this function but found it from http://www.robertblum.com/articles/2005/02/14/decomposing-matrices#comments.
void DecomposeMatrix(D3DXVECTOR3 *vRotation, D3DXVECTOR3 *vScaling, D3DXVECTOR3 *vTranslation, D3DXMATRIX *mTransform)
{
//Extract translation from Matrix
vTranslation->x = mTransform->_41;		vTranslation->y = mTransform->_42;		vTranslation->z = mTransform->_43;

//Extract Scale from Matrix
vLength.x = mTransform->_11;			vLength.y = mTransform->_12;			vLength.z = mTransform->_13;
vScaling->z = D3DXVec3Length(&vLength);
vLength.x = mTransform->_21;			vLength.y = mTransform->_22;			vLength.z = mTransform->_23;
vScaling->y = D3DXVec3Length(&vLength);
vLength.x = mTransform->_31;			vLength.y = mTransform->_32;			vLength.z = mTransform->_33;
vScaling->x = D3DXVec3Length(&vLength);

//Extract Rotations from Matrix
vRotation->x = atan2(mTransform->_23 /** vScaling->x*/, mTransform->_33);
vRotation->y = asin(mTransform->_13);
vRotation->z = atan2(mTransform->_12 /** vScaling->y*/, mTransform->_11);
}


In this example I have commented out the scaling factors on x and z. This actually works when there is rotation on only one axis. Once I throw in another axis this fails. However, when the scaling is in and the rotation is at a 90 angle then the value still returns properly. SECOND EDIT: I tried the single axis rotation on the y and it came back horribly inaccurate. Haven't investigated it yet but maybe it will provide some insight. SOLUTION: There were two solutions to finally solve this problem. A) the collision volumes this is happening on needed to be created in the perspective view in Max. B) When decomposing the matrix I changed the it so that now after getting the scale I divide the first row by x, 2nd by y and 3rd by z scales THEN extract the rotations using the trig (and no longer using scale values in those). [Edited by - SweetToothKane on May 2, 2007 4:57:25 PM]

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631434
• Total Posts
3000050
×