// private void pickSquares(GL gl, int button, int state, int x, int y) private void pickSquares(GL2 gl) { int selectBuf[] = new int[BUFSIZE]; IntBuffer selectBuffer = IntBuffer.wrap(selectBuf); int hits; int viewport[] = new int[4]; // if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) return; gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport, 0); gl.glSelectBuffer(BUFSIZE, selectBuffer); gl.glRenderMode(GL2.GL_SELECT); gl.glInitNames(); gl.glPushName(0); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); /* create 5x5 pixel picking region near cursor location */ glu.gluPickMatrix( (double) pickPoint.x, (double) (viewport[3] - pickPoint.y), 5.0, 5.0, viewport, 0); glu.gluOrtho2D(0.0, 3.0, 0.0, 3.0); drawSquares(gl, GL2.GL_SELECT); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPopMatrix(); gl.glFlush(); hits = gl.glRenderMode(GL2.GL_RENDER); selectBuffer.get(selectBuf); processHits(hits, selectBuf); }
/* * sets up selection mode, name stack, and projection matrix for picking. * Then the objects are drawn. */ private void pickRects(GL2 gl) { int[] selectBuf = new int[BUFSIZE]; IntBuffer selectBuffer = GLBuffers.newDirectIntBuffer(BUFSIZE); int hits; int viewport[] = new int[4]; // int x, y; gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); gl.glSelectBuffer(BUFSIZE, selectBuffer); gl.glRenderMode(GL2.GL_SELECT); gl.glInitNames(); gl.glPushName(-1); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); /* create 5x5 pixel picking region near cursor location */ glu.gluPickMatrix( (double) pickPoint.x, (double) (viewport[3] - pickPoint.y), // 5.0, 5.0, viewport, 0); gl.glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5); drawRects(gl, GL2.GL_SELECT); gl.glPopMatrix(); gl.glFlush(); hits = gl.glRenderMode(GL2.GL_RENDER); selectBuffer.get(selectBuf); processHits(hits, selectBuf); }
public void updateVisibleOctant(GL2 gl) { if (leavesCount > 0) { // Limits refreshLimits(); // Switch to OpenGL2 select mode int capacity = 1 * 4 * leavesCount; // Each object take in maximium : 4 * name stack depth IntBuffer hitsBuffer = Buffers.newDirectIntBuffer(capacity); gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer); gl.glRenderMode(GL2.GL_SELECT); gl.glInitNames(); gl.glPushName(0); gl.glDisable(GL2.GL_CULL_FACE); // Disable flags // Draw the nodes cube in the select buffer for (Octant n : leaves) { if (n != null) { gl.glLoadName(n.leafId); n.displayOctant(gl); n.visible = false; } } visibleLeaves = 0; int nbRecords = gl.glRenderMode(GL2.GL_RENDER); if (vizController.getVizModel().isCulling()) { gl.glEnable(GL2.GL_CULL_FACE); gl.glCullFace(GL2.GL_BACK); } // Get the hits and add the nodes' objects to the array int depth = Integer.MAX_VALUE; int minDepth = -1; for (int i = 0; i < nbRecords; i++) { int hit = hitsBuffer.get(i * 4 + 3); // -1 Because of the glPushName(0) int minZ = hitsBuffer.get(i * 4 + 1); if (minZ < depth) { depth = minZ; minDepth = hit; } Octant nodeHit = leaves[hit]; nodeHit.visible = true; visibleLeaves++; } if (minDepth != -1) { Octant closestOctant = leaves[minDepth]; Vec3f pos = new Vec3f(closestOctant.getPosX(), closestOctant.getPosY(), closestOctant.getPosZ()); limits.setClosestPoint(pos); } } }
public void updateSelectedOctant(GL2 gl, GLU glu, float[] mousePosition, float[] pickRectangle) { if (visibleLeaves > 0) { // Start Picking mode int capacity = 1 * 4 * visibleLeaves; // Each object take in maximium : 4 * name stack depth IntBuffer hitsBuffer = Buffers.newDirectIntBuffer(capacity); gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer); gl.glRenderMode(GL2.GL_SELECT); gl.glDisable(GL2.GL_CULL_FACE); // Disable flags gl.glInitNames(); gl.glPushName(0); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); glu.gluPickMatrix( mousePosition[0], mousePosition[1], pickRectangle[0], pickRectangle[1], drawable.getViewport()); gl.glMultMatrixf(drawable.getProjectionMatrix()); gl.glMatrixMode(GL2.GL_MODELVIEW); // Draw the nodes' cube int the select buffer List<Octant> visibleLeaves = new ArrayList<Octant>(); for (Octant n : leaves) { if (n != null && n.visible) { int i = visibleLeaves.size() + 1; visibleLeaves.add(n); gl.glLoadName(i); n.displayOctant(gl); } } // Restoring the original projection matrix gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glFlush(); // Returning to normal rendering mode int nbRecords = gl.glRenderMode(GL2.GL_RENDER); if (vizController.getVizModel().isCulling()) { gl.glEnable(GL2.GL_CULL_FACE); gl.glCullFace(GL2.GL_BACK); } // Clean previous selection selectedLeaves.clear(); // Get the hits and put the node under selection in the selectionArray for (int i = 0; i < nbRecords; i++) { int hit = hitsBuffer.get(i * 4 + 3) - 1; // -1 Because of the glPushName(0) Octant nodeHit = visibleLeaves.get(hit); selectedLeaves.add(nodeHit); } } }