# would you like to explain it for me ?

when i read “the red book” for Opengl, I cant understand this bellow:
“Another way to view matrix multiplications is to forget about a grand, fixed coordinate system in which your model is transformed and instead imagine that a local coordinate system is tied to the object you’re drawing. All operations occur relative to this changing coordinate system. With this approach, the matrix multiplications now appear in the natural order in the code.”
so i hope someone to explain it for me, the best way is presenting an example, i also want to know, wether the matrix multiplications have different order between using glPushMatrix(), glPopMatrix() and not using them.thanks.

i’m not sure but i’ll try an explanation:
consider the following matrix operations order:

glMatrixMode( GL_MODELVIEW );
glTranslatef(…) { matrix MAT1 };
glRotatef(…) { matrix MAT2 };
glScalef(…) { matrix MAT3 };

which will be the order of transformations to the next rendered objects?
it will be MAT3 x MAT2 x MAT1 ( not 1 x 2 x 3 ). So the above multiplications occurred as follow:

// current matrix is m1 = identity
glTranslatef(…); { matrix t }
// current matrix is m2 = tm1
glRotatef(…); { matrix r }
// current matrix is m3 = r
m2
glScalef(…); { matrix s }
// current matrix is m4 = s*m3

so you can see that operations in a different order: you are transforming all the world coordinates into object coordinates and are now working in this local coordinate system. Got it?

this order of multiplication is very usefull when drawing object trees:

glMatrixMode…
glLookAt… // view matrix
glPushMatrix… // save the matrix here
//apply main node world transform
gl…
gl…
gl…
glPushMatrix…
//apply child1 world transform
gl…
gl…
gl…
glPushMatrix…
//apply child1_child1 world transform
gl…
gl…
gl…
//returns to child1 world
glPopMatrix…
glPushMatrix…
//apply child1_chil2…
gl…
//returns to child1 world
glPopMatrix…
//returns to main world
glPopMatrix…
glPushMatrix…
//draw child2… 3… 4…
//returns to view-only matrix
glPopMatrix…
//draw other main nodes…
glPopMatrix…

i hope to had helped you…
kilmon000

it will be MAT3 x MAT2 x MAT1 ( not 1 x 2 x 3 ).

The resulting matrix will be MAT1 x MAT2 x MAT3. The reason is order of multiplication, you add a matrix on the right side.

In your example, you load the matrix stack with the identity matrix, and multiply in MAT1. The stack is then MAT1. Then you add MAT2, which goes to the right side, and the stack is then MAT1 x MAT2. Then you add MAT3 to the right, and get MAT1 x MAT2 x MAT3.

Forgot…

When multiplying with a vertex, you get MAT1 x MAT2 x MAT3 x V. Since a vertex is multiplied from right to left, you will multiply the vertex first by MAT3, then MAT2, and last MAT1. This is why the transformations is applied from bottom up (as read in the code).

yeah… i inverted the things: the matrix order is MAT1 x MAT2 x MAT3 but every vertex is affected first by MAT3 then MAT2 then MAT1… thank you bob

kilmon000

thank you