-
global coordinates
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?
-
Re: 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*.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules