#### Archived

This topic is now archived and is closed to further replies.

# pushmatrix.

This topic is 5763 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok.. here I go again. I''ve been trying to REALLY get it with the pushmatrix function but.. Can someone really über explain what the pushmatrix exactly does? Sure, I''ve used it in some code..but I can''t honestly say that I really get it 100%. What I''ve figured out is that it loads over some new 3D coordinates (X,Y,Z) as the one''s I''m working with? Or am I wrong? Enlight me oh might gurus... #include <me.h>

##### Share on other sites
OpenGL works in "states". You have a "matrix mode" (see glMatrixMode) that you are working in, and when you do matrix operations, you are affecting whatever matrix mode you set last. Functions like glRotate, glTranslate, and glScale also work with states. Everything you draw after you call them will be affected.

Now that we''ve got that, let''s look at the functionality of pushing and popping matrices. Let''s say you are drawing just a simple 2d game, we''ll say tetris. Now, let''s say your board is on a fixed coordinate system, and you want to move the origin to the center of the block, rotate that block 90 degrees, and then change back to the original system. Well, if you just chage your projection, and call glRotate, everything drawn after would be rotated. Let''s say you draw the blocks that have already fallen AFTER you call glRotate. Doing it this way would rotate those blocks as well. THis is where glPushMatrix and glPopMatrix come into play. The matrices work on a matrix stack (like a stack of plates in one of those things at golden corral, you have to pull the top plate off first). When you push a new matrix on the stack, you copy your old matrix and basically you''re working in a new matrix that does not affect the old one. Normally, you''ll want to change this matrix to the identity, perform your matrix operations, and then pop that matrix off of the stack. Viola. You have accomplished what you wanted without affecting the other parts of the scene.

##### Share on other sites
thnx.
damn.. (pop/push)-matrix rockz.

#include <me.h>

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633390
• Total Posts
3011631
• ### Who's Online (See full list)

There are no registered users currently online

×