public void updateSelectedOctant(GL gl, GLU glu, float[] mousePosition, float[] pickRectangle) {
    // Start Picking mode
    int capacity =
        1 * 4 * visibleLeaves.size(); // 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.glDisable(GL.GL_CULL_FACE); // Disable flags

    gl.glInitNames();
    gl.glPushName(0);

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

    glu.gluPickMatrix(
        mousePosition[0],
        mousePosition[1],
        pickRectangle[0],
        pickRectangle[1],
        drawable.getViewport());
    gl.glMultMatrixd(drawable.getProjectionMatrix());

    gl.glMatrixMode(GL.GL_MODELVIEW);

    // Draw the nodes' cube int the select buffer
    int hitName = 1;
    for (int i = 0; i < visibleLeaves.size(); i++) {
      Octant node = visibleLeaves.get(i);
      gl.glLoadName(hitName);
      node.displayOctant(gl);
      hitName++;
    }

    // Restoring the original projection matrix
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPopMatrix();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glFlush();

    // Returning to normal rendering mode
    int nbRecords = gl.glRenderMode(GL.GL_RENDER);
    if (vizController.getVizModel().isCulling()) {
      gl.glEnable(GL.GL_CULL_FACE);
      gl.glCullFace(GL.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);
    }
  }
Esempio n. 2
0
  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 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);
  }
  public void displayOctree(GL gl, GLU glu) {
    gl.glDisable(GL.GL_CULL_FACE);
    gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
    for (Octant o : visibleLeaves) {
      gl.glColor3f(1, 0.5f, 0.5f);
      o.displayOctant(gl);
      o.displayOctantInfo(gl, glu);
    }
    if (!vizController.getVizConfig().isWireFrame()) {
      gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
    }

    if (vizController.getVizModel().isCulling()) {
      gl.glEnable(GL.GL_CULL_FACE);
      gl.glCullFace(GL.GL_BACK);
    }
  }