Advertisement

strange glTranslatef()....

Started by January 21, 2002 03:46 PM
0 comments, last by notatric 23 years, 1 month ago
Hi, I''ve run into a small problem while coding with opengl. I''m rendering a small arena at 0,0,0 and drawing all triangles with hardcoded coordinates....everything ok so far...now I''m rendering a MS3D-file (code from Nehe! 1:1).... the model is rendered at the exact position via gltranslatef.... but when I render a second model it apears at (model1 coordinates)+model2 coords..... strange.... is there something I didn''t understand with glTranslatef()??... would it help to put the model code between a glpopmatrix()..glpushmatrix() ?? Help would be very good!!! It''s wicked Bye NoMoRe@
All matrix operations (translate, rotate, project...) work on the _current_ matrix. Which means that your second translation is indeed combined with the first.

What push/pop matrix do is save/restore the matrices on the matrix stack. Which means that if you push before your first translation, render, then pop, your matrix will be restored to what it was before the translation. Which means that you can now push, translater, render and pop for your second object.

Now, if you have several objects that are supposed to ''move together'', like the different parts of a bicycle, you''d push, translate/rotate to position the whole frame, render the frame, push again, translate/rotate to place the front wheel, pop, push translate/rotate to place the second wheel, pop, pop and move on to the next bike.

The matrix stack lets you keep track of a hierarchy of transformations. (Read up on ''scene graphs'' for further details.)
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement