View Full Version : Rotation and Translation Problems

Pierre

02-05-2010, 12: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:

http://best-nk.fr/open.jpg

Soon,

DarkShadow44

02-05-2010, 01: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

Pierre

02-05-2010, 01: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.

marshats

02-05-2010, 09:04 PM

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();

Pierre

02-06-2010, 08: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

Pierre

02-06-2010, 09: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?

Soon,

marshats

02-06-2010, 12: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)"

Pierre

02-06-2010, 01: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 ?

marshats

02-06-2010, 04: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.

Pierre

02-06-2010, 04: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...

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.