PDA

View Full Version : problem with picking



GreenCat
05-11-2005, 03:48 AM
when i pick one object the number of picking is set to 1. But when i click my mouse to a space that there is no object then the number of picking is increasing to 3 instead of being 0 .
What is the problem ?

I am using gluPickMatrix.
Also it is not so accurate.

Relic
05-11-2005, 04:05 AM
Mind that OpenGL coordinates are not Window coordinates!
The OpenGL coordinates use a bottom left origin, mouse coordinates are top left.
You need to invert the y-axis before sending it to OpenGL
yPicked = windowHeight - mouseY - 1;
If that's not it, post your matrix setup code.

For debugging it's helpful to render with the projecton you set with gluPickMatrix to see if it is where you clicked.

GreenCat
05-11-2005, 04:38 AM
this is the code of the mouse procedure

if (button != GLUT_LEFT_BUTTON || action !=GLUT_DOWN || render_style != USE_TETRA)
return;
Xorigin = xMouse;
Yorigin = height - yMouse;
glSelectBuffer (pickBufferSize, pickBuffer);
glRenderMode (GL_SELECT);
glInitNames();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glGetIntegerv(GL_VIEWPORT,vpArray);
gluPickMatrix (GLdouble (xMouse),GLdouble (vpArray[3] - yMouse), 5.0, 5.0, vpArray);

glFrustum( minx, maxx, miny, maxy, my_near, my_far);
DrawTetra(GL_SELECT);

glMatrixMode(GL_PROJECTION);
glPopMatrix();

glFlush();

nPicks = glRenderMode (GL_RENDER);

ProcessPicks (nPicks,pickBuffer);

glutPostRedisplay();

gamefish
05-11-2005, 04:59 AM
OpenGL APIs usually do not specify how close to an object we must point for the object to be indentified.
That means, the picking process is somehow not very precise.

Relic
05-11-2005, 05:03 AM
Yorign is calculated with Window height but not used.
Picking is calculated with viewport height.
Is the viewport height == window height?
Both are off by one.

Render the thing and look if the image shows the 5x5 pixels you picked. If not debug all values.

Or take this working example and change it to your needs:
http://www.sgi.com/products/software/opengl/examples/glut/examples/source/triselect.c

Relic
05-11-2005, 05:06 AM
Originally posted by gamefish:
OpenGL APIs usually do not specify how close to an object we must point for the object to be indentified.
That means, the picking process is somehow not very precise.No, OpenGL's selection buffer will exactly pick what the view contains. It's your decison how small the pick area is.