Jump to content
  • Advertisement

Archived

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

nick5454

Get angles from a MATRIX

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

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!