Example #1
0
  protected void render() {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

    glLoadIdentity();

    camera.look();

    // Each frame we calculate the new frustum.  In reality you only need to
    // calculate the frustum when we move the camera.
    GameCore.gFrustum.calculateFrustum();

    // Initialize the total node count that is being draw per frame
    Octree.totalNodesDrawn = 0;

    glPushMatrix();
    // Here we draw the octree, starting with the root node and recursing down each node.
    // This time, we pass in the root node and just the original world model.  You could
    // just store the world in the root node and not have to keep the original data around.
    // This is up to you.  I like this way better because it's easy, though it could be
    // more error prone.
    octree.drawOctree(octree, g_World);
    glPopMatrix();

    // Render the cubed nodes to visualize the octree (in wire frame mode)
    if (g_bDisplayNodes) Octree.debug.drawBoundingBox();

    glPushMatrix();
    // If there was a collision, make the Orange ball Red.
    if (octree.isObjectColliding()) {
      glColor3f(1.0f, 0.0f, 0.0f);
    } else {
      glColor3f(1.0f, 0.5f, 0.0f); // Disable Lighting.
    }
    // Move the Ball into place.
    glTranslatef(g_BallEntity.x, g_BallEntity.y, g_BallEntity.z);

    glDisable(GL_LIGHTING);
    // Draw the Ground Intersection Line.
    glBegin(GL_LINES);
    glColor3f(1, 1, 1);
    glVertex3f(g_vGroundISector[0].x, g_vGroundISector[0].y, g_vGroundISector[0].z);
    glVertex3f(g_vGroundISector[1].x, g_vGroundISector[1].y, g_vGroundISector[1].z);
    glEnd();

    // Draw the Forward Intersection Line.
    glBegin(GL_LINES);
    glColor3f(1, 1, 0);
    glVertex3f(
        g_vForwardISector[0].x * 10.0f, g_vForwardISector[0].y, g_vForwardISector[0].z * 10.0f);
    glVertex3f(
        g_vForwardISector[1].x * 10.0f, g_vForwardISector[1].y, g_vForwardISector[1].z * 10.0f);
    glEnd();

    // Re-enable lighting.
    glEnable(GL_LIGHTING);

    // System.out.println("x " + g_BallEntity.x + " y " + g_BallEntity.y);
    // Draw it!
    pObj.draw(g_BallEntity.fRadius, 20, 20);

    glPopMatrix();

    screen.setTitle(
        "Triangles: "
            + Octree.maxTriangles
            + "  -Total Draw: "
            + Octree.totalNodesDrawn
            + "  -Subdivisions: "
            + Octree.maxSubdivisions
            + "  -FPS: "
            + FPSCounter.get()
            + "  -Node Collisions: "
            + Octree.numNodesCollided
            + "  -Object Colliding? "
            + octree.isObjectColliding());
  }