Jump to content
  • Advertisement

Archived

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

zenon

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!