PDA

View Full Version : Why Save The Matrix?



WILL
07-01-2007, 09:15 PM
No, I'm not talking about some hippy program to save all those machines that conqoured the human race and enslaved us all in the distant fictional future.

I'm just wondering for the sake of edification why is it that we would want to save this matrix when working with OpenGL to draw a new primitive?

What valuable information is stored here and what why would it get lost if we didn't save it?

JernejL
07-01-2007, 10:44 PM
I'm just wondering for the sake of edification why is it that we would want to save this matrix when working with OpenGL to draw a new primitive?

What valuable information is stored here and what why would it get lost if we didn't save it?

if you change it (gltranslated / glrotatef / glscalef) then you should restore it with glpushmatrix / glpopmatrix mechanism, otherwise everything after you change it will follow the modified matrix...

WILL
08-01-2007, 02:24 AM
Ah.. so it's just like a rendering brush of sorts then?

JernejL
08-01-2007, 07:30 AM
Ah.. so it's just like a rendering brush of sorts then?

eh?

when you come into your rendering loop you make the matrix using glulookat or similar functions, when you change the matrix, you have to save previous state, otherwise all geometry you draw after change will follow the changed matrix, so you'd have to use routines to recreate your original matrix all the time which would be much more time consuming process.

Huehnerschaender
08-01-2007, 08:42 AM
Think about it in 2D to understand the principle like I told you.

Think of a plotter which draws a line at some point. Not resetting after drawing will draw the next point from the end of the line. Resetting will draw the next line fom origin again. Both has advantages, and you need both possibilities. For example, you draw a cube in 3D. You know dimensions, rotation and scale of that cube, draw the first face and go on from that point.

Drawing a second cude on another place, you would like to reset the matrix before, because you still have the position, rotation and scale of the first cube stored in the matrix.

Got it?

WILL
08-01-2007, 03:31 PM
Ok I've got it now. Thanks guys.

Just something that was floating around in my head the other day while messing with some stuff. :P