Esempio n. 1
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;
  }
Esempio n. 2
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();
  }
Esempio n. 3
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();
  }