View Full Version : object picking/selection

01-10-2010, 01:10 PM
I need some help with object selection...

I can't use GL_SELECT for that, because that only supports 128 (on my computer) names... :(
I also read that this is too slow on nvidia cards ;)

What would you recommend for selecting objects by clicking on them ?

01-10-2010, 08:38 PM
http://www.opengl.org/discussion_boards/...true#Post258304 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=258304&Searchpa ge=1&Main=50169&Words=coldet&Search=true#Post25830 4)

01-11-2010, 09:33 AM
Sorry, but I don't use glFrustum and I don't know how to check for ray intersections (the link is broken).

Can't you tell me how to do picking with gluPerspective ?
I don't understande Coldet too...

01-12-2010, 07:29 PM
I just checked the link and it works fine. :) Not sure what you mean about "not using glFrustum", but it sounds like you need to do a little background reading generally.

Here is a direct link : http://www.opengl.org/resources/faq/technical/selection.htm

You don't need to understand Coldet, other than the API it provides. If you don't want to go that complex then a simpler way is to simply do Ray-Sphere intersection on a bounding sphere for the objects, or other flavours of Ray-???? intersection depending on the size and shape of your objects.

Here's a link to another option : http://www.opengl.org/resources/faq/technical/color.htm#0050

01-13-2010, 12:54 PM
I mean the one for " the BSP FAQ " (checking for Ray intersections).

Couldn't you give me a short example that uses sphere ray intersections ?
I can't figure out how to create the x/y coord for the ray.
I found this function:

Ray3D(Point3D const &p, Vector3D const &v):p(p),v(v)
intersection(Ray3D const &r, Sphere3D const &s)


float x=/*???*/;
float y=/*???*/;
Ray3D r1(Point3D(x,y,0),Vector3D(0,0,1));
Sphere3D s1(Point3D(-1.5f,0.0f,-6.0f),2.0f);
Sphere3D s2(Point3D(1.5f,0.0f,-7.0f),2.0f);
float t = intersection(r1,s1);
If t is #INF then there is no collision.
What do you think about that ?

POINT lMousePos;
GetCursorPos( &lMousePos );

float depth[1];
GLdouble modelm[16], projm[16], pos[3];
int view[4];
// ret;
glGetDoublev( GL_MODELVIEW_MATRIX, modelm );
glGetDoublev( GL_PROJECTION_MATRIX, projm );
glGetIntegerv( GL_VIEWPORT, (GLint*)view );
glReadPixels(lMousePos.x,lMousePos.y,1,1,GL_DEPTH_ COMPONENT,GL_FLOAT,depth);

Ray3D r1(Point3D(pos[0],pos[1],pos[2]),Vector3D(0,0,1));
Sphere3D s1(Point3D(-1.5f,0.0f,-6.0f),1.0f);
Sphere3D s2(Point3D(1.5f,0.0f,-7.0f),1.0f);
float t = intersection(r1,s1);
float t2 = intersection(r1,s2);
char text[100];
sprintf(text,"Collis 1: %f\nCollis 2: %f",t,t2);

That seems to work, I just have to Replace the "Point3D" settings to my model-translate-code :D