Exemplo n.º 1
0
  private void convertDataStructures(ModelMD3 model, MeshInfoMD3 meshHeader) {
    int i = 0;

    Object3d currentMesh = new Object3d();

    // Assign the vertex, texture coord and face count to our new structure
    currentMesh.setNumVertices(meshHeader.numVertices * meshHeader.numMeshFrames);
    currentMesh.setNumVert(meshHeader.numVertices);

    currentMesh.setNumTexcoords(meshHeader.numVertices);
    currentMesh.setNumFaces(meshHeader.numTriangles);
    currentMesh.setName(meshHeader.strName);

    // Go through all of the vertices and assign them over to our structure
    for (i = 0; i < currentMesh.getNumVertices() * meshHeader.numMeshFrames; i++) {
      Vector3f temp =
          new Vector3f(
              vertices[i].vertex[0] / 64.0f,
              vertices[i].vertex[1] / 64.0f,
              vertices[i].vertex[2] / 64.0f);

      currentMesh.setVertices(temp, i);
    }

    for (i = 0; i < currentMesh.getNumTexcoords(); i++) {
      Vector3f temp = new Vector3f(texCoords[i].u, -texCoords[i].v, 0);
      currentMesh.setTexcoords(temp, i);
    }

    // Go through all of the face data and assign it over to OUR structure
    for (i = 0; i < currentMesh.getNumFaces(); i++) {
      // Assign the vertex indices to our face data
      currentMesh.getFace(i).setVertices(0, triangles[i].vertexIndices[0]);
      currentMesh.getFace(i).setVertices(1, triangles[i].vertexIndices[1]);
      currentMesh.getFace(i).setVertices(2, triangles[i].vertexIndices[2]);

      // Assign the texture coord indices to our face data
      currentMesh.getFace(i).setTexCoords(0, triangles[i].vertexIndices[0]);
      currentMesh.getFace(i).setTexCoords(1, triangles[i].vertexIndices[1]);
      currentMesh.getFace(i).setTexCoords(2, triangles[i].vertexIndices[2]);
    }
    currentMesh.setDimension();
    // Here we add the current object (or frame) to our list object list
    model.addObject(currentMesh);
  }
Exemplo n.º 2
0
  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();
      }
    }
  }