views:

598

answers:

2

I making a very simple 3d scene, having 5 points in world coordinates. I'd like to navigate across the scene so I'm defining a camera with both an UP and OUT vector. With this information I generate a rotation matrix in every frame, which I'll apply to the vectors in order to get the camera coordinates.

The question is: I've read about gimbal lock as a problem using this method, but would it happen in this case?

Note that I'm generating the rotation matrix in every frame, and I'm not rotating accumulatively. So could a lock happen in this situation? If that was the case, what would you suggest to safely apply a rotation (from the UP and OUT vectors)?

Thank you

A: 

You will encounter gimbal-lock problem when using matrix-approach to generate rotation matrices (for X,Y,Z) and then multiplying them to get final rotation matrix. If I've understood you will, you use OUT vector to get angles (alpha, beta, gamma), then you are calculating matrices, finally - you multiply them to get final roation matrix - then yes, you will encounter gimbal lock.

One way to get rid of this problem is to use Quaternions for calculations.

Also, here I've found some OpenGL tutorial about how to implement those.

Ravadre
+4  A: 

If by OUT you mean "forward", and this is always perpendicular to the UP vector, then NO, you won't encounter gimbal lock.

What you are doing is creating an orientation matrix from the UP and FORWARD vectors, and applying that each frame, which is a fairly common method for moving a camera in space. You are not applying multiple rotations using euler angles, which can be a cause of gimbal lock.

Note to create the matrix you will also need to create a "left" (or right) vector from the UP and FORWARD vectors. A good introduction to this is here - note that that example does then apply rotations to the camera matrix, which is an entirely optional step.

Wikipedia has a good explanation of gimbal lock.

Justicle
Thanks Justicle, this is exactly what I'm doing. What I call OUT vector is your FORWARD. With this (and applying a cross product to get the third vector) I generate an orthonormal matrix, and multiply to the vectors to get them transformed.Thanks for confirming. I was somehow certain that gimbal lock wouldn't apply in this case, but wanted to make sure, just in case.
Al
No problem, remember its not matrices that cause gimbal lock, but the combination of euler angles - see the wikipedia link.
Justicle