Ejemplo n.º 1
0
 public void listenInput(GameContainer gc, StateBasedGame sbg, int delta) {
   Input input = gc.getInput();
   if (input.isKeyPressed(Input.KEY_DOWN)) {
     cursor = Math.min(cursor + 1, 2);
   } else if (input.isKeyPressed(Input.KEY_UP)) {
     cursor = Math.max(cursor - 1, 0);
   }
   if (cursor == 0 && input.isKeyDown(Input.KEY_RIGHT)) {
     control.changeVolume(delta * 0.5f);
   } else if (cursor == 0 && input.isKeyDown(Input.KEY_LEFT)) {
     control.changeVolume(-delta * 0.5f);
   }
   if (cursor == 1 && input.isKeyDown(Input.KEY_RIGHT)) {
     control.goFullScreen(true);
   } else if (cursor == 1 && input.isKeyDown(Input.KEY_LEFT)) {
     control.goFullScreen(false);
   }
   if (cursor == 2 && input.isKeyDown(Input.KEY_RIGHT)) {
     control.changeBrightness(+5);
   } else if (cursor == 2 && input.isKeyDown(Input.KEY_LEFT)) {
     control.changeBrightness(-5);
   } else if (input.isKeyDown(Input.KEY_ENTER)) {
     ((GameController) gc).changeState("pause");
     //			sbg.enterState(((Game)sbg).prevState);
     ((GameController) gc).changeState(((Game) sbg).prevState);
   }
 }
Ejemplo n.º 2
0
  /**
   * Draw a gear wheel. You'll probably want to call this function when building a display list
   * since we do a lot of trig here.
   *
   * @param inner_radius radius of hole at center
   * @param outer_radius radius at center of teeth
   * @param width width of gear
   * @param teeth number of teeth
   * @param tooth_depth depth of tooth
   */
  private void gear(
      float inner_radius, float outer_radius, float width, int teeth, float tooth_depth) {
    int i;
    float r0, r1, r2;
    float angle, da;
    float u, v, len;

    r0 = inner_radius;
    r1 = outer_radius - tooth_depth / 2.0f;
    r2 = outer_radius + tooth_depth / 2.0f;

    da = 2.0f * (float) Math.PI / teeth / 4.0f;

    glShadeModel(GL_FLAT);

    glNormal3f(0.0f, 0.0f, 1.0f);

    /* draw front face */
    glBegin(GL_QUAD_STRIP);
    for (i = 0; i <= teeth; i++) {
      angle = i * 2.0f * (float) Math.PI / teeth;
      glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
      glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
      if (i < teeth) {
        glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
        glVertex3f(
            r1 * (float) Math.cos(angle + 3.0f * da),
            r1 * (float) Math.sin(angle + 3.0f * da),
            width * 0.5f);
      }
    }
    glEnd();

    /* draw front sides of teeth */
    glBegin(GL_QUADS);
    for (i = 0; i < teeth; i++) {
      angle = i * 2.0f * (float) Math.PI / teeth;
      glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
      glVertex3f(
          r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
      glVertex3f(
          r2 * (float) Math.cos(angle + 2.0f * da),
          r2 * (float) Math.sin(angle + 2.0f * da),
          width * 0.5f);
      glVertex3f(
          r1 * (float) Math.cos(angle + 3.0f * da),
          r1 * (float) Math.sin(angle + 3.0f * da),
          width * 0.5f);
    }
    glEnd();

    /* draw back face */
    glBegin(GL_QUAD_STRIP);
    for (i = 0; i <= teeth; i++) {
      angle = i * 2.0f * (float) Math.PI / teeth;
      glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
      glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
      glVertex3f(
          r1 * (float) Math.cos(angle + 3 * da),
          r1 * (float) Math.sin(angle + 3 * da),
          -width * 0.5f);
      glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
    }
    glEnd();

    /* draw back sides of teeth */
    glBegin(GL_QUADS);
    for (i = 0; i < teeth; i++) {
      angle = i * 2.0f * (float) Math.PI / teeth;
      glVertex3f(
          r1 * (float) Math.cos(angle + 3 * da),
          r1 * (float) Math.sin(angle + 3 * da),
          -width * 0.5f);
      glVertex3f(
          r2 * (float) Math.cos(angle + 2 * da),
          r2 * (float) Math.sin(angle + 2 * da),
          -width * 0.5f);
      glVertex3f(
          r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
      glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
    }
    glEnd();

    /* draw outward faces of teeth */
    glBegin(GL_QUAD_STRIP);
    for (i = 0; i < teeth; i++) {
      angle = i * 2.0f * (float) Math.PI / teeth;
      glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
      glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
      u = r2 * (float) Math.cos(angle + da) - r1 * (float) Math.cos(angle);
      v = r2 * (float) Math.sin(angle + da) - r1 * (float) Math.sin(angle);
      len = (float) Math.sqrt(u * u + v * v);
      u /= len;
      v /= len;
      glNormal3f(v, -u, 0.0f);
      glVertex3f(
          r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
      glVertex3f(
          r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
      glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
      glVertex3f(
          r2 * (float) Math.cos(angle + 2 * da),
          r2 * (float) Math.sin(angle + 2 * da),
          width * 0.5f);
      glVertex3f(
          r2 * (float) Math.cos(angle + 2 * da),
          r2 * (float) Math.sin(angle + 2 * da),
          -width * 0.5f);
      u = r1 * (float) Math.cos(angle + 3 * da) - r2 * (float) Math.cos(angle + 2 * da);
      v = r1 * (float) Math.sin(angle + 3 * da) - r2 * (float) Math.sin(angle + 2 * da);
      glNormal3f(v, -u, 0.0f);
      glVertex3f(
          r1 * (float) Math.cos(angle + 3 * da),
          r1 * (float) Math.sin(angle + 3 * da),
          width * 0.5f);
      glVertex3f(
          r1 * (float) Math.cos(angle + 3 * da),
          r1 * (float) Math.sin(angle + 3 * da),
          -width * 0.5f);
      glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
    }
    glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), width * 0.5f);
    glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), -width * 0.5f);
    glEnd();

    glShadeModel(GL_SMOOTH);

    /* draw inside radius cylinder */
    glBegin(GL_QUAD_STRIP);
    for (i = 0; i <= teeth; i++) {
      angle = i * 2.0f * (float) Math.PI / teeth;
      glNormal3f(-(float) Math.cos(angle), -(float) Math.sin(angle), 0.0f);
      glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
      glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
    }
    glEnd();
  }
Ejemplo n.º 3
0
  // Convert from Degrees to Radians.
  private float AR_DegToRad(float x) {

    return (float) Math.toRadians(x);
  }
Ejemplo n.º 4
0
  // Convert from Radians to Degrees.
  private float AR_RadToDeg(float x) {

    return (float) Math.toDegrees(x);
  }
Ejemplo n.º 5
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);
  }