Quaternion Problems

I’m trying to use quaternions to rotate my objects in scene coordinates instead of object coordinates (you know, rotate around the Z axis and the X/Y axis is no longer facing the same way).

So basicly what I am doing is converting the yaw/pitch/roll of the object into 3 quaternions, multiplying them together in the order QPitchQYawQRoll, converting the resulting quaternion into an axis angle which I then pass to glRotate. This unfortunately does not solve the problem. Certain rotational combinations work as expected, but others do not. Roll is behaving particularly strangely…is seems to always be off by a little bit unless Pitch and Yaw are both 0. Can anyone help me with this?

-Noah Desch

Check this FAQ:
http://skal.planet-d.net/demo/matrixfaq.htm

And search Gamedev.net for a document called: ‘Quaternion Powers’. Great doc about quaternions…

Check this FAQ:
http://skal.planet-d.net/demo/matrixfaq.htm

And search Gamedev.net for a document called: ‘Quaternion Powers’. Great doc about quaternions…

quaternions don’t eliminate gimbal lock inherently, they just give you a way around it.

if you create a quaternion for each euler angle, multiply the quaternions, then convert back to euler angles, it should be the same as w/o the quaternions, gimbal lock and all.

take ur euler angles and convert them directly to the quaternion or use axis angles:

//-----------------------------------------------------------------------------------------------------------------------------
inline Quaternion Quaternion::FromEulerAngle( const Vector3d& EulerAngle )
{
// cache trig values of half radian values
double cx = cos( EulerAngle.xPi/360 );
double cy = cos( EulerAngle.y
Pi/360 );
double cz = cos( EulerAngle.zPi/360 );
double sx = sin( EulerAngle.x
Pi/360 );
double sy = sin( EulerAngle.yPi/360 );
double sz = sin( EulerAngle.z
Pi/360 );

// cache products
double cc = cxcz;
double cs = cx
sz;
double sc = sxcz;
double ss = sx
sz;

this->w = (cycc) + (syss);
this->x = (cysc) - (sycs);
this->y = (cyss) + (sycc);
this->z = (cycs) - (sysc);

*this = this->Unit( );

return *this;
}

Originally posted by Succinct:
[b]quaternions don’t eliminate gimbal lock inherently, they just give you a way around it.

if you create a quaternion for each euler angle, multiply the quaternions, then convert back to euler angles, it should be the same as w/o the quaternions, gimbal lock and all.

take ur euler angles and convert them directly to the quaternion or use axis angles:
[/b]

So did I get it right… I can avoid gimbal locks by using quaternions and rotating my model using the matrix (glMultMatrix())derived from quaternion (as implemented in many quaternion-examples). o.k.

But can I avoid gimbal locks, if I convert the rotated quaternion to axis vector and angle (angle, vx, vy, vz) and feed this to glRotatef(angle, vx, vy, vz) (when I rotate objects in the scene). According to my initial tests, I have some problems. (this could be due to my poor implementation).

Thanks.

-J.