Package com.jme3.input
Class FlyByCamera
java.lang.Object
com.jme3.input.FlyByCamera
- All Implemented Interfaces:
ActionListener
,AnalogListener
,InputListener
A first-person camera controller.
After creation, you (or FlyCamAppState) must register the controller using
registerWithInput(com.jme3.input.InputManager)
.
Controls: - Move (or, in drag-to-rotate mode, drag) the mouse to rotate the camera - Mouse wheel for zooming in or out - WASD keys for moving forward/backward and strafing - QZ keys raise or lower the camera
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Camera
camera controlled by this controller (not null)protected boolean
protected boolean
drag-to-rotate mode flagprotected boolean
enable flag for controller (false→ignoring input)protected Vector3f
normalized "up" direction (a unit vector)protected InputManager
protected boolean
protected MotionAllowedListener
protected float
translation speed (in world units per second)protected float
rotation-rate multiplier (1=default)protected float
zoom-rate multiplier (1=default) -
Constructor Summary
ConstructorsConstructorDescriptionFlyByCamera
(Camera cam) Creates a new FlyByCamera to control the specified camera. -
Method Summary
Modifier and TypeMethodDescriptionfloat
Retrieves the current translation speed of the camera.float
Retrieves the current rotation-rate multiplier.float
Retrieves the current zoom-rate multiplier.boolean
Checks whether drag-to-rotate mode is currently enabled.boolean
Checks whether this camera controller is currently enabled.protected void
mapJoystick
(Joystick joystick) Configures joystick input mappings for the camera controller.protected void
moveCamera
(float value, boolean sideways) Translates the camera left/right or forward/backward by the specified amount.void
Callback to notify this controller of an action input event.void
Callback to notify this controller of an analog input event.void
registerWithInput
(InputManager inputManager) Registers this controller to receive input events from the specifiedInputManager
.protected void
riseCamera
(float value) Translates the camera vertically (up or down) by the specified amount, considering theinitialUpVec
.protected void
rotateCamera
(float value, Vector3f axis) Rotates the camera by the specified amount around the given axis.void
setDragToRotate
(boolean dragToRotate) Enable or disable drag-to-rotate mode.void
setEnabled
(boolean enable) Enable or disable this controller.void
void
setMoveSpeed
(float moveSpeed) Sets the translation speed of the camera.void
setRotationSpeed
(float rotationSpeed) Sets the rotation-rate multiplier for mouse input.void
setUpVector
(Vector3f upVec) Sets the up vector that should be used for the camera.void
setZoomSpeed
(float zoomSpeed) Sets the zoom-rate multiplier for mouse wheel input.void
Unregisters this controller from its currently associatedInputManager
.protected void
zoomCamera
(float value) Zooms the camera by the specified amount.
-
Field Details
-
cam
camera controlled by this controller (not null) -
initialUpVec
normalized "up" direction (a unit vector) -
rotationSpeed
protected float rotationSpeedrotation-rate multiplier (1=default) -
moveSpeed
protected float moveSpeedtranslation speed (in world units per second) -
zoomSpeed
protected float zoomSpeedzoom-rate multiplier (1=default) -
motionAllowed
-
enabled
protected boolean enabledenable flag for controller (false→ignoring input) -
dragToRotate
protected boolean dragToRotatedrag-to-rotate mode flag -
canRotate
protected boolean canRotate -
invertY
protected boolean invertY -
inputManager
-
-
Constructor Details
-
FlyByCamera
Creates a new FlyByCamera to control the specified camera.- Parameters:
cam
- camera to be controlled (not null)
-
-
Method Details
-
setUpVector
Sets the up vector that should be used for the camera.- Parameters:
upVec
- the desired direction (not null, unaffected)
-
setMotionAllowedListener
-
setMoveSpeed
public void setMoveSpeed(float moveSpeed) Sets the translation speed of the camera.- Parameters:
moveSpeed
- The new translation speed in world units per second. Must be non-negative.
-
getMoveSpeed
public float getMoveSpeed()Retrieves the current translation speed of the camera.- Returns:
- The current speed in world units per second.
-
setRotationSpeed
public void setRotationSpeed(float rotationSpeed) Sets the rotation-rate multiplier for mouse input. A higher value means the camera rotates more for a given mouse movement.- Parameters:
rotationSpeed
- The new rate multiplier (1.0 is default). Must be non-negative.
-
getRotationSpeed
public float getRotationSpeed()Retrieves the current rotation-rate multiplier.- Returns:
- The current rate multiplier.
-
setZoomSpeed
public void setZoomSpeed(float zoomSpeed) Sets the zoom-rate multiplier for mouse wheel input. A higher value means the camera zooms more for a given mouse wheel scroll.- Parameters:
zoomSpeed
- The new rate multiplier (1.0 is default). Must be non-negative.
-
getZoomSpeed
public float getZoomSpeed()Retrieves the current zoom-rate multiplier.- Returns:
- The current rate multiplier.
-
setEnabled
public void setEnabled(boolean enable) Enable or disable this controller. When disabled, the controller ignored input.- Parameters:
enable
- true to enable, false to disable
-
isEnabled
public boolean isEnabled()Checks whether this camera controller is currently enabled.- Returns:
true
if enabled,false
otherwise.- See Also:
-
isDragToRotate
public boolean isDragToRotate()Checks whether drag-to-rotate mode is currently enabled.- Returns:
true
if drag-to-rotate is enabled,false
otherwise.- See Also:
-
setDragToRotate
public void setDragToRotate(boolean dragToRotate) Enable or disable drag-to-rotate mode. When drag-to-rotate mode is enabled, the user must hold the mouse button and drag over the screen to rotate the camera, and the cursor is visible until dragged. When drag-to-rotate mode is disabled, the cursor is invisible at all times and holding the mouse button is not needed to rotate the camera. This mode is disabled by default.- Parameters:
dragToRotate
- true to enable, false to disable
-
registerWithInput
Registers this controller to receive input events from the specifiedInputManager
. This method sets up all the necessary input mappings for mouse, keyboard, and joysticks.- Parameters:
inputManager
- The InputManager instance to register with (must not be null).
-
mapJoystick
Configures joystick input mappings for the camera controller. This method attempts to map joystick axes and buttons to camera actions.- Parameters:
joystick
- TheJoystick
to map (not null).
-
unregisterInput
public void unregisterInput()Unregisters this controller from its currently associatedInputManager
. -
rotateCamera
Rotates the camera by the specified amount around the given axis.- Parameters:
value
- The amount of rotation.axis
- The axis around which to rotate (a unit vector, unaffected).
-
zoomCamera
protected void zoomCamera(float value) Zooms the camera by the specified amount. This method handles both perspective and parallel projections.- Parameters:
value
- The amount to zoom. Positive values typically zoom in, negative out.
-
riseCamera
protected void riseCamera(float value) Translates the camera vertically (up or down) by the specified amount, considering theinitialUpVec
.- Parameters:
value
- The translation amount. Positive values move the camera up, negative down.
-
moveCamera
protected void moveCamera(float value, boolean sideways) Translates the camera left/right or forward/backward by the specified amount.- Parameters:
value
- The translation amount. Positive values move in the primary direction (right/forward), negative in the opposite.sideways
- Iftrue
, the camera moves left/right (strafes). Iffalse
, the camera moves forward/backward.
-
onAnalog
Callback to notify this controller of an analog input event.- Specified by:
onAnalog
in interfaceAnalogListener
- Parameters:
name
- name of the input eventvalue
- value of the axis (from 0 to 1)tpf
- time per frame (in seconds)
-
onAction
Callback to notify this controller of an action input event.- Specified by:
onAction
in interfaceActionListener
- Parameters:
name
- name of the input eventisPressed
- true if the action is "pressed", false otherwisetpf
- time per frame (in seconds)
-