PDA

View Full Version : Translations and rotations?!



esuvs
02-18-2003, 03:25 PM
I know this is a fairly simple problem, but I can't quite get my head around it...
I have a model, centered at about (0,0,100). What I would like to do is to have this model rotate about it's own center.
So I try:

glTranslatef(0,0,-100); //bring to origin
glRotatef(angle, 0.0, 1.0, 0.0); //rotate
glTranslatef(0,0,-50); //bring into view frustum.

What i think happens is that the second translate sends it off along the new (rotated) z-axis, whereas I want to send it down the original (into the screen). How do I do this?

nexusone
02-18-2003, 06:10 PM
Note translations and rotations work in reverse order.

// Camera move
// This will effect all objects drawn
glTranslate( 0,0,-50);

//Object move
glPushMatrix(); // Push/pop save matrix so our next object is not effected by the first objects rotate/translate.

glTanslatef( 0,0,0 ); Move object
glRotatef(angle, 0,1,0); Rotate
glTranslatef( 0,0,-100); // Change objects origin of rotation
Draw_object();
glPopMatrix();


Originally posted by esuvs:
I know this is a fairly simple problem, but I can't quite get my head around it...
I have a model, centered at about (0,0,100). What I would like to do is to have this model rotate about it's own center.
So I try:

glTranslatef(0,0,-100); //bring to origin
glRotatef(angle, 0.0, 1.0, 0.0); //rotate
glTranslatef(0,0,-50); //bring into view frustum.

What i think happens is that the second translate sends it off along the new (rotated) z-axis, whereas I want to send it down the original (into the screen). How do I do this?