View Full Version : Reason why opengl transform in reverse?

02-06-2010, 11:58 PM
Is it because when I have a point P in space. If I rotate, then scale it. OpenGl reads it like this

P' = Rotate()P
P'' = Scale()P'
P'' = Scale()Rotate()P

So starting from left it scale then rotate point P.

Can anyone here enlighten me.

Thank you very much.

02-07-2010, 07:20 AM
Yea, It has to do how openGL deals with matrix multiplication.
In your example you should remember that the first line essentially does this
then that also means that the second line does this
put these two together and you will have
ModelviewMatrix=ScaleMatrix*(RotationMatrix*Modelv iewMatrix)

Now this might be confusing at the beginning, but that's the way it works, fortunately starting with openGL 3.0 you can do it anyway you like.

02-07-2010, 07:27 AM
OpenGL 3.2 compatibility profile spec: http://www.opengl.org/registry/doc/glspec32.compatibility.20091207.pdf

page 62:
"If C is the current matrix and M is the matrix pointed to by MultMatrix's argument, then the resulting current matrix, C' , is
C' = C M.

page 63:
"Rotate, Translate, Scale, Frustum, and Ortho manipulate the current matrix. Each com-
putes a matrix and then invokes MultMatrix with this matrix."

02-07-2010, 11:00 AM
So starting from left it scale then rotate point P.

Sound like semantics but for me it makes more sense to say openGL matrix operations occur from right-to-left (or bottom-to-top in C-code).

For instance say you have code like

glLoadIdentity(); // load Matrix => MV=I
glTranslatef(car_x_pos, car_y_pos, car_z_pos); // times Matrix T => MV=I*T
glRotatef(RAD_TO_DEG * car_direction, 0.0, 0.0, -1.0); // times Matrix R => MV=I*T*R
glScalef(Sx,Sy,Sz); // times Matrix S => MV=I*T*R*S
draw(P); // draw points P'= MV*P = I*T*R*S*P

The effective operation order is of scaling first, then rotation, then translating. I think of operations going from bottom-to-top in openGL code which corresponds to right-to-left in matrix operations as

P' = I*T*R*S*P