object picking/selection

I need some help with object selection…

I can’t use GL_SELECT for that, because that only supports 128 (on my computer) names… :frowning:
I also read that this is too slow on nvidia cards :wink:

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


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…

I just checked the link and it works fine. :slight_smile: 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

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§,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 );
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
Collis 2: %f",t,t2);

That seems to work, I just have to Replace the “Point3D” settings to my model-translate-code :smiley: