glRotate - How does it really work?

Started by
10 comments, last by OneMoreToGo 17 years, 9 months ago
Quote:Original post by OneMoreToGo
I'm not sure I understand your solution... glTranslate has no effect on glVertex. Or does it? *Dun dun duuhhh* ;)


Translating does have an effect on vertices that are passed in to the pipeline. Consider translating from the origin (0, 0, 0) to (10, 0, 0). To do this you would issue a glTranslatef(10.0f, 0.0f, 0.0f). Your origin now is located at (10, 0, 0), so if we issue a glVertex3f(5.0f, 0.0f, 0.0f), we would be multiplying the modelview matrix, which has an origin (10, 0, 0), by the column matrix (5, 0, 0) to obtain a vertex location of (15, 0, 0). There is a bit more to this matrix and vector math, but to answer your question, a translation does effect the final location of a vertex when passed through the pipeline.

Quote:Original post by OneMoreToGo
EDIT: And like swordfish said, wouldn't the rotate call have to be AFTER the translate call? :???:


No. OpenGL uses post-multiplication for matrix math. Matrices are stored in column major order and represents vertices a column vectors. Because it is post-multiplied, the math is from right to left and not left to right. Left to right would be used by row major order matrices.

Looking at the commands.
We currently have matrix O on the matrix stack. What we want is O` = O * R * T * v. When you issue a translate or rotate command, the current matrix O is replaced by O * C. Looking at the example, issuing a rotate command produces the current matrix: R` = O * R. R` is now the new matrix on the stack. Now issue a translation command to produce the matrix: T` = R` * T. If we replace R` with O * R we get the final result: O * R * T = O`.

Quote:Original post by OneMoreToGo
EDIT 2: Tried it, I *think* it worked, but it's hard to tell because the texture has gotten 2 times as big as before!


Not quite sure because I would have to look closer at your code. Hope this helps you.

Advertisement
Thanks, kalas! (Perhaps without realizing it), you have reinforced my weak understanding of matrices!

This topic is closed to new replies.

Advertisement