I populate my 3D-space with spheres that contain smaller spheres. When the spheres doesn't have anything inside of them, my selection routine works fine. But when my spheres contain smaller spheres I don't get any selections. I think that this has to do with glPushName and glPushMatrix but I don't know how.
See pseudocode for the drawing method below.
1 2 3 4 5 6 7 8 9 10 11 12
| for (int i = 0; i < counter; i++) { gl.glPushMatrix(); gl.glPopMatrix(); }
glPushName(uniqueId) gl.glPushMatrix() gl.glPopMatrix() gl.glPopName(); |
Selection routines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| private int[] setupSelection() { int objectsFound = 0; int viewportCoords[] = new int [4]; int selectBuffer[] = new int [32]; gl.glSelectBuffer(32, selectBuffer); gl.glGetIntegerv(GL.GL_VIEWPORT, viewportCoords); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glRenderMode(GL.GL_SELECT); gl.glLoadIdentity(); glu.gluPickMatrix(selectedPoint.getX(), viewportCoords[3] - selectedPoint.getY(), 2, 2, viewportCoords);
glu.gluPerspective(45.0f,(float)HEIGTH/(float)WIDTH,0.1f,150.0f); gl.glMatrixMode(GL.GL_MODELVIEW); return selectBuffer;
}
private int getSelection(int[] selectBuffer) { int objectsFound; objectsFound = gl.glRenderMode(GL.GL_RENDER); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); System.out.println("Objects found : "+objectsFound); if (objectsFound > 0) { int lowestDepth = selectBuffer[1]; int selectedObject = selectBuffer[3]; for (int i = 1; i < objectsFound; i++) { if (selectBuffer[(i * 4) + 1] < lowestDepth) { lowestDepth = selectBuffer[(i * 4) + 1]; selectedObject = selectBuffer[(i * 4) + 3]; } } System.out.println("Selected object : "+selectedObject); return selectedObject; } return 0; } |
Best Regards,
Sami