Пример #1
0
  public void shoot() {
    // this is very similar to the above method
    int maxIterations = 500;
    float newX = 0, newY = 0, newZ = 0;

    for (int i = 0; i < maxIterations; i += 1) {
      newX =
          -(controller.getX()
              + (float)
                  (-(i)
                      * (Math.sin(Math.toRadians(controller.getAngleX())))
                      * (Math.cos(Math.toRadians(controller.getAngleY())))));
      newY =
          -(controller.getY()
              + (float) (-(i) * (Math.sin(Math.toRadians(controller.getAngleY())))));
      newZ =
          -(controller.getZ()
              + (float)
                  ((i)
                      * (Math.cos(Math.toRadians(controller.getAngleX())))
                      * (Math.cos(Math.toRadians(controller.getAngleY())))));

      if (checkShootZombie(newX, newY, newZ)) break;
    }
  }
Пример #2
0
 public void addZombie() {
   // adds a zombie where the player is looking
   float newX = 0, newZ = 0;
   newX =
       -(controller.getX()
           + (float)
               (-(100)
                   * (Math.sin(Math.toRadians(controller.getAngleX())))
                   * (Math.cos(Math.toRadians(controller.getAngleY())))));
   newZ =
       -(controller.getZ()
           + (float)
               ((100)
                   * (Math.cos(Math.toRadians(controller.getAngleX())))
                   * (Math.cos(Math.toRadians(controller.getAngleY())))));
   zombies.add(new Zombie(controller, zombieM, newX, newZ));
 }
Пример #3
0
  public static void setPerspective(float aspect, float fov, float znear, float zfar) {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    float f = 1f / (float) Math.tan(Math.toRadians(fov) / 2f);
    float zrange = znear - zfar;

    float[] m = new float[16];

    m[0] = f / aspect;
    m[1] = 0;
    m[2] = 0;
    m[3] = 0;

    m[4] = 0;
    m[5] = f;
    m[6] = 0;
    m[7] = 0;

    m[8] = 0;
    m[9] = 0;
    m[10] = (zfar + znear) / zrange;
    m[11] = (zfar * znear) / zrange;

    m[12] = 0;
    m[13] = 0;
    m[14] = -1f;
    m[15] = 1;

    projection.set(m);

    glLoadMatrixf(projection.get());

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
  }
Пример #4
0
 public RenderEngine() {
   glEnable(GL_DEPTH_TEST);
   projection = new Matrix4().initPerspective((float) Math.toRadians(90), 16f / 9f, 0.001f, 1000);
 }
Пример #5
0
  public void checkSelected() {
    // this method highlights a cube if it is being looked at
    // I use a method of ray tracing to check along the players line of sight
    if (controller.getSelectedWeapon() != 1) return;

    boolean anythingSelected = false;
    int maxIterations = 500;

    float newX = 0, newY = 0, newZ = 0;

    for (int i = 0; i < maxIterations; i += 1) {
      newX =
          -(controller.getX()
              + (float)
                  (-(i)
                      * (Math.sin(Math.toRadians(controller.getAngleX())))
                      * (Math.cos(Math.toRadians(controller.getAngleY())))));
      newY =
          -(controller.getY()
              + (float) (-(i) * (Math.sin(Math.toRadians(controller.getAngleY())))));
      newZ =
          -(controller.getZ()
              + (float)
                  ((i)
                      * (Math.cos(Math.toRadians(controller.getAngleX())))
                      * (Math.cos(Math.toRadians(controller.getAngleY())))));

      if (collisionLooking(-newX, -newY, -newZ)) {
        Cube selected = getCube(-(int) newX, -(int) newY, -(int) newZ);
        int[][] sides = new int[6][3];
        float[] differences = new float[6];
        for (int j = 0; j < sides.length; j++) {
          sides[j] = selected.getSideMid(j);
        }

        for (int j = 0; j < sides.length; j++) {
          differences[j] =
              (float)
                  Math.sqrt(
                      Math.pow((sides[j][0] - newX), 2)
                          + Math.pow((sides[j][1] - newY), 2)
                          + Math.pow((sides[j][2] - newZ), 2));
        }

        float smallest = differences[0];
        for (int j = 0; j < differences.length; j++) {
          if (differences[j] < smallest) smallest = differences[j];
        }

        int side = -1;

        for (int j = 0; j < differences.length; j++) {
          if (differences[j] == smallest) side = j;
        }

        selected.selectedSide[side] = true;

        selectedCube = selected;
        selectedSide = side;
        anythingSelected = true;

        break;
      }
    }

    if (!anythingSelected) {
      selectedCube = null;
      selectedSide = -1;
    }
  }
Пример #6
0
 private Vec3 getLookVector() {
   Vec3 vec =
       Vec3.fromAngles((float) Math.toRadians(pitch), (float) Math.toRadians(yaw)).scale(speed);
   return vec;
 }
Пример #7
0
  // Convert from Degrees to Radians.
  private float AR_DegToRad(float x) {

    return (float) Math.toRadians(x);
  }