Rotation and Translation Problems

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.

[b]Then the frame 2:

And that is my problem![/b]

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:

Soon,

I don’t understand exactly what you mean…

But it’s a difference if you use

  • glTranslate before glRotate or
  • glRotate before glTranslate

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.

This is not an openGL question but a programming question. Here’s some pseudo code


if (frame==1)
{
  glTranslatef(0,dy,0);
  glRotatef(-90,0,0,1);
} 
else if (frame==2)
{
  glTranslatef(dx,0,0);
}
  draw_box();

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)
  rotation=-90
} 
else if (frame==2)
{
  direction is (dx,0,0)
  rotation=0
}
  glTranslatef(direction.x,direction.y,direction.z);
  glRotatef(rotation,0,0,1);
  draw_box();

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

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?

Soon,

Reading here may help you see how the 16 element matrix is composed. Pay particular note of the section “Model-View Matrix (GL_MODELVIEW)”

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 ?

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

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…