Jump to content
  • Advertisement
Sign in to follow this  

euler to quaternion not working

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

Hi, Trying to convert euler angles to quaternion (see code) but doesn't seem to work properly (a rotation of 90 degrees on any axis rotates an object about ~1 degree, but never more). Can anyone spot an error?
quat EulerToQuat(const float3 &rot)
 const float p = PI / 180;
 float c1, s1, c2, s2, c3, s3, c1c2, s1s2;
 quat q;
 c1 = cos( (rot.y * p) * 0.5f);
 s1 = sin( (rot.y * p) * 0.5f);
 c2 = cos( (rot.x * p) * 0.5f);
 s2 = sin( (rot.x * p) * 0.5f);
 c3 = cos( (rot.z * p) * 0.5f);
 s3 = sin( (rot.z * p) * 0.5f);
 c1c2 = c1 * c2;
 s1s2 = s1 * s2;
 q.w = c1c2 * c3 - s1s2 * s3;
 q.x = c1c2 * s3 + s1s2 * c3;
 q.y = s1 * c2 * c3 + c1 * s2 * s3;
 q.z = c1 * s2 * c3 - s1 * c2 * s3;
 return q;

Share this post

Link to post
Share on other sites

I got the code from this site (nice resource btw):


So I assume the method works correctly. The only thing I added is the conversion of degrees to radians.

Perhaps that's what I'm doing wrong?

* Can someone point me to a piece of code that does the conversion and also takes in account singularities?

[Edited by - remdul on May 20, 2006 7:50:31 AM]

Share this post

Link to post
Share on other sites
Ack, I've got it solved. It was caused by an unrelated problem (some mixup in my matrix class).

The code I posted above is correct though.

As far as singularities concerned...doesn't seem to be a problem either.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!