Class Camera

java.lang.Object
eu.svjatoslav.sixth.e3d.gui.Camera
All Implemented Interfaces:
FrameListener

public class Camera extends Object implements FrameListener
Represents the viewer's camera in the 3D world, with position, orientation, and movement.

The camera is the user's "eyes" in the 3D scene. It has a position (location), a looking direction (defined by XZ and YZ angles), and a movement system with velocity, acceleration, and friction for smooth camera navigation.

By default, the user can navigate using arrow keys (handled by WorldNavigationUserInputTracker), and the mouse controls the look direction (handled by InputManager).

Programmatic camera control:


 Camera camera = viewPanel.getCamera();

 // Set camera position
 camera.setLocation(new Point3D(0, -50, -200));

 // Set camera orientation (radians)
 camera.setAngleXZ(0);     // horizontal rotation (yaw)
 camera.setAngleYZ(0);     // vertical rotation (pitch)

 // Copy camera state from another camera
 Camera snapshot = new Camera(camera);
 
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    double
     
    static final double
    Camera movement speed limit, relative to the world.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a camera at the world origin with no rotation.
    Camera(Point3D location)
    Creates a camera at the specified location with no rotation.
    Camera(Point3D location, float angleXZ, float angleYZ)
    Creates a camera at the specified location with the given orientation.
    Camera(Camera sourceView)
    Creates a copy of an existing camera, cloning its position and orientation.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clamps the camera's movement speed to SPEED_LIMIT.
    double
    Returns the horizontal rotation angle (yaw) on the X-Z plane, in radians.
    double
    Returns the vertical rotation angle (pitch) on the Y-Z plane, in radians.
    Returns the camera's current position in world space.
    double
    Returns the current movement speed (magnitude of the movement vector).
    Returns the current movement velocity vector, relative to the camera's orientation.
    boolean
    onFrame(ViewPanel viewPanel, int millisecondsSinceLastFrame)
    Called before each frame render, allowing the listener to update state and indicate whether a repaint is needed.
    void
    setAngleXZ(double angleXZ)
    Sets the horizontal rotation angle (yaw) on the X-Z plane.
    void
    setAngleYZ(double angleYZ)
    Sets the vertical rotation angle (pitch) on the Y-Z plane.
    void
    setLocation(Point3D location)
    Sets the camera's position in world space.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SPEED_LIMIT

      public static final double SPEED_LIMIT
      Camera movement speed limit, relative to the world. When camera coordinates are updated within the world, camera orientation relative to the world is taken into account.
      See Also:
    • cameraAcceleration

      public double cameraAcceleration
  • Constructor Details

    • Camera

      public Camera()
      Creates a camera at the world origin with no rotation.
    • Camera

      public Camera(Camera sourceView)
      Creates a copy of an existing camera, cloning its position and orientation.
      Parameters:
      sourceView - the camera to copy
    • Camera

      public Camera(Point3D location)
      Creates a camera at the specified location with no rotation.
      Parameters:
      location - the initial position in world space
    • Camera

      public Camera(Point3D location, float angleXZ, float angleYZ)
      Creates a camera at the specified location with the given orientation.
      Parameters:
      location - the initial position in world space
      angleXZ - horizontal rotation angle in radians (yaw)
      angleYZ - vertical rotation angle in radians (pitch)
  • Method Details

    • onFrame

      public boolean onFrame(ViewPanel viewPanel, int millisecondsSinceLastFrame)
      Description copied from interface: FrameListener
      Called before each frame render, allowing the listener to update state and indicate whether a repaint is needed.

      Each registered listener is called exactly once per frame tick. The frame is only rendered if at least one listener returns true (or if the view was explicitly marked for repaint).

      Specified by:
      onFrame in interface FrameListener
      Parameters:
      viewPanel - the view panel being rendered
      millisecondsSinceLastFrame - time elapsed since the previous frame, for frame-rate-independent updates
      Returns:
      true if the view should be re-rendered this frame, false if this listener has no visual changes
    • enforceSpeedLimit

      public void enforceSpeedLimit()
      Clamps the camera's movement speed to SPEED_LIMIT. Called after modifying the movement vector to prevent excessive velocity.
    • getAngleXZ

      public double getAngleXZ()
      Returns the horizontal rotation angle (yaw) on the X-Z plane, in radians.
      Returns:
      the XZ angle in radians
    • setAngleXZ

      public void setAngleXZ(double angleXZ)
      Sets the horizontal rotation angle (yaw) on the X-Z plane.
      Parameters:
      angleXZ - the XZ angle in radians
    • getAngleYZ

      public double getAngleYZ()
      Returns the vertical rotation angle (pitch) on the Y-Z plane, in radians.
      Returns:
      the YZ angle in radians
    • setAngleYZ

      public void setAngleYZ(double angleYZ)
      Sets the vertical rotation angle (pitch) on the Y-Z plane.
      Parameters:
      angleYZ - the YZ angle in radians
    • getLocation

      public Point3D getLocation()
      Returns the camera's current position in world space.
      Returns:
      the world-space location (mutable reference)
    • setLocation

      public void setLocation(Point3D location)
      Sets the camera's position in world space.
      Parameters:
      location - the new world-space position
    • getMovementVector

      public Point3D getMovementVector()
      Returns the current movement velocity vector, relative to the camera's orientation. Modify this vector to programmatically move the camera.
      Returns:
      the movement vector (mutable reference)
    • getMovementSpeed

      public double getMovementSpeed()
      Returns the current movement speed (magnitude of the movement vector).
      Returns:
      the scalar speed value