PDA

View Full Version : Rotation Problem



06-01-2001, 09:59 AM
Hello,

I've a problem with glRotatef: I have some blocks on the screen. I want to rotate ONE of them. But when I use glRotatef, all blocks are rotated. What can I do?

Deiussum
06-01-2001, 10:17 AM
OpenGL is a state machine so whenever you use glRotatef it changes the state of the current matrix so that everything after that call is affected. If you only want to rotate one cube you should use glPushMatrix and glPopMatrix around it like so...

glPushMatrix(); // Push current matrix onto the matrix stack
glRotatef(); // Modify current matrix
DrawCube();
glPopMatrix(); // Pop top of stack into current matrix, resetting it to what it was prior to the glRotatef

06-01-2001, 10:49 AM
Yepp, it works. Thanx. But the command don't work for Moving or Scaling because I have the same problems there. Could you give me further help?

Michael Steinberg
06-02-2001, 05:12 AM
It's the same as Deissum proposed. You have to push the matrix that is to be used for ALL cubes, change it to the needs of the single cube you wanted to change, and then pop the stack again.

glMatrixMode( GL_MODELVIEW );
glPushMatrix();

glRotate ...
glTranslate ...
glScale ...

// Draw single cuve now

glPopMatrix();

Then you should also call to mind that the matrix operations work the other way around. With what I wrote above, you would first scale the cube, then translate it and at least, you would rotate it.
Hope that helps.

06-02-2001, 09:42 AM
Thanx, now it works. http://www.opengl.org/discussion_boards/ubb/biggrin.gif