Public Group

#### Archived

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

# 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.

## 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 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]

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002295
×