View Full Version : window coordinates of a vertex
02-25-2002, 04:40 PM
Does any one know if there is a way to tell the window (device) position [x, y] of a vertex after model-view transformation on that vertex. I want to test if that vertex on screen is within a selecting rectangle. Any help is greatly appreciated.
02-25-2002, 05:07 PM
Well the screen (x,y) coords are not generated _right_ after the modelview transform. After the modelview transform the coords are in eye space (or eye coordinates if you will). Then the clip coordinates are formed after the eye space coordinates are multiplied by the projection matrix. Then the perspective division takes place to generate the normalized device coordinates. Then those are transformed into the window (x,y) coordinates by the viewport transformation which the viewport transformation also happens to be a matrix.
Whew, now that that is done. What you want is to use the selection buffer. This is explained in detail in the Redbook and superbible. Older versions are on the web for free.
02-25-2002, 10:13 PM
gluProject() / gluUnproject() (or something like that)
supposed to do that?
02-26-2002, 04:35 AM
If this is about a single vertex and the selection rectangle is small you could try the following:
1)Mask off color/alpha/depth writes, disable depth test, enable stencil writes
2)clear stencil buffer to 0 (or subregion by rendering a quad with the proper stencil ops)
3)set stencil op so to never fail, set 1on write
4)render the vertex as a point
5)readback the selection rectangle region from the stencil buffer
6)check for value 1
This is a fairly ghetto method and will not perform too well.
02-26-2002, 05:30 AM
Use gluProject -- very simple and fast and works.
02-26-2002, 07:40 PM
Thanks, Jeff. Your method works well.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.