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