Picking/Selection problems

Hello,

I want to select an object in the canvas by double clicking. My application creates 19 array list objects and I always get 19 hits which have got all the same name which is the first array list index.

output:

hit i=1: offset=0
number of names=1
z1=0.9923994 z2=-0.9954901
names: 1

hit i=2: offset=4
number of names=1
z1=0.9164743 z2=0.9992776
names: 1

hit i=3: offset=8
number of names=1
z1=0.9230722 z2=-0.9948257
names: 1

Do somebody know why? Here the some code:

public void reshape(GLDrawable drawable, int x, int y, int width, int height) {
gl.glOrtho(-geometry.width-maxZ/2, geometry.width+maxZ/2, geometry.height-maxZ/2, geometry.height+maxZ/2, -10000.0f, 10000.0f);
}

private void renderAll(int mode) {
gl.glLoadIdentity();
gl.glTranslated(Sim3DParameters.view_movex, Sim3DParameters.view_movey, Sim3DParameters.view_movez);
gl.glRotated(Sim3DParameters.view_rotx, 1.0, 0.0, 0.0);
gl.glRotated(Sim3DParameters.view_roty, 0.0, 1.0, 0.0);
gl.glRotated(Sim3DParameters.view_rotz, 0.0, 0.0, 1.0);

  int index;
  if (mode == GL.GL_SELECT) {
      for (int i = 0; i < listIndices.size(); i++) {
        index = ((Integer)listIndices.get(i)).intValue();
        gl.glLoadName(index);      //gl.glPushName(index);
        gl.glCallList(index);
      }
  }
  else {
      for (int i = 0; i < listIndices.size(); i++) {
        index = ((Integer)listIndices.get(i)).intValue();
        gl.glCallList(index);
      }      
  }

}

public void pickTubes(int xMouse, int yMouse, GLDrawable drawable) {
int bufferSize = 512;
IntBuffer pickBuffer = BufferUtils.newIntBuffer(bufferSize);
int hits, viewport[] = new int[4];

  gl.glGetIntegerv(GL.GL_VIEWPORT, viewport);      // obtain parameters for current viewport
  gl.glSelectBuffer(bufferSize, pickBuffer);       // designate buffer
  gl.glRenderMode(GL.GL_SELECT);                  // activate picking
  gl.glInitNames();                        // initialize object-id stack
  gl.glPushName(0);

  gl.glMatrixMode(GL.GL_PROJECTION);
  gl.glPushMatrix();
  gl.glLoadIdentity();

  glu.gluPickMatrix(xMouse, viewport[3]-yMouse, 5.0, 5.0, viewport);
  Dimension size = drawable.getSize();
  reshape(drawable, 0, 0, (int)size.getWidth(), (int)size.getHeight());
  renderAll(GL.GL_SELECT);

  gl.glMatrixMode(GL.GL_PROJECTION);
  gl.glPopMatrix();
  gl.glFlush();

  hits = gl.glRenderMode(GL.GL_RENDER);
  processPicks(hits, pickBuffer);

}

Thanks a lot.
Kati

ol’ friend picking… :slight_smile:

I don’t see a real mistake, but there might be something which lays outside of your quoted code (i.e. in your call list).

It seems that all of your scene objects (which you render in the call list) get the same name assigned. So I guess that there might be something wrong with your listIndices list?

I’m sorry that I can’t provide really fruitful hints here. I can at least point at an example class for picking which I wrote a few days ago
http://user.cs.tu-berlin.de/~schabby/PickingExample.java.

Maybe you should also consider not to call renderAll(GL_SELECT) directly in pickTubes but rather let it be regularly called by your update thread (e.g. net.java.games.jogl.Animator). You may also move your selection buffer evaluation behind the call list statement in the GL_SELECTauswertung
if block. I don’t know for sure if this is an related issue here, but I it caused some problems once in my program.

Thanks Schabby for the quick answer.

[quote]It seems that all of your scene objects (which you render in the call list) get the same name assigned. So I guess that there might be something wrong with your listIndices list?
[/quote]
No, each list entry has it’s own index.

[quote]I’m sorry that I can’t provide really fruitful hints here. I can at least point at an example class for picking which I wrote a few days ago
http://user.cs.tu-berlin.de/~schabby/PickingExample.java.
[/quote]
Thanks, but it doesn’t help. I read and tried many examples during the last week. All examples are working fine, but I can’t see any differences in my application.

[quote]Maybe you should also consider not to call renderAll(GL_SELECT) directly in pickTubes but rather let it be regularly called by your update thread (e.g. net.java.games.jogl.Animator).
[/quote]
pickTubes is called by display(). Thus, it is called directly.

Then the application crashed with an unexpected exception.

I can’t find any mistakes and I don’t understand why it doesn’t work. ???

Kati

P.S.: One object in the array list consists of e.g. ten cylinders and two cycles. Do I have to create one entry for each cylinder or cycle?
Could that be the problem? ???

Oops, Sorry! I lost the thread out of my view. Do you still have the problem? If yes, you can can send me your code (Johannes.Schaback at gmail.com) and i’ll check if I find something. Since I’m not an English native speaker, the problem will be probably solved much faster if I have a look on the code instead of writing pages of entries in this thread :slight_smile:

What kind of exception crashes your app?