Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: global coordinates

  1. #1
    Guest

    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?

  2. #2
    Intern Newbie
    Join Date
    Aug 2001
    Location
    Vancouver, British Columbia, Canada
    Posts
    43

    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
  •