Problem with euler to quaternion rotation

Started by
1 comment, last by lipsryme 11 years ago

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 ?

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.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

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.

This topic is closed to new replies.

Advertisement