View Full Version : gimbal lock

jrbcast

03-15-2002, 09:45 AM

Hi

I want to rotate a 3D scene In the way it should be using a trackball but using a mouse. I´m sure most of you know whats the gimbal lock problem. I´ve found some papers and a library but it´s not useful for me. Do you know where to find some information that can teach me the math basis of the problem and how to solve it?. I am trying to do it mapping the coordinates of the camera over a virtual sphere without the use of quats but It´s quite difficult. Where can I find a "stupids for" tutorial about this?..

many thanks.

satan

03-15-2002, 04:15 PM

http://www.delphi3d.net/listfiles.php?category=1

jrbcast

03-16-2002, 12:38 AM

Originally posted by satan:

http://www.delphi3d.net/listfiles.php?category=1

thanks a lot. Lets see If I can I achive my objectives...

Gavin

03-16-2002, 03:43 AM

If it is not for 'serious commercial use' then I have (very ugly) but simple bodge.

zeckensack

03-16-2002, 05:00 AM

Assuming that you have a target 'up' vector, you can do a cross product between that and your scene's 'up' vector (prolly (0;1;0)). Normalize the result, that's your rotation axis. Get the angle between the two up vectors. If the angle is very small, don't bother to rotate, as your rotation axis may be very close to (0;0;0) anyway, otherwise that's your rotation angle. Use angle-axis rotation (glRotatef(angle,axis.x,axis.y,axiz.z); or so), using these two results. That should solve gimbal lock.

Or just use quats http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Jambolo

03-17-2002, 11:48 AM

Here is a example of the problem of gimble lock:

0. Stand up if your chair doesn't spin.

1. Pitch your head up 90 degrees. p=90,y=0,r=0. You are looking straight up.

2. Roll CW 90 degrees. p=90,y=0,r=90. You are still looking straight up but now you have turned to the left.

3. Pitch down 90 degrees. p=0, y=0, r=90.

You are now looking to the left with your head straight (as if p=0,y=90,r=0), but according to your Euler angles, you should be looking straight ahead with your head tilted over to the right.

There are two ways to fix this.

1. Use a rotation matrix or quaternions to keep track orientation.

2. Allow only one angle (typically yaw) to go up to (and beyond) +/- 90 degrees.

nickels

03-19-2002, 08:03 AM

I don't agree with the math above, it is like the proof that 1==2, you are 'dividing by zero'.

Yaw is not a defined quantity when pitch = 90 degrees. Therein lies the strangeness.

Theorem: 2 = 1

Proof:

Given: A = B

Multiply by A: A^2 = BA

Subtract B^2: A^2 - B^2 = BA - B^2

Factor: (A + B) (A - B) = B (A - B)

Cancel: (A + B) = B

Substitute: B + B = B

Collect: 2B = B

Cancel: 2 = 1

QED

(Acknowledge Gerry Roach for the proof typing)

[This message has been edited by nickels (edited 03-19-2002).]

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.