Picking

I have gone thru the NeHe picking tut and have it working to a small degree. If I remove my camera, I get picking result.

My issue comes in with my camera. I use GLU.gluLookAt to place my camera. With the camera active, pikcing fails. If I remove it and use translate to move outward to see my objects, picking works.

What do I need to do to my camera for picking 3d objects? THanks! :slight_smile:

Hey MickeyB. I have struggled with picking a bit myself. Its hard to tell what your problem is without any source code or details.

But the principles in picking is as follows:

First you draw your scene as you do normaly, in the same frame you rdraw your scene with two exceptions.


//The modelview mode is in GL_SELECT, meaning nothing will be drawn
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glRenderMode(GL11.GL_SELECT);
GL11.glSelectBuffer(ibuf); // buffer holding selections



//Make the projection.. eg what is shown at screen ZOOM into a 5 x 5 pixels image at mouse position. 
GL11.glMatrixMode(GL11.GL_PROJECTION);
GLU.gluPickMatrix(
                  mouseX,
                  mouseY,
                  5.0f,
                  5.0f,
                  _viewPortarr);

You can check wether there were any hits


int hits =GL11.glRenderMode(GL11.GL_RENDER);

Thanks. I will review some more.

btw as a debugging feature you can omit the

GL11.glRenderMode(GL11.GL_SELECT);

in the second rendering. This way you can see if the picking projection actually works… Eg you zoom into the correct object.

ok, if I turn off the camera and do a tranlsate of -35 z, the ship is centered on my screen and I can pick it. Removing GL_SELECT cause a quick zoom into the ships rear. This is good!

Now with the camera on at

GLU.gluLookAt(0f, 15f, 35f,0.0f,8.0f,0.0f,0.0f,1.0f,0.0f);

and the translate turned off…
I get nothing…

doh!

[sung to any tune you choose]
“I got it, I got it, I got it, I got it!”

;D

In select, left out camera call, used same translation and object draw from render method and I get nice clean picks!! Thanks all!!