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

Thread: how to get the vertices coordinates

  1. #1
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    52

    how to get the vertices coordinates

    Hi,i am new to computer graphic
    I want to know this:
    If i have view matrix and projection matrix,and can i know the vertex coordinates of say,at the center of my viewport or the top-left of my viewport?Thank guys~

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,170

    Re: how to get the vertices coordinates

    If i have view matrix and projection matrix,and can i know the vertex coordinates of say,at the center of my viewport or the top-left of my viewport
    Are you talking about a 3D projection or a 2D orthographic projection?
    For 2D, it's much easier, for 3D it's not an easy thing.

    Why do you need to do this? What makes you think this is something useful to you?

  3. #3
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,162

    Re: how to get the vertices coordinates

    Since the screen coordinates are calculated using the following equation:

    V_screen = M_Viewport * M_Projection * M_ModelView * V_local

    then, the local coordinates (coordinates in the model-space), can be easily calculated using the following formula:

    V_local = M_ModelView ^ -1 * M_Projection ^ -1 * M_Viewport ^ -1 * V_screen

    where:

    M_Viewport - viewport transformation matrix,
    M_Projection - projection matrix,
    M_ModelView - model-view matrix
    V_local - vertex spatial coordinates in object-space
    V_screen - vertex coordinates in screen-space

    You just have to retrieve screen coordinates (X,Y) and the depth (Z-coordinate) of the clicked pixel. This assumes the pixel is visible, or otherwise it would be difficult to read the depth. Also, clicking a pixel on the screen does not assumes that you have clicked a vertex. You probably want to implement some kind of picking.

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,224

    Re: how to get the vertices coordinates

    Quote Originally Posted by Aleksandar
    Since the screen coordinates are calculated using the following equation:

    V_screen = M_Viewport * M_Projection * M_ModelView * V_local
    Don't forget the perspective divide:

    * OpenGL Transformation (songho)

    Clipping happens right before this.

Posting Permissions

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