Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Quaternion To Euler


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Alundra   Members   -  Reputation: 992

Like
0Likes
Like

Posted 02 August 2014 - 10:23 AM

Hi all,

recently I have added a quaternion to euler to have a visual value of the quaternion but of course the value is not used in game.

Here the code I use :

void CQuaternion::ToEulerAngles( float* X, float* Y, float* Z ) const
{
  const float SingularityTest = x*y + z*w;
  if( SingularityTest > 0.4999995f )
  {
    *Y = 2.0f * CMath::ATan2( x, w );
    *Z = CMath::HALF_PI;
    *X = 0.0f;
  }
  else if( SingularityTest < -0.4999995f )
  {
    *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) );
  }
}

The code is based on this article :

http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/

Is it a correct way to do or a better way exists ?

Thanks for the help



Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS