示例#1
0
  /**
   * Rotates this camera by a given amount. If <code>relative</code> is set to <code>true</code>
   * then the rotation will be performed relative to this camera's current orientation. Otherwise,
   * the rotation will be performed relative to the world coordinate system.
   *
   * <p>If this camera's focus is locked, then only rotation about the z axis (roll) will be
   * performed.
   *
   * @param rotation The amount of rotation to be applied to this camera.
   * @param relative A boolean flag stating whether the rotation performed should be relative to
   *     this camera's current orientation.
   */
  public void rotate(Rotation rotation, boolean relative) {
    // store current focus point
    Vector3D focusPoint = getFocusPoint();

    // perform rotation
    if (relative) super.setOrientation(getOrientation().append(rotation));
    else super.setOrientation(rotation.append(getOrientation()));

    // if focus is locked, look at the point of focus
    if (focusLocked) lookAt(focusPoint);
  }
示例#2
0
  /**
   * Sets this object's orientation to that described by a given <code>Rotation</code> object,
   * relative to the object's default orientation.
   *
   * @param orientation A <code>Rotation</code> object defining the desired orientation, relative to
   *     the object's default orientation.
   * @throws IllegalArgumentException If <code>orientation</code> is <code>null</code>.
   */
  public void setOrientation(Rotation orientation) {
    // null given?
    if (orientation == null) throw new IllegalArgumentException("Cannot set null orientation.");

    // if focus is locked, we can only alter the
    // orientation of the local up (y-axis) vector
    if (focusLocked) lookAt(getFocusPoint(), Vector3D.Y_AXIS.rotate(orientation));
    else super.setOrientation(orientation);
  }
示例#3
0
  /**
   * Rotates this camera to focus on a given point with the local y-axis (up vector) set to a given
   * vector. The resulting local y-axis may be altered as needed to make it perpendicular to the
   * focus vector formed between this Camera's position and the given point.
   *
   * @param point A <code>Vector3D</code> describing the point on which this camera will focus.
   * @param up A <code>Vector3D</code> describing the desired local y axis (up vector).
   */
  public void lookAt(Vector3D point, Vector3D up) {
    // find focus vector and distance from point
    Vector3D focusVector = point.subtract(getPosition());

    // set focus depth
    setFocusDepth(focusVector.magnitude());

    // set orientation (using inverse of focus vector for +z-axis
    super.setOrientation(new Rotation(up, focusVector.inverse()));
  }
示例#4
0
  /**
   * Rotates this camera by a given amount around a given point. The rotation will be performed
   * relative to the world coordinate system. If the <cod>reorient</code> flag is set to <code>true
   * </code>, then the rotation will be applied as a standard rotational transformation would;
   * altering this camera's orientation. If set to <code>false</code>, this camera's orientation
   * will remain unchanged as the rotation is performed.
   *
   * <p>Note that the camera will maintain focus if the camera's focus is locked.
   *
   * @param rotation The amount of rotation to be applied to this camera.
   * @param point The point, in the world coordinate system, about which the rotation will occur.
   * @param reorient A flag stating whether or not to alter this camera's orientation as with the
   *     applied rotation.
   */
  public void rotate(Rotation rotation, Vector3D point, boolean reorient) {
    // store current focus point
    Vector3D focusPoint = getFocusPoint();

    // find vector between given point and camera, in local coordinates
    Vector3D vect = getPosition().subtract(point);

    // move camera to given point
    super.setPosition(point);

    // rotate camera for standard rotation
    if (reorient) super.setOrientation(rotation.append(getOrientation()));

    // rotate vector
    vect = vect.rotate(rotation);

    // move back to proper position
    super.setPosition(getPosition().add(vect));

    // if focus is locked, look at original focus point
    if (focusLocked) lookAt(focusPoint);
  }