PDA

View Full Version : using gluProject: efficient enough? anyone know better?



Schlogenburg
08-09-2000, 03:16 PM
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.

Kilam Malik
08-10-2000, 02:43 AM
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.


Regards,

Kilam.

DFrey
08-10-2000, 04:08 AM
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. http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Schlogenburg
08-10-2000, 06:46 AM
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.

ben
08-10-2000, 08:36 AM
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.

Schlogenburg
08-10-2000, 09:10 AM
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
functions.

Kilam Malik
08-10-2000, 10:04 PM
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).

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

if (!valid_draw)
return false;

LockOpenGL();

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);

p1.x(o1x);
p1.y(o1y);
p1.z(o1z);

p2.x(o2x);
p2.y(o2y);
p2.z(o2z);

UnlockOpenGL();

return true;
}



Have fun!

Kilam.

ben
08-11-2000, 01:49 AM
Kilam,

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.

Thanks

drakaza
08-11-2000, 03:34 AM
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/000593.html

Check out this topic section. A few links and discussions about BSP's. Feel free to resurrect the post http://www.opengl.org/discussion_boards/ubb/smile.gif


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