Jump to content
  • Advertisement
Sign in to follow this  

OpenGL 3D Rotations and avoiding Gimble Lock

This topic is 3486 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been having some difficulty with understanding OpenGL rotations; so far the only coordinate system that makes sense to me for rotation is the spherical coordinate system since every point in a sphere can be reached with two types of rotation. Probably this is because I know enough to convert between this and normal XYZ vectors. However, this system doesn't allow me to accomplish what I need. What I am trying to do is cause a directional key stroke or mouse movement to rotate the viewport relative to itself so that no matter which way your are facing, left/right/up/down function the same way. Let's say we have a vector which represents the point on the surface of a sphere where we are looking at. When you LoadIdentity() in OpenGL tutorials an object at (0, 0, -10) is in front of you. It seems the default camera vector is (0, 0, -1), the up vector is (0, 1, 0), and the rotation is (0, 0, 0). As soon as you do any rotations, further rotations along x, y, or z axis no longer work properly (this is a common problem I think). Despite reading some articles on quaternions I can't make enough sense of it to use it. It doesn't seem to solve the underlying problem with rotating relative to the viewport because I still need the coordinates of left/right/up/down relative to the current 4D vector. Some of the confusion is between all these coordinate systems and their rotations; how does a 4D vector rotate? You still have to convert it to an XYZ rotation for OpenGL too. What's a good way to organize this? This is my first thought: 1) Make a Quat with the default camera view 2) Find the Quat representing the top/bottom/left/right of the current viewport 3) Move the Camera Quat towards this new Quat by a certain portion/speed 4) Convert the Quat to some XYZ rotation that OpenGL understands 5) Do the matrix transform then render objects 6) Go back to #2 A code sample that does this, or perhaps a better way to do it, would be appreciated. The underlying math isn't that hard once it's figured out, but it can be hard to conceptualize. [Update] Angle-Axis format is apparently the easier format to understand, and can be converted to quaternions and back. Using a combination of concepts from different sites, I was able to get relative motion working. I still need to find a way to return to a standardized plane, for instance "level off" the ship in a 3D space game. I used these pages as reference: http://www.cprogramming.com/tutorial/3d/quaternions.html http://www.gamedev.net/reference/articles/article1095.asp http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm [Edited by - BinaryAlgorithm on April 30, 2009 12:20:03 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!