View Full Version : how to get the vertices coordinates

zydgyy

04-11-2012, 10:55 PM

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~

BionicBytes

04-12-2012, 04:05 AM

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?

Aleksandar

04-12-2012, 07:24 AM

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.

Dark Photon

04-12-2012, 07:39 AM

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) (http://www.songho.ca/opengl/gl_transform.html)

Clipping happens right before this.

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.