Jump to content
  • Advertisement
Sign in to follow this  
lipsryme

Problem with euler to quaternion rotation

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

Basically I've got a GUI where the user can input euler angle rotations in degrees for X, Y and Z (so Pitch, Yaw, Roll).

Then I'm creating a quaternion based of these values with the directx function:

XMQuaternionRotationRollPitchYaw(DegToRad(newRotation.x), DegToRad(newRotation.y), DegToRad(newRotation.z));

 

DegToRad is my own wrapper function that does:

inline float DegToRad(const float& deg)
{
	return float(deg * (PI / 180.0f));
}

 

 

Now the problem I'm having is when inputting 180 degrees as yaw my resulting quaternion looks like this:

{3,49459e-007, 0, 1, 0} (w, z, y, x order)

 

In my application it still works but then I'm writing that out to a text file as a floating point value and after reading it again my rotation gets completely messed up. Which I assume is because of this w-component. Any ideas what's wrong? Is it just a floating point precision problem ?

Edited by lipsryme

Share this post


Link to post
Share on other sites
Advertisement

What is the value after you read it back in? Is it 3.49459 by any chance (which would suggest the read function isn't coping with the exponent part correctly)? What function are you using to read it back in?

 

Note 3.49459e-007 is very close to zero (3.49459 * 10 ^ -7), you could just clamp it to zero using an epsilon before writing it out.

Share this post


Link to post
Share on other sites

The vector it's writing out is actually (0, 1, 0, 0) (xyzw). So it seems like it's already clamping this to zero.

 

Solved: Oh...it seems like there was some part of the code that did not read the w-component, so it was always 1.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!