PDA

View Full Version : Creating a selection box using gluUnproject



crispy
07-25-2007, 04:25 AM
Hi all

Im working on a program to display data from a 3D particle simulation, the displayer reads the particle coordinates from a data file and displays them using an opengl viewer.

The particle display etc is all working nicely, and I've been able to implement selection of single particles with picking.

However, I want to implement a way of clicking with the mouse and dragging to select a whole area of particles (using picking). As the particle simulation is contained within a cube, I guess the best way to do this would be to first create a selection box in the XY plane, and then extend it into the Z direction afterwards. However, I don't know how to get the coordinates on the "front" of the simulation (e.g. the XY plane of the simulation cube).

Does anyone know how I can do this? I've tried gluUnproject, which works if I click on a particle, but does not work if I click into empty space.

Any help appreciated, and I hope that made sense.

Cheers

Crispy

vbovio
07-31-2007, 11:05 AM
one cheap way you could try is doing the selection in 2D:

map/get all your particles center points (3D) to its corresponding window point (2D) using glProject, then do your mouse selection area, basically you have two corners for this selection (top left and bottom right points), then get all the 2D points that are inside that rectangle and map again those 2D points to the corresponding 3D ones, then you get to know which particles were selected.

You can use this method and don't even use picking..
from 3D to 2D is easy, the oposite way is more tricky..

hope that helps.

flatus
07-31-2007, 11:52 AM
Save the mouse coordinates when the user clicks down the mouse button and the mouse coordinates when they let up on it.

then use gluPickMatrix to set the size of the picking region.