public class FlyByCamera extends java.lang.Object implements AnalogListener, ActionListener
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 cameraModifier and Type | Field and Description |
---|---|
protected Camera |
cam
camera controlled by this controller (not null)
|
protected boolean |
canRotate |
protected boolean |
dragToRotate
drag-to-rotate mode flag
|
protected boolean |
enabled
enable flag for controller (false→ignoring input)
|
protected Vector3f |
initialUpVec
normalized "up" direction (a unit vector)
|
protected InputManager |
inputManager |
protected boolean |
invertY |
protected MotionAllowedListener |
motionAllowed |
protected float |
moveSpeed
translation speed (in world units per second)
|
protected float |
rotationSpeed
rotation-rate multiplier (1=default)
|
protected float |
zoomSpeed
zoom-rate multiplier (1=default)
|
Constructor and Description |
---|
FlyByCamera(Camera cam)
Creates a new FlyByCamera to control the specified camera.
|
Modifier and Type | Method and Description |
---|---|
float |
getMoveSpeed()
Read the translation speed.
|
float |
getRotationSpeed()
Read the rotation-rate multiplier.
|
float |
getZoomSpeed()
Read the zoom-rate multiplier.
|
boolean |
isDragToRotate()
Test whether drag-to-rotate mode is enabled.
|
boolean |
isEnabled()
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 |
onAction(java.lang.String name,
boolean value,
float tpf)
Callback to notify this controller of an action input event.
|
void |
onAnalog(java.lang.String name,
float value,
float tpf)
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 |
setMotionAllowedListener(MotionAllowedListener listener) |
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 |
unregisterInput()
Unregister this controller from its input manager.
|
protected void |
zoomCamera(float value)
Zoom the camera by the specified amount.
|
protected Camera cam
protected Vector3f initialUpVec
protected float rotationSpeed
protected float moveSpeed
protected float zoomSpeed
protected MotionAllowedListener motionAllowed
protected boolean enabled
protected boolean dragToRotate
protected boolean canRotate
protected boolean invertY
protected InputManager inputManager
public FlyByCamera(Camera cam)
cam
- camera to be controlled (not null)public void setUpVector(Vector3f upVec)
upVec
- public void setMotionAllowedListener(MotionAllowedListener listener)
public void setMoveSpeed(float moveSpeed)
moveSpeed
- new speed (in world units per second)public float getMoveSpeed()
public void setRotationSpeed(float rotationSpeed)
rotationSpeed
- new rate multiplier (1=default)public float getRotationSpeed()
public void setZoomSpeed(float zoomSpeed)
zoomSpeed
- new rate multiplier (1=default)public float getZoomSpeed()
public void setEnabled(boolean enable)
enable
- true to enable, false to disablepublic boolean isEnabled()
setEnabled(boolean)
public boolean isDragToRotate()
setDragToRotate(boolean)
public void setDragToRotate(boolean dragToRotate)
dragToRotate
- true to enable, false to disablepublic void registerWithInput(InputManager inputManager)
inputManager
- protected void mapJoystick(Joystick joystick)
public void unregisterInput()
protected void rotateCamera(float value, Vector3f axis)
value
- rotation amountaxis
- direction of rotation (a unit vector)protected void zoomCamera(float value)
value
- zoom amountprotected void riseCamera(float value)
value
- translation amountprotected void moveCamera(float value, boolean sideways)
value
- translation amountsideways
- true→left, false→forwardpublic void onAnalog(java.lang.String name, float value, float tpf)
onAnalog
in interface AnalogListener
name
- name of the input eventvalue
- value of the axis (from 0 to 1)tpf
- time per frame (in seconds)public void onAction(java.lang.String name, boolean value, float tpf)
onAction
in interface ActionListener
name
- name of the input eventvalue
- true if the action is "pressed", false otherwisetpf
- time per frame (in seconds)