# Get rotation angles from D3DXMATRIX

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

## Recommended Posts

Hi. I have an orientation quaternion from which I extracted the rotation matrix and now I need to get rotation in XYZ euler angles. Is there any way to do it using dx9 math lib? or any other simple way? The code I wrote is:
void GetRotation( D3DXVECTOR3 *angles_out, D3DXQUATERNION *qrot )
{
D3DXQuaternionNormalize(qrot, qrot);
D3DXMATRIX rot;
D3DXMatrixIdentity(&rot);
// Get rotation matrix from this quat
D3DXMatrixRotationQuaternion( &rot, qrot);

// Here finally I need to extract euler angles from "rot" matrix and put it
// into 3D vector(xyz) "angles_out".
}


Any ideas how to do this?

##### Share on other sites
Check the docs at Magic Software. Dave does discuss extracting Euler angles from a rotation matrix. Not DX specific, but doesn't need to be. The only consideration might be the row-wise vs. column-wise orientation, e.g., you might have to take the transpose of the rotation part before applying Dave's formulas.

##### Share on other sites
it is possible to transform a point by a matrix
like this but I am not sure what I should do then.

D3DXVECTOR3 X = D3DXVECTOR3(1,0,0);
D3DXVECTOR3 Y = D3DXVECTOR3(0,1,0);
D3DXVECTOR3 Z = D3DXVECTOR3(0,0,1);

D3DXVec3TransformCoord(&X, &X, &rot); // trnasform 3D point by rotation matrix
D3DXVec3TransformCoord(&Y, &Y, &rot); // trnasform 3D point by rotation matrix
D3DXVec3TransformCoord(&Z, &Z, &rot); // trnasform 3D point by rotation matrix

at this statge I think I rotated each axis by "rot" matrix. but still I dont know how to combine those three 3D vectors into 1 3D vector (xyz) with correct euler angles.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 10
• 9
• 15
• 22