system
1
How do I get a vertex’s global coordinates after I do severl PushMatrix/translate,multmatrix,scale, etc.
for example (psudocode)
glLoadIdentity
glPushmatrix
gltranslate
glrotate
glPushMatrix
glscale
glMultMatrix
glVertex3f X, Y, Z
glPopmatrix
glPopMatrix
how do I get X,Y, and Z where they would appear in global coordinates?
You need to multiply the vertex by the same matrices that were used to tranform it for rendering.
One way to do it is as follows:
glLoadIdentity
glPushmatrix
gltranslate
glrotate
glPushMatrix
glscale
glMultMatrix
transformMatrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, transformMatrix);
glVertex3f X, Y, Z
glPopmatrix
glPopMatrix
transformedVertex[3];
MyMatrixMultiply(transformMatrix, X, Y, Z, transformedVertex);
Or, if performance is an issue, it might be better to compute the required matrix yourself, instead of using glGet*.