Exemplo n.º 1
0
  // pitch camera up or down
  private void turnPitch(double pitch) {
    Vec3 oldup = new Vec3(up.x, up.y, up.z);

    up.x -= Math.tan(pitch) * persp.x;
    up.y -= Math.tan(pitch) * persp.y;
    up.z -= Math.tan(pitch) * persp.z;

    persp.x += Math.tan(pitch) * oldup.x;
    persp.y += Math.tan(pitch) * oldup.y;
    persp.z += Math.tan(pitch) * oldup.z;

    up = up.normalize();

    persp = persp.normalize();
  }
Exemplo n.º 2
0
  // turn the camera in its current plane
  private void turnYaw(double roll) {
    // Up cross focus for left vector
    Vec3 left = persp.cross(up);

    // Normalize left vector
    left = left.normalize();

    // Move up vector
    persp.x += (Math.tan(roll) * left.x);
    persp.y += (Math.tan(roll) * left.y);
    persp.z += (Math.tan(roll) * left.z);

    // Normalize persp vector
    persp = persp.normalize();
  }
Exemplo n.º 3
0
  // handles camera movement
  public void moveCamera(float speed, Vec3 ratio) {
    double pitch = 0, roll = 0;
    if (rotatorP.equals("") || rotatorR.equals("")) {
    } else if (rotatorP.equals("up")) {
      pitch = Math.PI / 180;
    } else if (rotatorP.equals("down")) {
      pitch = -1 * Math.PI / 180;
    } else if (rotatorR.equals("right")) {
      roll = Math.PI / 180;
    } else if (rotatorR.equals("left")) {
      roll = -1 * Math.PI / 180;
    }

    persp.setToSub(eye);

    // double length;

    if (pitch != 0) {
      turnPitch(pitch);
    } else if (roll != 0 && move) // YAW)
    {
      turnRoll(roll);
    }

    if (!move /*YAW*/ && roll != 0) {
      turnYaw(roll);
    }

    persp.setToAdd(eye);

    if (move) {
      moveForward(speed, ratio);
    }

    if (eye.y < 0) {
      persp.y -= eye.y;
      eye.y = 0;
    }
    if (eye.y > (skyHeight - 1) / 1) {
      persp.y -= (eye.y - (skyHeight - 1) / 1);
      eye.y = (skyHeight - 1) / 1;
    }

    return;
  }
Exemplo n.º 4
0
  // move the camera forward one unit
  private void moveForward(float speed, Vec3 ratio) {
    double scale =
        Math.sqrt(
            Math.pow(eye.x - persp.x, 2)
                + Math.pow(eye.y - persp.y, 2)
                + Math.pow(eye.z - persp.z, 2));
    double movex = ((persp.x - eye.x) / scale) * speed;
    double movey = ((persp.y - eye.y) / scale) * speed;
    double movez = ((persp.z - eye.z) / scale) * speed;

    moveAmount.x = (float) movex;
    moveAmount.y = (float) movey;
    moveAmount.z = (float) movez;

    latLon.x += movex * ratio.x;
    latLon.y += movey * ratio.y;
    latLon.z += movez * ratio.z;

    eye.x += movex;
    persp.x += movex;
    eye.y += movey;
    persp.y += movey;
    eye.z += movez;
    persp.z += movez;
  }