Archived

This topic is now archived and is closed to further replies.

nick5454

Get angles from a MATRIX

Recommended Posts

I Have a D3DXMATRIX. I need to grab the x, y, and z angles from this structure so I can determine max tilt. ANyone got a link or know how in DX9? nick

Share this post


Link to post
Share on other sites
Dunno if it completely works, i grabbed that somewhere. Never actually used it.


void COrientation::ToEulerAngles( float& fYaw, float& fPitch, float& fRoll )
{

// rot = cy*cz -cy*sz sy

// cz*sx*sy+cx*sz cx*cz-sx*sy*sz -cy*sx

// -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy


fPitch = asinf( m_matOrientation._31 );
if ( fPitch < D3DX_PI / 2 )
{
if ( fPitch > -D3DX_PI / 2 )
{
fYaw = atan2f( -m_matOrientation._32, m_matOrientation._33 );
fRoll = atan2f( -m_matOrientation._21, m_matOrientation._11 );
}
else
{
// WARNING. Not a unique solution.

float fRmY = atan2f( m_matOrientation._12, m_matOrientation._22 );
fRoll = 0.0; // any angle works

fYaw = fRoll - fRmY;
}
}
else
{
// WARNING. Not a unique solution.

float fRpY = atan2f( m_matOrientation._12, m_matOrientation._22 );//Math::ATan2(m[1][0],m[1][1]);

fRoll = 0.0; // any angle works

fYaw = fRpY - fRoll;
}

fYaw = D3DXToDegree( fYaw );
fPitch = D3DXToDegree( fPitch );
fRoll = D3DXToDegree( fRoll );

}
[source]

Share this post


Link to post
Share on other sites