Sign in to follow this  
Tesserex

[Resolved, basically] Return of the Gimbal Lock!

Recommended Posts

I have, what I think, is a working quaternion camera control. When I fly my spaceship around it has no gimbal lock. To set the camera (in OpenGL) I use gluLookAt. My up and forward vectors are calculated by the following:
up = rotation.Transform(Y_VECT);
forward = rotation.Transform(Z_VECT);
where rotation is a quaternion. The parameters are just basis vectors. My Transform function looks like this. Remember that it does work (it seems):
Vector Transform(Vector v)
{
	Vector nv;
	nv.x = v.x*(w*w + x*x - y*y - z*z) + v.y*(2*x*y - 2*w*z) + v.z*(2*x*z + 2*w*y);
	nv.y = v.x*(2*x*y + 2*w*z) + v.y*(w*w - x*x + y*y - z*z) + v.z*(2*y*z - 2*w*x);
	nv.z = v.x*(2*x*z - 2*w*y) + v.y*(2*y*z + 2*w*x) + v.z*(w*w - x*x - y*y + z*z);
	return nv;
}
Now, is this doing the same thing as that "q*p*q^-1" thing I've seen around? Or is it just coincidence that it works in this case? My actual problem. When I try to use this to modify the vector that controls the camera's view relative to the ship (my "chase" vector) it gets gimbal lock. The quaternion used to rotate is a small constant increment. I make the call:
chasevect = cam_dx.Transform(chasevect);
which I thought would rotate the chase vector by the quaternion cam_dx. It doesn't work. Why? Maybe I'll try the same way as the ship: Instead of incrementing the vector by a constant quaternion, update a new chase quaternion (my function to multiply 2 quaternions I know works) and use the chase quat to transform the original "basis" chase vector. I would think though that the methods should do the same thing. [Edited by - Tesserex on May 5, 2007 8:11:37 PM]

Share this post


Link to post
Share on other sites
I think I'm onto it but I dont know what to do next. When I set the camera parameters, the forward vector is given by the ships rotation.transform(chasevect). However, the up vector is just the basis vector transformed.... Hmm, even if I transform the chase vector instead, the "up" part of the chase is never specified. I'm just asking for gimbal lock here. Right?

Share this post


Link to post
Share on other sites
Nothing you're talking about has anything to do with gimbal lock.

If you're using quaternions to specify rotations, why are you using gluLookAt? Convert the quaternion into a rotation matrix and use that directly.

Share this post


Link to post
Share on other sites
Not to say "I follow exactly what everyone tells me", but the article on a simple quaternion camera uses gluLookAt with quaternions.

update: I have it basically fixed.

Issue 1) I needed to update my camera up vector along with the chase vector.

Issue 2) I can't just transform the basis by the chase quaternion and then the ship quaternion - that causes the gimbal lock. Instead, I needed to multiply the camera (chase) and ship quaternions togther, and then apply that to the basis vectors.

[Edited by - Tesserex on May 5, 2007 8:12:53 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Tesserex
Issue 1) I needed to update my camera up vector along with the chase vector.

Yes, if you're doing it this way. But that's a totally stupid way to do it; you're wasting a large amount of math on finding cross products you already know. Again, just convert the quaternion to a rotation matrix.

Quote:

Issue 2) I can't just transform the basis by the chase quaternion and then the ship quaternion - that causes the gimbal lock.

No, it doesn't. The only thing that causes gimbal lock is euler angles (or similar systems), which you aren't using. You've been misled, and it's likely you're working off a tutorial written by someone who doesn't know what they're talking about.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this