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 5 of 5

Thread: Get vertex information after transformation

  1. #1
    Intern Newbie
    Join Date
    Feb 2005
    Posts
    39

    Get vertex information after transformation

    Say I have a vertex at (1.0, 1.0, 1.0).
    Its coordinates are recorded in variables:

    float x=1.0;
    float y=1.0;
    float z=1.0;

    Then I rotate the ModelView Matrix by 45 degree to y axis.

    glRotatef(45.0, 0.0, 1.0, 0.0);
    glBegin(GL_POINTS);
    glVertex3f(x, y, z);
    glEnd();

    How could I get the information about the transformed coordinates in OpenGL? In this example, I want to get the values of x, y and z after rotate.
    Because I want to create some moving cubes which would interact with the ball in a game, I need to know the new positions of the vertices of the cube then recalculate the surfaces for collision detection.

  2. #2
    Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    368

    Re: Get vertex information after transformation

    One method (which might not be the best, but just came into my head) would be to get the current modelview and projection matrices and then do the multiplication yourself.
    Each vertex as it goes down the pipeline, is multiplied by these two matrices. The problem is I can't remember in which turn. You might want to check out the OpenGL Programming Guide. An old version should be lying around over the 'net.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,749

    Re: Get vertex information after transformation

    you should do mathematics for that. Just know where are the center of rotations, the axis and the angle to rotate. And do some cos and sin regarding the plane on which you are rotating. There are many documentation about this over the net.
    You can use other mathematics means but they are more complicated.

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2004
    Posts
    19

    Re: Get vertex information after transformation

    Hi! I agree with moucard, you could do that by multiplying the vertex by the matrixes, but I don't know what of them and in what order.... I think this must be the best way to do that, since that must be the way Opengl performs to calculate the new vertex position. See ya!!

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2004
    Posts
    19

    Re: Get vertex information after transformation

    Ah, and I thought that multiplying by the modelview matrix after the rotation, you'll be indirectly applying the mathematical formulas that jide talked about... That's it:

    Xu = Xo * cos(angle) - Yo * sin(angle)
    Yu = Yo * cos(angle) + Xo * sin(angle)

    If translation were around the z-axis...

    See ya!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •