Class Camera
- All Implemented Interfaces:
FrameListener
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
FieldsModifier and TypeFieldDescriptiondoubleCamera acceleration factor for movement speed.static final doubleCamera movement speed limit, relative to the world. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClamps the camera's movement speed toSPEED_LIMIT.doubleReturns 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.voidOrients the camera to look at a target point in world coordinates.booleanCalled before each frame render, allowing the listener to update state and indicate whether a repaint is needed.
-
Field Details
-
SPEED_LIMIT
public static final double SPEED_LIMITCamera 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 cameraAccelerationCamera 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
Creates a copy of an existing camera, cloning its position and orientation.- Parameters:
sourceView- the camera to copy
-
Camera
Creates a camera with the specified transform (position and orientation).- Parameters:
transform- the initial transform defining position and rotation
-
-
Method Details
-
onFrame
Description copied from interface:FrameListenerCalled 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:
onFramein interfaceFrameListener- Parameters:
viewPanel- the view panel being renderedmillisecondsSinceLastFrame- time elapsed since the previous frame, for frame-rate-independent updates- Returns:
trueif the view should be re-rendered this frame,falseif this listener has no visual changes
-
enforceSpeedLimit
public void enforceSpeedLimit()Clamps the camera's movement speed toSPEED_LIMIT. Called after modifying the movement vector to prevent excessive velocity. -
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
Returns the transform containing this camera's location and orientation.- Returns:
- the transform (mutable reference)
-
lookAt
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
-