Opengl Why premultiply matrices when rotating in global space?

Home / Uncategorized / Opengl Why premultiply matrices when rotating in global space?

Ok so i know when i call glRotatef() it does this,
C = C * M

where "C" is the current matrix on the stack, and "M" is the matrix computed by glRotatef(). However this causes the object to rotate around its local-axis. If i want to rotate the object around its global axis I’d have to do
C = M * C

so for example if i wanted to rotate around global x, then global y, then global z. it’d be

C = Mz * My* Mx * C

I have tested it and it works. I wanna know the reason why do we have to premultiply for global rotation and vice versa.

The "C" in my case is the modelview matrix. Do Note i am not talking about pre multiplying matrices with vectors. I know all the column major – row major stuff. I wanna know the consequences of pre/post multiplying a transformation to another matrix4x4.

Matrix mutliplication is not commutative:
A*B != B*A

So here:
C = C * M

at first object is rotated according to its local transformations C, then rotate at angle defined in M around its NEW position C.

But here:

C = M * C

you at first peform rotation around the global axes, then around local axes.
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *