PDA

View Full Version : Preserving the order of transformations



MKAI
06-17-2003, 01:25 AM
Hi everyone

As you know, OpenGL reserves the order of successive transformations. For example in this code:

glMatrixMode(GL_MODELVIEW);
t1;
t2;
t3;
DrawObject();

The t3 affects first, then t2 and finally t1.
How should I force OpenGL to transform in the same order that I specify in code(My transformations are affected by user input and I can't predict the next transformation). I need a more direct way than using my own stack to reversre use input.

Thanks

Obli
06-17-2003, 01:48 AM
The GL will always issue transforms in the order you specify them. Where's the point?

Deiussum
06-17-2003, 04:33 AM
It's not OpenGL specifically that "reserves the order of successive transformations."

All OpenGL does is multiply matrices and keeps the current one. The properties of matrix math is the reason that the last one is effectively done first. If you REALLY need to change the order, you can do your own matrix math and pre-multiply new transforms instead of post-multiplying them, as OpenGL does.

For instance pseudocode for glRotate looks something like so...




void glRotate(float ang, float x, float y, float z)
{
Matrix rot = CreateRotationMatrix(ang, x, y, z);

CurrentMatrix = CurrentMatrix * rot;
}


If you wanted to do your own matrix stuff that does things in the reverse order, your function might look similar to so...




void myGlRotate(float ang, float x, float y, float z)
{
Matrix rot = CreateRotationMatrix(ang, x, y, z);

CurrentMatrix = rot * CurrentMatrix ;
glLoadMatrix(CurrentMatrix);
}