PDA

View Full Version : Picking



08-08-2004, 05:43 AM
Hi,

I have implemented picking in my app, (basically copying from a tutorial) which sets up the selection matrix as follows:


glGetIntegerv(GL_VIEWPORT,viewport);
gluPickMatrix(cursorX,viewport[3]-cursorY,5,5,viewport);
gluFrustum(-0.5,0.5,-0.5,0.5,0.1,60);
glMatrixMode(GL_MODELVIEW);I want to achieve a similar result, but to specify the matrix with OpenGL co-ordinates. Is this possible without converting from OpenGL -> window manager co-ordinates (using UnProject() or something)?

Thanks for any help,

Adam

08-08-2004, 06:59 PM
I want to achieve a similar result, but to specify the matrix with OpenGL co-ordinates.could you explain more? not sure what you mean.

08-09-2004, 01:23 AM
My app will draw the same objects to multiple outputs (eg. multiple screens / windows / etc...) which could be looking at different parts of the scene.

Therefore a mouse click in one window will not result in the same objects picked, as a mouse click at the same window co-ordinates in another window. Instead, i want the mouse click to be translated to the co-ordinates in my scene and a function for all windows called -

int Pick(double x, double y)

where x and y are co-ordinates in my scene.

How do i set the picking matrix for these two co-ordinates?

Thanks,

Adam

08-09-2004, 12:55 PM
im not sure, but i think gluUnProject() is what you want. that will "unproject" your screen x,y,z back into the world.

08-09-2004, 01:00 PM
and the picking matrix is just based on the current viewport x,y.

example:

gluPickMatrix( mouseX, height - 1 - mouseY, mouseWidth, mouseHeight );

you need to call this right before glOrtho()/gluPerspective()/glFrustum().

08-09-2004, 01:03 PM
or maybe you need glProject(), which will take world coordinated and convert them to screen coordinates.

08-13-2004, 11:08 AM
The red book states:

Advanced

The net result of the matrix created by gluPickMatrix() is to transform the clipping region into the unit cube -1 ≤ (x, y, z) ≤ 1 (or -w ≤ (wx, wy, wz) ≤ w). The picking matrix effectively performs an orthogonal transformation that maps a subregion of this unit cube to the unit cube. Since the transformation is arbitrary, you can make picking work for different sorts of regions - for example, for rotated rectangular portions of the window. In certain situations, you might find it easier to specify additional clipping planes to define the picking region.

Is this refering to standard clipping planes?

I can probably just use them.

Thanks for the help