View Full Version : Rotation and Translation Problems

02-05-2010, 01:26 PM
Hello everyone,

I would like to know how to solve my problem.

Translated and Rotated I use OpenGL, and I'm doing a 3D game.

My character has to move on a 3D terrain.

Let me explain my problem:

I start from the beginning until now all is well.

I realize a translation and rotation.

Either the frame 1.

The rotation should be about itself.

Then the frame 2:

And that is my problem!

The character still all right.

Once completed this rotation I'd like to make a translation but in the sense of rotation.

Here's a little diagram explaining:



02-05-2010, 02:18 PM
I don't understand exactly what you mean...

But it's a difference if you use
- glTranslate before glRotate or
- glRotate before glTranslate

02-05-2010, 02:25 PM
Yes i know that.

My question is:

How to make a translation followed by rotation of the object
on itself and then resume moving toward the new direction.

02-05-2010, 10:04 PM
This is not an openGL question but a programming question. Here's some pseudo code

if (frame==1)
else if (frame==2)

Note that assumes that you keep accumulating the MODELVIEW matrix.

Or you could just note that in the second frame the rotation is 0.

if (frame==1)
direction is (0,dy,0)
else if (frame==2)
direction is (dx,0,0)

02-06-2010, 09:40 AM
ok thank but i can have 600 frames, it's more complexe than you said.

I find the solution:

We must make calculations and save the matrix and the matrix
reuse each time.

Thank you again

02-06-2010, 10:07 AM
I have a another question on the matrix.

When you have an array of size 16 for the womb.

What are the boxes containing the position x, y, z.

And what are the other boxes?


02-06-2010, 01:47 PM
Reading here (http://www.songho.ca/opengl/gl_transform.html) may help you see how the 16 element matrix is composed. Pay particular note of the section "Model-View Matrix (GL_MODELVIEW)"

02-06-2010, 02:29 PM
Ok I ask you this question because now my character moves in a 3d world and I want to follow the camera.

Thank for the link, now i understand the matrix!

Do you have a another link for another methods for the camera without lookat with matrix of character ?

02-06-2010, 05:05 PM
Do you have a another link for another methods for the camera without lookat with matrix of character ?

I find gluLookAt is good for what I do ... sorry No I don't have any other references that do not use gluLookAt.

02-06-2010, 05:18 PM
Ok i seek technics as it:

double x = Mesh.objectTransformationMatrix[8] - Mesh.objectTransformationMatrix[12];
double y = Mesh.objectTransformationMatrix[9] - Mesh.objectTransformationMatrix[13];
double z = Mesh.objectTransformationMatrix[10] - Mesh.objectTransformationMatrix[14];

// eyeCenter == eyeDir

Glu.gluLookAt(Mesh.objectTransformationMatrix[12], //eye X
Mesh.objectTransformationMatrix[13], //eye Y
Mesh.objectTransformationMatrix[14], //eye Z
x, //center X
y, //center Y
z, //center Z
0.0f, // upvect X
Math.Sin(Mesh.objectTransformationMatrix[5]), // upvect Y
0.0f); // upvect Z

But this code don't work...