PDA

View Full Version : window coordinates of a vertex



junlin_xu
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.

SirKnight
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.

-SirKnight

CViper
02-25-2002, 10:13 PM
isnt
gluProject() / gluUnproject() (or something like that)
supposed to do that?

zeckensack
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.

jefftkd
02-26-2002, 05:30 AM
Use gluProject -- very simple and fast and works.

Jeff

junlin_xu
02-26-2002, 07:40 PM
Thanks, Jeff. Your method works well.