using gluProject: efficient enough? anyone know better?

In my engine I need a selection system that works for simple picking and dragging.
However dragging won’t work with GL selection buffer which is what I’d use. I don’t know of any other kind of geometric selection, so I’m thinkin that I have:

  • about 300 points, 300 points possible on the screen

  • will use gluProject to find the screen 2d positions of these points so they can be compared to the 2d mouse pointer to see if the mouse has selected them

    But I’ve read that gluProject may not be efficient enough to do this. Beware this is a game where speed is important.
    Please give me lots of info I’ve spent many hours on the problem.

it seems to me this would be the best solution.

I used the opposite way. gluUnProject the screencoordinate where you picked with z = 0.0 and another time with z = 1.0. Then you get a line in 3D object space from the mouse position back in space. Then you cut this line with your objects in 3D. Should be faster, as you have less matrix multiplications (i think 3 muls for every gluProject). When you got a structure like octrees or bsp it could be very fast to determine what the line hits.

I use it in a modeller and I have objects with a lot of faces (>2000). The picking runs well.



Don’t you mean world space Kilam? Well, I can excuse you for confusing object space with world space since you are working on a modeling program where the object and world spaces are usually the same.

Hey could you send me the source, or just send me the routine where you used gluUnProject? The usage of this routine is very complicated.

I don’t know if this falls into the same boat as the gl selection buffer, but I thought I’d mention it…

The gl feedback mechanism can give you the projections of your points into screen coordinates pretty quickly.

You could use the GL_2D argument when calling the glFeedbackBuffer() function, call glRenderMode(GL_FEEDBACK), render the points, …

Then, you can parse the feedback array and get the 2D positions back. Use the insertion of GL_PASS_THROUGH_TOKENs to identify which point is which. I’m not sure if this is faster than looping with gluProject, but I thought I’d mention it.

I have no idea how to do that, looking into the Red Book right now.
I would have looked at this already, but I was told that feedback would be slower than/less efficient than using un/projection

Here it is: You put in a 2D screen point and get back two point describing the line in world space (DFrey: Yep, world space… object space and world space are really the same in my prog. Although I got more than one object, they are all positioned in world space as the modelling kernel calculates the 3D positions).

[b]bool Part3DPane::PickRay(Point2D pIn, Point3D &p1, Point3D &p2)
GLdouble o1x,o1y,o1z;
GLdouble o2x,o2y,o2z;

if (!valid_draw)
return false;


gluUnProject(pIn.x(),drawSizeY - pIn.y(),0.0,modelMatrix,projMatrix,viewport,&o1x,&o1y,&o1z);
gluUnProject(pIn.x(),drawSizeY - pIn.y(),1.0,modelMatrix,projMatrix,viewport,&o2x,&o2y,&o2z);




return true;

Have fun!



Your ray selection sounds really good! I have a question regarding this, though. What is a BSP (or OctTree). I was thinking about intersecting the 3D world line with object to find out if it hits and it seems that testing each and every object in the scene is not the way to go. If you could briefly explain what a BSP is (or point me to a web-page) I’d really appreciate it.


Check out this topic section. A few links and discussions about BSP’s. Feel free to resurrect the post

[This message has been edited by drakaza (edited 08-11-2000).]