public void updateVisibleOctant(GL gl) { // Limits refreshLimits(); // Switch to OpenGL select mode int capacity = 1 * 4 * leaves.getCount(); // Each object take in maximium : 4 * name stack depth IntBuffer hitsBuffer = BufferUtil.newIntBuffer(capacity); gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer); gl.glRenderMode(GL.GL_SELECT); gl.glInitNames(); gl.glPushName(0); gl.glDisable(GL.GL_CULL_FACE); // Disable flags // Draw the nodes cube in the select buffer for (Octant n : leaves) { n .resetUpdatePositionFlag(); // Profit from the loop to do this, because this method is // always after updating position gl.glLoadName(n.getNumber()); n.displayOctant(gl); } int nbRecords = gl.glRenderMode(GL.GL_RENDER); if (vizController.getVizModel().isCulling()) { gl.glEnable(GL.GL_CULL_FACE); gl.glCullFace(GL.GL_BACK); } visibleLeaves.clear(); // 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.getItem(hit); visibleLeaves.add(nodeHit); } if (minDepth != -1) { Octant closestOctant = leaves.getItem(minDepth); Vec3f pos = new Vec3f(closestOctant.getPosX(), closestOctant.getPosY(), closestOctant.getPosZ()); limits.setClosestPoint(pos); } // System.out.println(minDepth); }
void removeLeaf(Octant leaf) { leaves.remove(leaf); }
void addLeaf(Octant leaf) { leaves.add(leaf); }