When a vertex is drawn is it multiplied with only the top matrix in the matrix stack (e.g MODELVIEW) or all of them? Or am I completely on the wrong track?

For example, If my stack had these 3 transformations on it:

1) Identity
2) Translate to a point somewhere (camera)
3) Translate slightly to another point (object offset)

And then I rendered my object, would every vector be adjusted by all transformations on the stack?

Thanks in advance,
Peter

moonie

06-10-2003, 05:38 PM

yes the vector will b transformed by all the transformation in the stack.

peter.vullings

06-10-2003, 07:26 PM

Thanks!
Is there some way I can mark this post as being answered?

Relic

06-11-2003, 03:46 AM

To be more precise, the vertices are only transformed by current matrices, which are the Top Of Stack matrices:
v' = ProjectionTOS * ModelviewTOS * v;

If you generated this with something like
glLoadIdentity();
glPushMatrix();
glTranslatef();
glPushMatrix();
glTranslatef();
glBegin();
glVertex();
glEnd();
...
then the top of stack is the concatenation of the two translations, so it's transformed by both translations.
Though this is not the case if you add a glLoadIdentity() or glLoadMatrix() in between.

peter.vullings

06-11-2003, 11:28 AM

oh, right. Because 'push' operations make a copy of the last matrix on the stack, and any subsequent operations on the top of the stack will concatenate with that copy...

That makes a lot of sense now.

Thanks very much

Relic

06-12-2003, 01:23 AM

Note that the above code is academic and does the same if no glPushMatrix would have been used.
The interesting part could follow after "..." when you use glPopMatrix and glPushMatrix again to build transformations hierarchies.

peter.vullings

06-12-2003, 12:39 PM

Yes, but using pushMatrix means you can easily revert to a previous transformation just by popping the stack, doesnt it? I woild say this is very handy.