Hi,
Here the code I use based on this link :
http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
void CQuaternion::ToEulerAngles( float* X, float* Y, float* Z ) const
{
const float SingularityTest = ( x * y ) + ( z * w );
if( SingularityTest > 0.499f )
{
*Y = 2.0f * CMath::ATan2( x, w );
*Z = CMath::HALF_PI;
*X = 0.0f;
}
else if( SingularityTest < -0.499f )
{
*Y = -2.0f * CMath::ATan2( x, w );
*Z = -CMath::HALF_PI;
*X = 0.0f;
}
else
{
const float zz = z * z;
*Y = CMath::ATan2( 2.0f * ( ( y * w ) - ( x * z ) ), 1.0f - 2.0f * ( ( y * y ) - zz ) );
*Z = CMath::ASin( 2.0f * SingularityTest );
*X = CMath::ATan2( 2.0f * ( ( x * w ) - ( y * z ) ), 1.0f - 2.0f * ( ( x * x ) - zz ) );
}
}
Quaternion To Euler is called when gizmo is used to shows the new rotation on the rotation property in the editor.
It's also called when you attach one actor to another since the rotation is transformed to local space.
The problem is it can fastly gives bad result.
There is a fix to have correct result ?
Thanks