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 a quaternion), 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.getTransform().setTranslation(new Point3D(0, -50, -200));

 // Set camera orientation using a quaternion
 camera.getTransform().getRotation().set(Quaternion.fromAngles(0.5, -0.3));

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

    Fields
    Modifier and Type
    Field
    Description
    double
    Camera acceleration factor for movement speed.
    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(Camera sourceView)
    Creates a copy of an existing camera, cloning its position and orientation.
    Camera(Transform transform)
    Creates a camera with the specified transform (position and orientation).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clamps the camera's movement speed to SPEED_LIMIT.
    double
    Returns the current movement speed (magnitude of the movement vector).
    Returns the current movement velocity vector, relative to the camera's orientation.
    Returns the transform containing this camera's location and orientation.
    void
    lookAt(Point3D target)
    Orients the camera to look at a target point in world coordinates.
    boolean
    onFrame(ViewPanel viewPanel, int millisecondsSinceLastFrame)
    Called before each frame render, allowing the listener to update state and indicate whether a repaint is needed.

    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
      Camera acceleration factor for movement speed. Higher values result in faster acceleration.
  • 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(Transform transform)
      Creates a camera with the specified transform (position and orientation).
      Parameters:
      transform - the initial transform defining position and rotation
  • 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.
    • 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
    • getTransform

      public Transform getTransform()
      Returns the transform containing this camera's location and orientation.
      Returns:
      the transform (mutable reference)
    • lookAt

      public void lookAt(Point3D target)
      Orients the camera to look at a target point in world coordinates.

      Calculates the required XZ and YZ rotation angles to point the camera from its current position toward the target. Useful for programmatic camera control, cinematic sequences, and following objects.

      Example:

      
       Camera camera = viewPanel.getCamera();
       camera.getTransform().setTranslation(new Point3D(100, -50, -200));
       camera.lookAt(new Point3D(0, 0, 0));  // Point camera at origin
       
      Parameters:
      target - the world-space point to look at