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 Cameracamera controlled by this controller (not null)protected booleanprotected booleandrag-to-rotate mode flagprotected booleanenable flag for controller (false→ignoring input)protected Vector3fnormalized "up" direction (a unit vector)protected InputManagerprotected booleanprotected MotionAllowedListenerprotected floattranslation speed (in world units per second)protected floatrotation-rate multiplier (1=default)protected floatzoom-rate multiplier (1=default) -
Constructor Summary
ConstructorsConstructorDescriptionFlyByCamera(Camera cam) Creates a new FlyByCamera to control the specified camera. -
Method Summary
Modifier and TypeMethodDescriptionfloatRetrieves the current translation speed of the camera.floatRetrieves the current rotation-rate multiplier.floatRetrieves the current zoom-rate multiplier.booleanChecks whether drag-to-rotate mode is currently enabled.booleanChecks whether this camera controller is currently enabled.protected voidmapJoystick(Joystick joystick) Configures joystick input mappings for the camera controller.protected voidmoveCamera(float value, boolean sideways) Translates the camera left/right or forward/backward by the specified amount.voidCallback to notify this controller of an action input event.voidCallback to notify this controller of an analog input event.voidregisterWithInput(InputManager inputManager) Registers this controller to receive input events from the specifiedInputManager.protected voidriseCamera(float value) Translates the camera vertically (up or down) by the specified amount, considering theinitialUpVec.protected voidrotateCamera(float value, Vector3f axis) Rotates the camera by the specified amount around the given axis.voidsetDragToRotate(boolean dragToRotate) Enable or disable drag-to-rotate mode.voidsetEnabled(boolean enable) Enable or disable this controller.voidvoidsetMoveSpeed(float moveSpeed) Sets the translation speed of the camera.voidsetRotationSpeed(float rotationSpeed) Sets the rotation-rate multiplier for mouse input.voidsetUpVector(Vector3f upVec) Sets the up vector that should be used for the camera.voidsetZoomSpeed(float zoomSpeed) Sets the zoom-rate multiplier for mouse wheel input.voidUnregisters this controller from its currently associatedInputManager.protected voidzoomCamera(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:
trueif enabled,falseotherwise.- See Also:
-
isDragToRotate
public boolean isDragToRotate()Checks whether drag-to-rotate mode is currently enabled.- Returns:
trueif drag-to-rotate is enabled,falseotherwise.- 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- TheJoystickto 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:
onAnalogin 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:
onActionin interfaceActionListener- Parameters:
name- name of the input eventisPressed- true if the action is "pressed", false otherwisetpf- time per frame (in seconds)
-