Package eu.svjatoslav.sixth.e3d.gui
Class Camera
java.lang.Object
eu.svjatoslav.sixth.e3d.gui.Camera
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptiondoublestatic final doubleCamera movement speed limit, relative to the world. -
Constructor Summary
ConstructorsConstructorDescriptionCamera()Creates a camera at the world origin with no rotation.Creates a camera at the specified location with no rotation.Creates a camera at the specified location with the given orientation.Creates a copy of an existing camera, cloning its position and orientation. -
Method Summary
Modifier and TypeMethodDescriptionvoidClamps the camera's movement speed toSPEED_LIMIT.doubleReturns the horizontal rotation angle (yaw) on the X-Z plane, in radians.doubleReturns the vertical rotation angle (pitch) on the Y-Z plane, in radians.Returns the camera's current position in world space.doubleReturns the current movement speed (magnitude of the movement vector).Returns the current movement velocity vector, relative to the camera's orientation.booleanCalled before each frame render, allowing the listener to update state and indicate whether a repaint is needed.voidsetAngleXZ(double angleXZ) Sets the horizontal rotation angle (yaw) on the X-Z plane.voidsetAngleYZ(double angleYZ) Sets the vertical rotation angle (pitch) on the Y-Z plane.voidsetLocation(Point3D location) Sets the camera's position in world space.
-
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 cameraAcceleration
-
-
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 at the specified location with no rotation.- Parameters:
location- the initial position in world space
-
Camera
Creates a camera at the specified location with the given orientation.- Parameters:
location- the initial position in world spaceangleXZ- horizontal rotation angle in radians (yaw)angleYZ- vertical rotation angle in radians (pitch)
-
-
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. -
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
Returns the camera's current position in world space.- Returns:
- the world-space location (mutable reference)
-
setLocation
Sets the camera's position in world space.- Parameters:
location- the new world-space position
-
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
-