Class Camera

All Implemented Interfaces:
EventEmitterInterface

public class Camera extends EventEmitter
Represents the virtual camera in the 3D scene.

The camera defines the viewpoint from which the scene is rendered. It holds its own position and orientation (rotation) in world space. It also contains the projection plane, which determines the field of view and focal length for the 3D-to-2D projection.

Author:
Lehlogonolo Poole
See Also:
  • Field Details

    • position

      private Vector3 position
      The 3D position of the camera in the world (c).
    • rotation

      private Rotation rotation
      The orientation of the camera, defined by pitch, yaw, and roll angles.
    • projectionPlane

      private Vector3 projectionPlane
      The position of the display surface relative to the camera's local coordinate system. The Z-component of this vector is the most critical, acting as the focal length (zoom). A larger Z-value results in a narrower field of view (more zoom).
  • Constructor Details

    • Camera

      public Camera(Vector3 position, Rotation rotation, Vector3 projectionPlane)
      Constructs a new Camera with a specified position, rotation, and projection plane.
      Parameters:
      position - The camera's position in 3D space.
      rotation - The camera's orientation.
      projectionPlane - The camera's projection plane settings.
    • Camera

      public Camera()
      Default constructor that creates a camera at the origin (0,0,0), with zero rotation, looking along the world's Z-axis. It uses a default projection plane.
  • Method Details

    • move

      public void move(Vector3 delta)
      Moves the camera by a given delta vector.
      Parameters:
      delta - The vector to add to the camera's current position.
    • getPosition

      public Vector3 getPosition()
      Gets the position
      Returns:
      The camera's position in 3D space.
    • setPositionNoEvent

      public Camera setPositionNoEvent(Vector3 position)
    • setPosition

      public Camera setPosition(Vector3 position)
      Sets the position
      Parameters:
      position - The new position for the camera.
    • getRotation

      public Rotation getRotation()
      Gets the rotation
      Returns:
      The camera's orientation.
    • setRotationNoEvent

      public Camera setRotationNoEvent(Rotation rotation)
    • setRotation

      public Camera setRotation(Rotation rotation)
      Sets the rotation
      Parameters:
      rotation - The new rotation for the camera.
    • getProjectionPlane

      public Vector3 getProjectionPlane()
      Gets the projection plane
      Returns:
      The camera's projection plane settings.
    • setProjectionPlane

      public Camera setProjectionPlane(Vector3 projectionPlane)
      Sets the projection plane
      Parameters:
      projectionPlane - The new projection plane settings.
    • getForward

      public Vector3 getForward()
      Calculates the camera's forward-facing direction vector in world space. This is determined by transforming a local "forward" vector (0, 0, 1) using the camera's current yaw and pitch.
      Returns:
      A normalized Vector3 representing the direction the camera is pointing.
    • getRight

      public Vector3 getRight()
      Calculates the camera's right-facing direction vector in world space. This is determined by transforming a local "right" vector (1, 0, 0) using the camera's current yaw and pitch.
      Returns:
      A normalized Vector3 representing the direction the camera is pointing.
    • getUp

      public Vector3 getUp()
      Calculates the camera's up-facing direction vector in world space. This is determined by transforming a local "up" vector (0, 1, 0) using the camera's current yaw and pitch. Roll is ignored.
      Returns:
      A normalized Vector3 representing the direction the camera is pointing.
    • lookAt

      public void lookAt(Vector3 target)
      Orients the camera to look at a specific target point in world space. This method calculates the necessary pitch and yaw to align the camera's forward vector with the direction from its current position to the target. The camera's roll is set to 0.
      Parameters:
      target - The world-space Vector3 point to look at.
    • viewPlane

      public NormalPlane viewPlane()
      Returns a NormalPlane representing the camera's view plane. This plane is defined by the camera's position and its forward-facing direction.
      Returns:
      A NormalPlane representing the camera's view plane.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setFocalLength

      public void setFocalLength(double d)
    • event

      public void event()