Ejemplo n.º 1
0
  @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");
  }
Ejemplo n.º 2
0
  @Override
  public void init() throws IOException {

    super.init();
    camera = new Camera(true);
    camera.setPosition(-17f, 20f, 17f, 0, 0, 0, 0, 1, 0);
    float df = 100.0f;

    // Precalculate the Sine and Cosine Lookup Tables.
    // Basically, loop through 360 Degrees and assign the Radian
    // value to each array index (which represents the Degree).
    for (int i = 0; i < 360; i++) {
      g_fSinTable[i] = (float) Math.sin(AR_DegToRad(i));
      g_fCosTable[i] = (float) Math.cos(AR_DegToRad(i));
    }

    pObj = new Sphere();
    pObj.setOrientation(GLU_OUTSIDE);

    Octree.debug = new BoundingBox();
    // Turn lighting on initially
    Octree.turnLighting = true;

    // The current amount of end nodes in our tree (The nodes with vertices stored in them)
    Octree.totalNodesCount = 0;

    // This stores the amount of nodes that are in the frustum
    Octree.totalNodesDrawn = 0;

    // The maximum amount of triangles per node.  If a node has equal or less
    // than this, stop subdividing and store the face indices in that node
    Octree.maxTriangles = 800;

    // The maximum amount of subdivisions allowed (Levels of subdivision)
    Octree.maxSubdivisions = 5;

    // The number of Nodes we've checked for collision.
    Octree.numNodesCollided = 0;

    // Wheter the Object is Colliding with anything in the World or not.
    octree.setObjectColliding(false);

    // Wheter we test the whole world for collision or just the nodes we are in.
    Octree.octreeCollisionDetection = true;

    LoadWorld();

    // for(int i=0; i < g_World.getNumOfMaterials(); i++)
    // {
    //	System.out.println(g_World.getMaterials(i).getName() + " indice " + i);

    // }

    // for(int i=0; i < g_World.getNumOfObjects(); i++)
    // {
    //	System.out.println(g_World.getObject(i).getName());
    //	System.out.println(g_World.getObject(i).getMaterialID());
    // System.out.println(g_World.getPObject(i).getMaterialID());
    // }

    // System.out.println(g_World.getPMaterials(12).getColor()[0] + " " +
    // g_World.getPMaterials(12).getColor()[1]
    //                    + " " + g_World.getPMaterials(12).getColor()[2]);
    // System.out.println(g_World.getPMaterials(g_World.getPObject(6).getMaterialID()));

    inputManager = new InputManager();

    createGameActions();

    posLuz1F = Conversion.allocFloats(posLuz1);

    // Define a cor de fundo da janela de visualização como preto
    glClearColor(0, 0, 0, 1);

    // Ajusta iluminação
    glLight(GL_LIGHT0, GL_AMBIENT, Conversion.allocFloats(luzAmb1));
    glLight(GL_LIGHT0, GL_DIFFUSE, Conversion.allocFloats(luzDif1));
    glLight(GL_LIGHT0, GL_SPECULAR, Conversion.allocFloats(luzEsp1));

    // Habilita todas as fontes de luz
    glEnable(GL_LIGHT0);

    glEnable(GL_LIGHTING);
    // Agora posiciona demais fontes de luz
    glLight(GL_LIGHT0, GL_POSITION, posLuz1F);

    // Habilita Z-Buffer
    glEnable(GL_DEPTH_TEST);

    // Seleciona o modo de GL_COLOR_MATERIAL
    // glColorMaterial(GL_FRONT, GL_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);
    glMaterial(GL_FRONT, GL_SPECULAR, Conversion.allocFloats(spec));
    glMaterialf(GL_FRONT, GL_SHININESS, df);
  }