Camera GimbalLock

Hello.

Which could be the best way to avoid Gimbal Lock.
There is an exemple of how my camera work.

class CCamera
{
private:
  CVector m_Position;  // Camera position
  CVector m_Right;     // Right vector
  CVector m_Up;        // Up vector
  CVector m_Direction; // Direction
  ...    
  ....
  ...... 

  void Move_X( float Speed )
  {
    /* QUESTION : Here, should I save a the 
                  speed value and use it only when 
                  I build up the cam matrix in the 
                  Update() function ?
    */ 

    // X Axis of the camera
    CVector vAxeX;
    vAxeX.Set( m_Right.X(), m_Up.X(), m_Direction.X() ) *= (-Speed);

    // Move along the (local) X axis of the camera 

    m_Position += vAxeX;
  }

  void RotationX( float Degres )
  {
    /* QUESTION : Here, should I save a the 
                  Pitch angle, and use it in the 
                  Update() function when
                  I build up the cam matrix ?
    */ 

    m_Right.RotationX( -Degres ).Normalise();
    m_Up.RotationX( -Degres ).Normalise();
    m_Direction.RotationX( -Degres ).Normalise();
  }

  CMatrix GetMatRotation(void)
  {...} 

  CMatrix GetMatTranslation(void)
  {...}

void Update(void)
{
// Activate the Modelview matrix
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

// Build the new matrix
CMatrix MatCamera;
MatCamera = GetMatTranslation() * GetMatRotation();

// Loading the new matrix
glLoadMatrixf( MatCamera.Inverse() );

}


Should I use Quaternion ?
Cause, Quaternion give me some difficulty to keep my Right, Up, Direction vector working…
Pretend I’m using Quaternion, I should use EULER angle to rotation (Pitch, Yaw, Roll).
Create a Quaternion from those value… And build up the new rotation matrix.

Now, pretend I want to implement a LookAt() function,
I will my Right, Up and Direction Vector…
How could I keep those one working ?

When using Quaternion, we always need to convert Matrix
to Quat, Quat to Matrix… Too many calculs

Please Help me.
Martin

[This message has been edited by Erakis (edited 10-08-2002).]

If you want to avoid gimbal lock, you must apply changes to the orientation as a matrix or a quaternion, not euler angles.

You can store the orientation as euler angles, but then to change the orientation you must: convert to a matrix or quat, apply the changes, then convert back. It’s easier to just store the orientation as a quat or a matrix.

In your case, you are using a matrix - up, dir, and right vectors effectively form a rotation matrix. I don’t think you will have a problem with gimbal lock with your current setup.

[This message has been edited by Jambolo (edited 10-10-2002).]