PDA

View Full Version : picking, getting an extra hit



JTW
12-12-2003, 08:45 AM
hi everyone;

for the most part, my picking code works fine. but what i can't figure out is that in addition to the object i click on, i always get an extra hit. for instance, even with only one object on the name stack, i get 2 hits returned if i click on the object, and 1 hit if i don't click on the object. except for the dummy pushname(0), i only push one name on the stack. any ideas?

in the DrawGLScene() function i have:
glLoadName(10);
object.render();

and the picking code is:
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);
glSelectBuffer(BUFSIZE,selectBuf);

glRenderMode(GL_SELECT);

glInitNames();
glPushName(0);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

gluPickMatrix(x,768-y, 10.0f, 10.0f, viewport);
gluPerspective(45.0f,double(1024)/double(768),0.1f,100000.0f); // same as in projection mode
glMatrixMode(GL_MODELVIEW);

glPushMatrix();
DrawGLScene();
glPopMatrix();

glMatrixMode(GL_PROJECTION);

glPopMatrix();
glMatrixMode(GL_MODELVIEW);

GLint hits;
// returning to normal rendering mode
hits = glRenderMode(GL_RENDER);

blip
12-12-2003, 11:25 AM
That looks pretty much like my picking code, which I just got working for 3d objects and text. I was getting an extra hit also. Turns out I was changing the Projection Matrix inside my draw scene which caused my text to always get hit. But you are only drawing one object so..??? I casted the x and y coordinates in gluPickMatrix to doubles. Also, what are the object names that are returned in the pick buffer. Are they both name 10? Just some ideas.

JTW
12-13-2003, 05:46 PM
the names of hits are: the object i want, and the dummy name i push immediately after initializing the name stack (i know this because when i change the dummy value, that's what i get as a hit).

what constitutes changing the projection matrix? there are some calls to glRotatef() and glTranslatef() when i set up the view/camera, but i simply can't figure out what the extra hit might be. if it helps, the depth of the first (and closest) hit is always 2147482496 which couldn't possibly be right... could it?

thanks.

[This message has been edited by JTW (edited 12-13-2003).]