Need help with ModelView matrix

I would like to obtain the coordinates (position only) of an object relative to the scene origin (world coords). The object is the last from a series of 8 objects. Each of the previous objects suffer transformations (rotions, translations).
Is it possible to obtain the model matrix from modelview matrix?
If yes, can anyone show me an example?


Hi cOde,

OpenGL only maintain one model-view matrix for the whole scene. If you apply any transformation to it to position an object and change it again to position another object then there’s no way to know the position of the former object.

So you can create your own model-view matrix for each object you create and then apply the transformation to the object’s matrix instead the OpenGL’s model-view matrix.

Later you can load the object’s matrix to OpenGL (using glLoadMatrix{fd}()) and render it, and repeat the same steps for each object.

Do you want the accumulated changes?

What might be helpful besides glLoadMatrix is the matrix stack functionality. With glPushMatrix and glPopMatrix, you can save off a matrix and then come back to it.


glPushMatrix() // here are now two matrices on the stack, Opengl uses the more recent one
gluLookAt(10,10,10,0,0,0,0,1,0) // still two matrices on the stack, but the top one is now changed
glPushMatrix() // here are now three matrices on the stack

as of right now all vertices multiplied by the modelview matrix will be affected by the gluLookAt and the translate

glPopMatrix() // removes the top matrix, the translate is no more, but you still have the gluLookAt
glPopMatrix() // back to the original identity

You can call glLoadMatrix and any other functions any time during all this, but OpenGL will operate on the most recent matrix you pushed onto the stack. Make sure for every push matrix, there’s a pop somewhere.