Archived

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

Get angles from a MATRIX

This topic is 4985 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

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