public class Camera extends Pose

The Camera class is a subclass of the Pose class and is used by a Viewport to viewport the scene in a 3D graphics or game engine. This class provides several functionalities:

  • It can be set to viewport in orthographic projection.
  • It has a vertical field of view, a near and far clipping plane for perspective rendering.
  • It can translate and rotate relative to its current orientation.
  • It can look at a specific point in the scene.
  • It can orbit around a point at a certain radius.
  • It can get the point it is orbiting around.
  • It can change the distance from itself to the orbit point.
  • It can get the distance from itself to the orbit point.
  • It can get the perspective frustum and orthographic matrix.
  • It can get the chosen projection matrix based on whether it is set to draw in orthographic or not.
  • It can get the view matrix.
  • It can build a Swing Component that represents itself.
  • Constructor Details

    • Camera

      public Camera()
    • Camera

      public Camera(String name)
  • Method Details

    • getComponents

      public void getComponents(List<JPanel> list)
      Build a Swing Component that represents this Node.
      Overrides:
      getComponents in class Pose
      Parameters:
      list - the list to add components to.
    • getDrawOrthographic

      public boolean getDrawOrthographic()
    • setDrawOrthographic

      public void setDrawOrthographic(boolean selected)
    • getFovY

      public double getFovY()
    • setFovY

      public void setFovY(double fovY)
    • getNearZ

      public double getNearZ()
    • setNearZ

      public void setNearZ(double nearZ)
    • getFarZ

      public double getFarZ()
    • setFarZ

      public void setFarZ(double farZ)
    • pedestal

      public void pedestal(double delta)
      Translate relative to camera's current orientation if canTranslate is true.
      Parameters:
      delta - distance to travel. Positive is up.
    • truck

      public void truck(double delta)
      Translate relative to camera's current orientation if canTranslate is true.
      Parameters:
      delta - distance to travel. Positive is right.
    • dolly

      public void dolly(double delta)
      Translate relative to camera's current orientation if canTranslate is true.
      Parameters:
      delta - distance to travel. Positive is forward.
    • pan

      public void pan(double delta)
      Rotate relative to camera's current orientation if canRotate is true.
      Parameters:
      delta - degrees to rotate. Positive is left.
    • tilt

      public void tilt(double delta)
      Rotate relative to camera's current orientation if canRotate is true.
      Parameters:
      delta - degrees to rotate. Positive is up.
    • roll

      public void roll(double delta)
      Rotate relative to camera's current orientation if canRotate is true.
      Parameters:
      delta - degrees to rotate. Positive is counter-clockwise.
    • lookAt

      public void lookAt(javax.vecmath.Vector3d target)
      Set the pan and tilt values such that the camera is looking at the target. Set the orbit distance to the distance between the camera and the target.
      Parameters:
      target - the point to look at.
    • getPerspectiveFrustum

      public javax.vecmath.Matrix4d getPerspectiveFrustum(int width, int height)
    • getOrthographicMatrix

      public javax.vecmath.Matrix4d getOrthographicMatrix(int width, int height)
      Render the scene in orthographic projection.
    • getChosenProjectionMatrix

      public javax.vecmath.Matrix4d getChosenProjectionMatrix(int width, int height)
    • getViewMatrix

      public javax.vecmath.Matrix4d getViewMatrix()
    • getOrbitPoint

      public javax.vecmath.Vector3d getOrbitPoint()
      Returns:
      the point that the camera is orbiting around.
    • setOrbitRadius

      public void setOrbitRadius(double newRadius)
      Change the distance from the camera to the orbit point. The orbit point does not move. In effect the camera is performing a dolly in/out.
      Parameters:
      newRadius - new radius. Must be >=1.
    • getOrbitRadius

      public double getOrbitRadius()
    • orbit

      public void orbit(double dx, double dy)
      Orbit the camera around a point orbitRadius ahead of the camera.
      Parameters:
      dx - change in x
      dy - change in y
    • panTilt

      public void panTilt(double panDegrees, double tiltDegrees)
      Combination pan and tilt.
      Parameters:
      panDegrees - pan angle in degrees
      tiltDegrees - tilt angle in degrees
    • getCanTranslate

      public boolean getCanTranslate()
    • setCanTranslate

      public void setCanTranslate(boolean canTranslate)
    • getCanRotate

      public boolean getCanRotate()
    • setCanRotate

      public void setCanRotate(boolean canRotate)
    • orbitDolly

      public void orbitDolly(double scale)
      Move towards or away from the orbit point if canTranslate is true.
      Parameters:
      scale - relative to the current orbit distance.
    • toJSON

      public org.json.JSONObject toJSON()
      Description copied from class: Node
      Serialize this node and its children to a JSON object and its children. Classes that override this method should call super.toJSON() first, then add to the object returned.
      Overrides:
      toJSON in class Pose
      Returns:
      the JSON object.
    • fromJSON

      public void fromJSON(org.json.JSONObject json)
      Description copied from class: Node
      Deserialize this node and its children from a JSON object and its children. Classes that override this method should call super.fromJSON(). When they do it will trigger the creation of child nodes. The child nodes will then call their own fromJSON() methods.
      Overrides:
      fromJSON in class Pose
      Parameters:
      json - the JSON object to read from.