Jump to content
  • Advertisement

Archived

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

ham2233

OpenGL OpenGL Game Programming and Matrices

This topic is 6009 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

I''m working out of the book OpenGL Game Programming (PrimaTech Press), but am having some trouble. When they get into the actual rendering, the book is a little lacking in sufficient explanations of what is happening at each point in the program. I''m specifically curious about the glPushMatrix() and glPopMatrix() functions. Really, though, I''d like to just have someone lay it out for me. What is the purpose of pushing and popping matrices, and what happens when an identity is loaded? When would one want to push a matrix, and when would one not? Also, how does this relate to translations and scaling and such? I realize there may be online resources related to this. If so, links to those would be much appreciated. Otherwise, if someone is up to the challenge of just laying this out for me, I''d be very appreciative. Thanks, Justin

Share this post


Link to post
Share on other sites
Advertisement
Pushing and popping matrices allows you to save the current matrix temporarily. This allows you to translate to the objects position (and push), then translate to the arm position (and push), then to the wrist position and render the wrist and hand, then pop the matrix and render the arm, then pop and render the rest of the object. Loading the identity matrix brings you back to the origin.

This all works as a matrix stack following first in, last out order, if you already know how a stack works.

Share this post


Link to post
Share on other sites
You''re probably having trouble understanding what a matrix is used for exacly.

A matrix is a coordinate system that can be moved around in space simply by multiplying it with certain types of matrices. An identity matrix is just the matrix at it''s starting position in space. If you were to multiply a vertex by an identity matrix the vertex would not move.

Ok, so we want to start from the beginning, so we create a WorldMatrix and initialize it with an identity matrix. Now we want to move your model from it''s local space out into world space somewhere, we''ll use position 10,5,20(x,y,z). What we''d want to do at this point is create another matrix, we''ll call it Matrix, and set it up as a translation matrix and give it our position 10,5,20. All you have to do is multiply Matrix with WorldMatrix and store the result in WorldMatrix.

Now whenever you multiply any vertices with the WorldMatrix the vertices will move over by 10,5,20.

There are 6 types of matrices that I know of: Identity, Translate, Rotate, Scale, Scew and LookAt. Every time you multiply one of these matrices with your WorldMatrix your model will tranlate through space relative to the WorldMatrix coordinate system.

Pushing the WorldMatrix saves it''s values onto a stack. I believe the stack is 32 high. Pushing will retrieve the last values that were pushed and store them into the WorldMatrix.

Share this post


Link to post
Share on other sites
Oh yeah, just do a search for matrix or matrices with google.com to find out how to set up each of the matrices, plus you''ll find out how to multiply them with each other and vertices.

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!