Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: gimbal lock

  1. #1
    Intern Newbie
    Join Date
    Aug 2001
    Location
    Almeria, Spain
    Posts
    34

    gimbal lock

    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.

  2. #2
    Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    377

  3. #3
    Intern Newbie
    Join Date
    Aug 2001
    Location
    Almeria, Spain
    Posts
    34

    Re: gimbal lock

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

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    668

    Re: gimbal lock

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

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,652

    Re: gimbal lock

    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

  6. #6
    Junior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    Belmont, CA, USA
    Posts
    224

    Re: gimbal lock

    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.

  7. #7
    Member Regular Contributor nickels's Avatar
    Join Date
    Feb 2000
    Location
    Colorado
    Posts
    298

    Re: gimbal lock

    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).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •