Camera - Rotation Matrix

Hello.

I’m building a camera Class. There, is the private members of the class :

//Camera matrix
MATRIX4 CamMatrix;

// Each axis of the camera
VECTOR3D CamAxisX;
VECTOR3D CamAxisY
VECTOR3D CamAxisZ

// Direction vector
VECTOR3D CamView;

//Position of the camera
VECTTOR3D CamPos

So now I will explain what is my problem.
I want to use my own matrix operation, so I don’t want to use glRotated or glTranslated.
I just need to use a GL command when it time to update the camera so
glLoadMatrix( CamMatrix )

Well, now I have no difficulty with translation along an axis. So I can go UP and DOWN, Straf LEFT to RIGHT or move FORWARD and BACKWARD.

The problem is starting with rotation
I built a function like this one :

Camera::Pitch( float Angle )
{
// Where Angle could be 15°. So add 15°
// to the camera direction (Ex :Look Up)
// I have/want to update the matrix and the
// others members of the class.
// If axis change I need to update it too.
// I know that I need to apply a rotation
// (pitch) around the X axis but how ?
// What I need ? Help please
}

A big Thanks
Martin

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

If you are going to use glLoadMatrix you might as well store your camera orientation in a matrix ( MATRIX4 CamMatrix) and get rid of those VECTOR3D. A 4x4 matrix is composed of the rotation parts and the position so there is no point storing the info twice.

If your Matrix4 class is any good it will have all the rotation functions you need otherwise find a class that does have them.

You will be happy to know that you have lots of redundant data there. In the OpenGL system:

CamAxisX = (CamMatrix[0],CamMatrix[1],CamMatrix[2])
CamAxisY = (CamMatrix[4],CamMatrix[5],CamMatrix[6])
CamAxisZ = (CamMatrix[8],CamMatrix[9],CamMatrix[10])
CamPos = (CamMatrix[12],CamMatrix[13],CamMatrix[14])
CamView = -CamAxisZ

It’s relatively easy to create a rotation matrix to rotate around the X, Y, and Z axes – it should be in any graphics book or any basic info on transformations. Just remember that order is important and you may have to transpose the matrices to account for using a different order.

First, when I create the rotation matrix :

Camera::Pitch( float Angle )
{
// Here I will create a new rotation matrix
RotationMatrix.RotX( Angle );
}

Do I need a rotation matrix for each one (Pitch, Yaw and Roll ) ?

When those matrix are created, I need to create a new matrix for translation. So

There, pretend I intercept a keybord key to straf…
I will do :

TranslationMatrix.Indentity();
TranslationMatrix[12]= -PosX;
TranslationMatrix[13]= -PosY;
TranslationMatrix[14]= -PosZ;

Well, Something is missing or I’m on the right way ?

On each frame, I update the matrix if it’s nessary, with this function :

Camera::UpdateCameraMatrix()
{
// I think I need to mult those matrix ?
// Which order is the best ?
// Translation * RotationMatrix_X *
// RotationMatrix_Y * RotationMatrix_Z;
}

A BIG Thanks again.
Martin.

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