PDA

View Full Version : would you like to explain it for me ?



victorswan
02-08-2002, 09:14 PM
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.

Overmind
02-09-2002, 11:17 AM
Please don't crosspost on both forums.

The use of Push/PopMatrix doesn't change the order of matrix operations. It's the only the interpretation of them that is changing.

Personally I think the local coordinate interpretation is easier to understand than the global coordinate system, but you have to find out for yourself what you understand best.

Every coordinate you give to OpenGL is relative to some coordinate system. glVertex3f(1.0, 0.0, 0.0) means one unit from the origin along the x-axis. When you write glTranslatef(0.0, 1.0, 0.0) this means "move the origin one unit along the y-axis". All further coordinates are relative to the new origin.

Similar with rotations, glRotatef(45.0, 0.0, 1.0, 0.0) means "rotate the axes of the coordinate system 45 degrees around the y-axis).




So when you write:
glTranslatef(1.0, 0.0, 0.0)

you change your coordinate system:
^ y ^ y
| -> |
| |
o-----> x o +-----> x
|< 1 >| |< 1 >|< 1 >|
(with "o" being the old origin)
= translate one unit along the x-axis


but when you do:
glScalef(2.0, 0.0, 0.0)
glTranslatef(1.0, 0.0, 0.0)

you get:
^ y ^ y
| -> |
| |
o-----> x o-----------> x
|< 1 >| |< 2 >|
= scale the x-axis by two

^ y
|
|
o +-----------> x
|< 2 >|< 2 >|
= translate one unit (= 2 global units because of the scale) along the x-axis

and when you do:
glTranslatef(1.0, 0.0, 0.0)
glScalef(2.0, 0.0, 0.0)

you get:
^ y ^ y
| -> |
| |
o-----> x o +-----> x
|< 1 >| |< 1 >|< 1 >|
= translate one unit along the x-axis

^ y
|
|
o +-----------> x
|< 1 >|< 2 >|
= scale the x-axis by two (notice that the distance to the origin doesn't change)


You have to see this as a way of "thinking in the right order". With this model you don't have to reverse the transformation order because you think of it in the same order than OpenGL does.

I hope that was clear. Sorry for not giving an example with rotation, but thats not so easy with ascii-art ;-).

Overmind