View Full Version : Quaternion (Almost done but...)

02-25-2002, 03:16 PM
Hello... http://www.opengl.org/discussion_boards/ubb/smile.gif
Well, 1 weeks ago, I dicided to build a Camara CLASS.
This one use it own matrix. So when the camera is Created :

MatCam = Matrix(Identity);

Each frame of my OpenGL program, the camera is refreshed.
Here, is what I do in the refresh function :

// Get the new orientation of the camera depend the degres
// here( DegPitch, DegRoll, DegYaw)...

CamOrientation = AngleEULERToQuat( DegPitch, DegRoll, DegYaw );
QuatNormalize( CamOrientation );

// Just after this, I set up a new matrix to contain the rotation.

MatRotation = MatIdentity;
MatTemp = QuatToMatrix( CamOrientation );
MatRotation = MatMultiply( MatRotation, MatTemp );

// I set up a new matrix again, but now to contain the translation.

MatTranslate = MatIdentite;
MatTranslate[12] = MatTranslate[12] - CamPos.vX;
MatTranslate[13] = MatTranslate[13] - CamPos.vY;
MatTranslate[14] = MatTranslate[14] + CamPos.vZ;

// To finalize, I load the rotation matrix and I multiply it by the
// translation matrix.

glLoadMatrixf( MatRotation );
glMultMatrixf( MatDeplacement );

// End of the refresh function....

************************************************** ********************
When I translate my camera, it's sound great.
But when I rotate it (any degres...) I got a weird rotation.

Ex : Under 90° (Y axis), my camera move backward and rotate too...
************************************************** ********************

What's could be the problem ?
Thanks to help me...

PS :Here is my matrix format :

[ 0 4 8 12 ]
[ 1 5 9 13 ]
[ 2 6 10 14 ]
[ 3 7 11 15 ]


[This message has been edited by Erakis (edited 02-25-2002).]

[This message has been edited by Erakis (edited 02-25-2002).]

[This message has been edited by Erakis (edited 02-25-2002).]

02-25-2002, 09:01 PM
Hi Erick!!! I readed your problem, and didn't understand the question!!!

But I'll try to help you!!!

I think the problem in your case, is the way you are doing the rotations...

You can't set for example a camera struct like this:

struct camera{

and when you do your rotations use them with SetEulerFromAngles().

The correct way is to increase the Quaternion of each object, when the camera were rotated!!! Instead, you are going to get Gimbal Lock liked Problem ...

Just try this:

Instead of increasing the Camera Struct when the object were rotated, Increase you Quaternion!

Maybe it's help you! And sorry for the bad english


02-26-2002, 04:59 PM
I can't tell why your rotations are wrong but here's some tips.

You can go directly from Euler angles to a rotation matrix without using quaternions.

You also don't need all those matrix multiplies since multiplying the identity matrix by a matrix is the same as copying it.

If you manipulate the orientation using Euler angles, you may run into gimbal lock.

02-26-2002, 05:38 PM
glLoadMatrixf( MatRotation );
glMultMatrixf( MatDeplacement );

Have you tried it the other way round?

glLoadMatrixf( MatDeplacement );
glMultMatrixf( MatRotation );

Can you assure us that the Angles2Quat function you use is working right?