コード例 #1
0
ファイル: TesteMD2.java プロジェクト: yuripourre/exemplwjgl
  @Override
  public void init() throws IOException {
    super.init();

    screen.setTitle("MD2 Loader");

    createGameActions();

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, 800 / 600, 1.0f, 2000.0f);
    glMatrixMode(GL_MODELVIEW);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    // Here, we turn on a lighting and enable lighting.  We don't need to
    // set anything else for lighting because we will just take the defaults.
    // We also want color, so we turn that on

    // Habilita Z-Buffer
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHT0); // Turn on a light with defaults set
    glEnable(GL_LIGHTING); // Turn on lighting
    glEnable(GL_COLOR_MATERIAL); // Allow color

    // To make our model render somewhat faster, we do some front back culling.
    // It seems that Quake2 orders their polygons clock-wise.
    // Seleciona o modo de aplicação da textura
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, modo);
    glEnable(GL_CULL_FACE); // Turn culling on
    glCullFace(GL_FRONT);
    glEnable(GL_TEXTURE_2D);
    g_World.load(FILE_NAME);
    // g_LoadMd2.importMD2(g_World, "modelsd2/model8/head.md2", "modelsd2/model8/head.png");
    // g_LoadMd2.importMD2(g_World, "modelsd2/model8/throne.md2", "modelsd2/model8/throne.png");
  }
コード例 #2
0
ファイル: TesteMD2.java プロジェクト: yuripourre/exemplwjgl
  public void render() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
    glLoadIdentity(); // Reset The matrix

    //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

    // Give OpenGL our position,	then view,		then up vector
    gluLookAt(0, 1.5f, 100, 0, .5f, 0, 0, 1, 0);

    // We want the model to rotate around the axis so we give it a rotation
    // value, then increase/decrease it. You can rotate right of left with the arrow keys.

    glRotatef(g_RotateX, 0, 1.0f, 0); // Rotate the object around the Y-Axis
    g_RotateX += g_RotationSpeed; // Increase the speed of rotation

    // Make sure we have valid objects just in case. (size() is in the vector class)
    if (g_World.getObject().size() <= 0) return;

    for (int i = 0; i < g_World.getObject().size(); i++) {
      // Get the current object that we are displaying
      Object3d pObject = g_World.getObject(i);

      glBindTexture(GL_TEXTURE_2D, pObject.getMaterialID());

      // Render lines or normal triangles mode, depending on the global variable
      glBegin(g_ViewMode);

      // Go through all of the faces (polygons) of the object and draw them
      for (int j = 0; j < pObject.getNumFaces(); j++) {
        // Go through each corner of the triangle and draw it.
        for (int whichVertex = 0; whichVertex < 3; whichVertex++) {
          // Get the index for each point in the face
          int index = pObject.getFace(j).getVertices(whichVertex);

          // Get the index for each texture coord in the face
          int index2 = pObject.getFace(j).getTexCoords(whichVertex);

          // Give OpenGL the normal for this vertex.  Notice that we put a
          // - sign in front.  It appears that because of the ordering of Quake2's
          // polygons, we need to invert the normal
          // glNormal3f(-pObject.getNormal(index).x, -pObject.getNormal(index).y,
          // -pObject.getNormal(index).z);

          // Make sure there was a UVW map applied to the object or else it won't have tex coords.
          if (pObject.getNumTexcoords() > 0) {
            glTexCoord2f(pObject.getTexcoords(index2).s, pObject.getTexcoords(index2).t);
          }

          // Pass in the current vertex of the object (Corner of current face)
          glVertex3f(
              pObject.getVertices(index).x,
              pObject.getVertices(index).y,
              pObject.getVertices(index).z);
        }
      }

      glEnd();
    }
    // Render the cubed nodes to visualize the octree (in wire frame mode)
    if (g_bDisplayNodes) {
      // TOctree.g_Debug.renderDebugLines();
      for (int j = 0; j < g_World.getObject().size(); j++) {
        g_World.getObject(j).drawBoundingBox();
      }
    }
  }
コード例 #3
0
ファイル: Testesala.java プロジェクト: yuripourre/exemplwjgl
  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());
  }