Example #1
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);
      }
    }
  }
Example #2
0
 /*
  * The nine squares are drawn. In selection mode, each square is given two
  * names: one for the row and the other for the column on the grid. The
  * color of each square is determined by its position on the grid, and the
  * value in the board[][] array.
  */
 private void drawSquares(GL2 gl, int mode) {
   int i, j;
   for (i = 0; i < 3; i++) {
     if (mode == GL2.GL_SELECT) {
       gl.glLoadName(i);
     }
     for (j = 0; j < 3; j++) {
       if (mode == GL2.GL_SELECT) {
         gl.glPushName(j);
       }
       gl.glColor3f((float) i / 3.0f, (float) j / 3.0f, (float) board[i][j] / 3.0f);
       gl.glRecti(i, j, i + 1, j + 1);
       if (mode == GL2.GL_SELECT) {
         gl.glPopName();
       }
     }
   }
 }
Example #3
0
 /*
  * The three rectangles are drawn. In selection mode, each rectangle is
  * given the same name. Note that each rectangle is drawn with a different z
  * value.
  */
 private void drawRects(GL2 gl, int mode) {
   if (mode == GL2.GL_SELECT) gl.glLoadName(1);
   gl.glBegin(GL2.GL_QUADS);
   gl.glColor3f(1.0f, 1.0f, 0.0f);
   gl.glVertex3i(2, 0, 0);
   gl.glVertex3i(2, 6, 0);
   gl.glVertex3i(6, 6, 0);
   gl.glVertex3i(6, 0, 0);
   gl.glColor3f(0.0f, 1.0f, 1.0f);
   gl.glVertex3i(3, 2, -1);
   gl.glVertex3i(3, 8, -1);
   gl.glVertex3i(8, 8, -1);
   gl.glVertex3i(8, 2, -1);
   gl.glColor3f(1.0f, 0.0f, 1.0f);
   gl.glVertex3i(0, 2, -2);
   gl.glVertex3i(0, 7, -2);
   gl.glVertex3i(5, 7, -2);
   gl.glVertex3i(5, 2, -2);
   gl.glEnd();
 }
Example #4
0
  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);
      }
    }
  }