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
Modifier 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
ConstructorDescriptionFlyByCamera
(Camera cam) Creates a new FlyByCamera to control the specified camera. -
Method Summary
Modifier and TypeMethodDescriptionfloat
Read the translation speed.float
Read the rotation-rate multiplier.float
Read the zoom-rate multiplier.boolean
Test whether drag-to-rotate mode is enabled.boolean
Test whether this controller is enabled.protected void
mapJoystick
(Joystick joystick) protected void
moveCamera
(float value, boolean sideways) Translate the camera left or forward 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) Register this controller to receive input events from the specified input manager.protected void
riseCamera
(float value) Translate the camera upward by the specified amount.protected void
rotateCamera
(float value, Vector3f axis) Rotate the camera by the specified amount around the specified 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) Set the translation speed.void
setRotationSpeed
(float rotationSpeed) Set the rotation-rate multiplier.void
setUpVector
(Vector3f upVec) Sets the up vector that should be used for the camera.void
setZoomSpeed
(float zoomSpeed) Set the zoom-rate multiplier.void
Unregister this controller from its input manager.protected void
zoomCamera
(float value) Zoom 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) Set the translation speed.- Parameters:
moveSpeed
- new speed (in world units per second)
-
getMoveSpeed
public float getMoveSpeed()Read the translation speed.- Returns:
- current speed (in world units per second)
-
setRotationSpeed
public void setRotationSpeed(float rotationSpeed) Set the rotation-rate multiplier. The bigger the multiplier, the more rotation for a given movement of the mouse.- Parameters:
rotationSpeed
- new rate multiplier (1=default)
-
getRotationSpeed
public float getRotationSpeed()Read the rotation-rate multiplier. The bigger the multiplier, the more rotation for a given movement of the mouse.- Returns:
- current rate multiplier (1=default)
-
setZoomSpeed
public void setZoomSpeed(float zoomSpeed) Set the zoom-rate multiplier. The bigger the multiplier, the more zoom for a given movement of the mouse wheel.- Parameters:
zoomSpeed
- new rate multiplier (1=default)
-
getZoomSpeed
public float getZoomSpeed()Read the zoom-rate multiplier. The bigger the multiplier, the more zoom for a given movement of the mouse wheel.- Returns:
- current rate multiplier (1=default)
-
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()Test whether this controller is enabled.- Returns:
- true if enabled, otherwise false
- See Also:
-
isDragToRotate
public boolean isDragToRotate()Test whether drag-to-rotate mode is enabled.- Returns:
- If drag to rotate feature is enabled.
- 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
Register this controller to receive input events from the specified input manager.- Parameters:
inputManager
- (not null, alias created)
-
mapJoystick
-
unregisterInput
public void unregisterInput()Unregister this controller from its input manager. -
rotateCamera
Rotate the camera by the specified amount around the specified axis.- Parameters:
value
- rotation amountaxis
- direction of rotation (a unit vector)
-
zoomCamera
protected void zoomCamera(float value) Zoom the camera by the specified amount.- Parameters:
value
- zoom amount
-
riseCamera
protected void riseCamera(float value) Translate the camera upward by the specified amount.- Parameters:
value
- translation amount
-
moveCamera
protected void moveCamera(float value, boolean sideways) Translate the camera left or forward by the specified amount.- Parameters:
value
- translation amountsideways
- true→left, false→forward
-
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 eventvalue
- true if the action is "pressed", false otherwisetpf
- time per frame (in seconds)
-