Class CustomChaseCamera
- java.lang.Object
-
- jadex.extension.envsupport.observer.graphics.jmonkey.cameratypes.CustomChaseCamera
-
- All Implemented Interfaces:
com.jme3.export.Savable
,com.jme3.input.controls.ActionListener
,com.jme3.input.controls.AnalogListener
,com.jme3.input.controls.InputListener
,com.jme3.scene.control.Control
public class CustomChaseCamera extends java.lang.Object implements com.jme3.input.controls.ActionListener, com.jme3.input.controls.AnalogListener, com.jme3.scene.control.Control
A camera that follows a spatial and can turn around it by dragging the mouse
-
-
Field Summary
Fields Modifier and Type Field Description protected com.jme3.renderer.Camera
cam
protected boolean
canRotate
protected static java.lang.String
ChaseCamDown
protected static java.lang.String
ChaseCamMoveLeft
protected static java.lang.String
ChaseCamMoveRight
protected static java.lang.String
ChaseCamToggleRotate
protected static java.lang.String
ChaseCamUp
protected static java.lang.String
ChaseCamZoomIn
protected static java.lang.String
ChaseCamZoomOut
protected boolean
chasing
protected float
chasingSensitivity
protected float
distance
protected float
distanceLerpFactor
protected boolean
dragToRotate
protected boolean
enabled
protected com.jme3.math.Vector3f
initialUpVec
protected com.jme3.input.InputManager
inputManager
protected boolean
invertXaxis
protected boolean
invertYaxis
protected boolean
leftClickRotate
protected com.jme3.math.Vector3f
lookAtOffset
protected float
maxDistance
protected float
maxVerticalRotation
protected float
minDistance
protected float
minVerticalRotation
protected float
offsetDistance
protected com.jme3.math.Vector3f
pos
protected float
previousTargetRotation
protected com.jme3.math.Vector3f
prevPos
protected boolean
rightClickRotate
protected boolean
rotating
protected float
rotation
protected float
rotationLerpFactor
protected float
rotationSensitivity
protected float
rotationSpeed
protected boolean
smoothMotion
protected com.jme3.scene.Spatial
target
protected com.jme3.math.Vector3f
targetDir
protected float
targetDistance
protected com.jme3.math.Vector3f
targetLocation
protected boolean
targetMoves
protected float
targetRotation
protected float
targetVRotation
protected com.jme3.math.Vector3f
temp
protected boolean
trailing
protected boolean
trailingEnabled
protected float
trailingLerpFactor
protected float
trailingRotationInertia
protected float
trailingSensitivity
protected boolean
vRotating
protected float
vRotation
protected float
vRotationLerpFactor
protected boolean
zooming
protected float
zoomSensitivity
protected float
zoomSpeed
-
Constructor Summary
Constructors Constructor Description CustomChaseCamera(com.jme3.renderer.Camera cam)
Constructs the chase camera if you use this constructor you have to attach the cam later to a spatial doing spatial.addControl(chaseCamera);CustomChaseCamera(com.jme3.renderer.Camera cam, com.jme3.input.InputManager inputManager)
Constructs the chase camera, and registers inputs if you use this constructor you have to attach the cam later to a spatial doing spatial.addControl(chaseCamera);CustomChaseCamera(com.jme3.renderer.Camera cam, com.jme3.scene.Spatial target)
Constructs the chase cameraCustomChaseCamera(com.jme3.renderer.Camera cam, com.jme3.scene.Spatial target, com.jme3.input.InputManager inputManager)
Constructs the chase camera, and registers inputs
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.jme3.scene.control.Control
cloneForSpatial(com.jme3.scene.Spatial spatial)
clone this camera for a spatialfloat
getChasingSensitivity()
returns the chasing sensitivityfloat
getDistanceToTarget()
return the current distance from the camera to the targetfloat
getHorizontalRotation()
returns the current horizontal rotation around the target in radianscom.jme3.math.Vector3f
getLookAtOffset()
float
getMaxDistance()
Returns the max zoom distance of the camera (default is 40)float
getMaxVerticalRotation()
returns the maximal vertical rotation angle of the camera around the targetfloat
getMinDistance()
Returns the min zoom distance of the camera (default is 1)float
getMinVerticalRotation()
returns the minimal vertical rotation angle of the camera around the targetfloat
getRotationSensitivity()
Returns the rotation sensitivityfloat
getTrailingRotationInertia()
returns the trailing rotation inertiafloat
getTrailingSensitivity()
returns the trailing sensitivitycom.jme3.math.Vector3f
getUpVector()
Returns the up vector of the camera used for the lookAt on the targetfloat
getVerticalRotation()
returns the current vertical rotation around the target in radians.float
getZoomSensitivity()
returns the zoom sensitivityboolean
isDragToRotate()
boolean
isEnabled()
Return the enabled/disabled state of the cameraboolean
isSmoothMotion()
returns true is smmoth motion is enabled for this chase cameraboolean
isTrailingEnabled()
returns true if the trailing is enabledvoid
onAction(java.lang.String name, boolean keyPressed, float tpf)
void
onAnalog(java.lang.String name, float value, float tpf)
void
read(com.jme3.export.JmeImporter im)
Read the cameravoid
registerWithInput(com.jme3.input.InputManager inputManager)
Registers inputs with the input managervoid
render(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp)
renders the camera control, should only be used internallyvoid
setChasingSensitivity(float chasingSensitivity)
Sets the chasing sensitivity, the lower the value the slower the camera will follow the target when it moves default is 5 Only has an effect if smoothMotion is set to true and trailing is enabledvoid
setDefaultDistance(float defaultDistance)
Sets the default distance at start of applicaitonvoid
setDefaultHorizontalRotation(float angle)
sets the default horizontal rotation of the camera at start of the applicationvoid
setDefaultVerticalRotation(float angle)
sets the default vertical rotation of the camera at start of the applicationvoid
setDragToRotate(boolean dragToRotate)
void
setEnabled(boolean enabled)
Enable or disable the cameravoid
setInvertHorizontalAxis(boolean invertXaxis)
invert the Horizontal axis movement of the mousevoid
setInvertVerticalAxis(boolean invertYaxis)
invert the vertical axis movement of the mousevoid
setLookAtOffset(com.jme3.math.Vector3f lookAtOffset)
Sets the offset from the target's position where the camera looks atvoid
setMaxDistance(float maxDistance)
Sets the max zoom distance of the camera (default is 40)void
setMaxVerticalRotation(float maxVerticalRotation)
sets the maximal vertical rotation angle of the camera around the target default is Pi/2;void
setMinDistance(float minDistance)
Sets the min zoom distance of the camera (default is 1)void
setMinVerticalRotation(float minHeight)
sets the minimal vertical rotation angle of the camera around the target default is 0;void
setRotationSensitivity(float rotationSensitivity)
Sets the rotation sensitivity, the lower the value the slower the camera will rotates around the target when draging with the mouse default is 5, values over 5 should have no effect.void
setSmoothMotion(boolean smoothMotion)
Enables smooth motion for this chase cameravoid
setSpatial(com.jme3.scene.Spatial spatial)
Sets the spacial for the camera control, should only be used internallyvoid
setToggleRotationTrigger(com.jme3.input.controls.Trigger... triggers)
Sets custom triggers for toggleing the rotation of the cam deafult are new MouseButtonTrigger(MouseInput.BUTTON_LEFT) left mouse button new MouseButtonTrigger(MouseInput.BUTTON_RIGHT) right mouse buttonvoid
setTrailingEnabled(boolean trailingEnabled)
Enable the camera trailing : The camera smoothly go in the targets trail when it moves.void
setTrailingRotationInertia(float trailingRotationInertia)
Sets the trailing rotation inertia : default is 0.1.void
setTrailingSensitivity(float trailingSensitivity)
Only has an effect if smoothMotion is set to true and trailing is enabled Sets the trailing sensitivity, the lower the value, the slower the camera will go in the target trail when it moves.void
setUpVector(com.jme3.math.Vector3f up)
Sets the up vector of the camera used for the lookAt on the targetvoid
setZoomInTrigger(com.jme3.input.controls.Trigger... triggers)
Sets custom triggers for zomming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel upvoid
setZoomOutTrigger(com.jme3.input.controls.Trigger... triggers)
Sets custom triggers for zomming out the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel downvoid
setZoomSensitivity(float zoomSensitivity)
Sets the zoom sensitivity, the lower the value, the slower the camera will zoom in and out.void
update(float tpf)
update the camera control, should only be used internallyprotected void
updateCamera(float tpf)
Updates the camera, should only be called internallyvoid
write(com.jme3.export.JmeExporter ex)
Write the camera
-
-
-
Field Detail
-
target
protected com.jme3.scene.Spatial target
-
minVerticalRotation
protected float minVerticalRotation
-
maxVerticalRotation
protected float maxVerticalRotation
-
minDistance
protected float minDistance
-
maxDistance
protected float maxDistance
-
distance
protected float distance
-
zoomSpeed
protected float zoomSpeed
-
rotationSpeed
protected float rotationSpeed
-
rotation
protected float rotation
-
trailingRotationInertia
protected float trailingRotationInertia
-
zoomSensitivity
protected float zoomSensitivity
-
rotationSensitivity
protected float rotationSensitivity
-
chasingSensitivity
protected float chasingSensitivity
-
trailingSensitivity
protected float trailingSensitivity
-
vRotation
protected float vRotation
-
smoothMotion
protected boolean smoothMotion
-
trailingEnabled
protected boolean trailingEnabled
-
rotationLerpFactor
protected float rotationLerpFactor
-
trailingLerpFactor
protected float trailingLerpFactor
-
rotating
protected boolean rotating
-
vRotating
protected boolean vRotating
-
targetRotation
protected float targetRotation
-
inputManager
protected com.jme3.input.InputManager inputManager
-
initialUpVec
protected com.jme3.math.Vector3f initialUpVec
-
targetVRotation
protected float targetVRotation
-
vRotationLerpFactor
protected float vRotationLerpFactor
-
targetDistance
protected float targetDistance
-
distanceLerpFactor
protected float distanceLerpFactor
-
zooming
protected boolean zooming
-
trailing
protected boolean trailing
-
chasing
protected boolean chasing
-
canRotate
protected boolean canRotate
-
offsetDistance
protected float offsetDistance
-
prevPos
protected com.jme3.math.Vector3f prevPos
-
targetMoves
protected boolean targetMoves
-
enabled
protected boolean enabled
-
cam
protected com.jme3.renderer.Camera cam
-
targetDir
protected final com.jme3.math.Vector3f targetDir
-
previousTargetRotation
protected float previousTargetRotation
-
pos
protected final com.jme3.math.Vector3f pos
-
targetLocation
protected com.jme3.math.Vector3f targetLocation
-
dragToRotate
protected boolean dragToRotate
-
lookAtOffset
protected com.jme3.math.Vector3f lookAtOffset
-
leftClickRotate
protected boolean leftClickRotate
-
rightClickRotate
protected boolean rightClickRotate
-
temp
protected com.jme3.math.Vector3f temp
-
invertYaxis
protected boolean invertYaxis
-
invertXaxis
protected boolean invertXaxis
-
ChaseCamDown
protected static final java.lang.String ChaseCamDown
- See Also:
- Constant Field Values
-
ChaseCamUp
protected static final java.lang.String ChaseCamUp
- See Also:
- Constant Field Values
-
ChaseCamZoomIn
protected static final java.lang.String ChaseCamZoomIn
- See Also:
- Constant Field Values
-
ChaseCamZoomOut
protected static final java.lang.String ChaseCamZoomOut
- See Also:
- Constant Field Values
-
ChaseCamMoveLeft
protected static final java.lang.String ChaseCamMoveLeft
- See Also:
- Constant Field Values
-
ChaseCamMoveRight
protected static final java.lang.String ChaseCamMoveRight
- See Also:
- Constant Field Values
-
ChaseCamToggleRotate
protected static final java.lang.String ChaseCamToggleRotate
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CustomChaseCamera
public CustomChaseCamera(com.jme3.renderer.Camera cam, com.jme3.scene.Spatial target)
Constructs the chase camera- Parameters:
cam
- the application cameratarget
- the spatial to follow
-
CustomChaseCamera
public CustomChaseCamera(com.jme3.renderer.Camera cam)
Constructs the chase camera if you use this constructor you have to attach the cam later to a spatial doing spatial.addControl(chaseCamera);- Parameters:
cam
- the application camera
-
CustomChaseCamera
public CustomChaseCamera(com.jme3.renderer.Camera cam, com.jme3.input.InputManager inputManager)
Constructs the chase camera, and registers inputs if you use this constructor you have to attach the cam later to a spatial doing spatial.addControl(chaseCamera);- Parameters:
cam
- the application camerainputManager
- the inputManager of the application to register inputs
-
CustomChaseCamera
public CustomChaseCamera(com.jme3.renderer.Camera cam, com.jme3.scene.Spatial target, com.jme3.input.InputManager inputManager)
Constructs the chase camera, and registers inputs- Parameters:
cam
- the application cameratarget
- the spatial to followinputManager
- the inputManager of the application to register inputs
-
-
Method Detail
-
onAction
public void onAction(java.lang.String name, boolean keyPressed, float tpf)
- Specified by:
onAction
in interfacecom.jme3.input.controls.ActionListener
-
onAnalog
public void onAnalog(java.lang.String name, float value, float tpf)
- Specified by:
onAnalog
in interfacecom.jme3.input.controls.AnalogListener
-
registerWithInput
public final void registerWithInput(com.jme3.input.InputManager inputManager)
Registers inputs with the input manager- Parameters:
inputManager
-
-
setToggleRotationTrigger
public void setToggleRotationTrigger(com.jme3.input.controls.Trigger... triggers)
Sets custom triggers for toggleing the rotation of the cam deafult are new MouseButtonTrigger(MouseInput.BUTTON_LEFT) left mouse button new MouseButtonTrigger(MouseInput.BUTTON_RIGHT) right mouse button- Parameters:
triggers
-
-
setZoomInTrigger
public void setZoomInTrigger(com.jme3.input.controls.Trigger... triggers)
Sets custom triggers for zomming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel up- Parameters:
triggers
-
-
setZoomOutTrigger
public void setZoomOutTrigger(com.jme3.input.controls.Trigger... triggers)
Sets custom triggers for zomming out the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel down- Parameters:
triggers
-
-
updateCamera
protected void updateCamera(float tpf)
Updates the camera, should only be called internally
-
isEnabled
public boolean isEnabled()
Return the enabled/disabled state of the camera- Returns:
- true if the camera is enabled
-
setEnabled
public void setEnabled(boolean enabled)
Enable or disable the camera- Parameters:
enabled
- true to enable
-
getMaxDistance
public float getMaxDistance()
Returns the max zoom distance of the camera (default is 40)- Returns:
- maxDistance
-
setMaxDistance
public void setMaxDistance(float maxDistance)
Sets the max zoom distance of the camera (default is 40)- Parameters:
maxDistance
-
-
getMinDistance
public float getMinDistance()
Returns the min zoom distance of the camera (default is 1)- Returns:
- minDistance
-
setMinDistance
public void setMinDistance(float minDistance)
Sets the min zoom distance of the camera (default is 1)
-
cloneForSpatial
public com.jme3.scene.control.Control cloneForSpatial(com.jme3.scene.Spatial spatial)
clone this camera for a spatial- Specified by:
cloneForSpatial
in interfacecom.jme3.scene.control.Control
- Parameters:
spatial
-
-
setSpatial
public void setSpatial(com.jme3.scene.Spatial spatial)
Sets the spacial for the camera control, should only be used internally- Specified by:
setSpatial
in interfacecom.jme3.scene.control.Control
- Parameters:
spatial
-
-
update
public void update(float tpf)
update the camera control, should only be used internally- Specified by:
update
in interfacecom.jme3.scene.control.Control
- Parameters:
tpf
-
-
render
public void render(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp)
renders the camera control, should only be used internally- Specified by:
render
in interfacecom.jme3.scene.control.Control
- Parameters:
rm
-vp
-
-
write
public void write(com.jme3.export.JmeExporter ex) throws java.io.IOException
Write the camera- Specified by:
write
in interfacecom.jme3.export.Savable
- Parameters:
ex
- the exporter- Throws:
java.io.IOException
-
read
public void read(com.jme3.export.JmeImporter im) throws java.io.IOException
Read the camera- Specified by:
read
in interfacecom.jme3.export.Savable
- Parameters:
im
-- Throws:
java.io.IOException
-
getMaxVerticalRotation
public float getMaxVerticalRotation()
returns the maximal vertical rotation angle of the camera around the target
-
setMaxVerticalRotation
public void setMaxVerticalRotation(float maxVerticalRotation)
sets the maximal vertical rotation angle of the camera around the target default is Pi/2;- Parameters:
maxVerticalRotation
-
-
getMinVerticalRotation
public float getMinVerticalRotation()
returns the minimal vertical rotation angle of the camera around the target
-
setMinVerticalRotation
public void setMinVerticalRotation(float minHeight)
sets the minimal vertical rotation angle of the camera around the target default is 0;- Parameters:
minHeight
-
-
isSmoothMotion
public boolean isSmoothMotion()
returns true is smmoth motion is enabled for this chase camera
-
setSmoothMotion
public void setSmoothMotion(boolean smoothMotion)
Enables smooth motion for this chase camera- Parameters:
smoothMotion
-
-
getChasingSensitivity
public float getChasingSensitivity()
returns the chasing sensitivity
-
setChasingSensitivity
public void setChasingSensitivity(float chasingSensitivity)
Sets the chasing sensitivity, the lower the value the slower the camera will follow the target when it moves default is 5 Only has an effect if smoothMotion is set to true and trailing is enabled- Parameters:
chasingSensitivity
-
-
getRotationSensitivity
public float getRotationSensitivity()
Returns the rotation sensitivity
-
setRotationSensitivity
public void setRotationSensitivity(float rotationSensitivity)
Sets the rotation sensitivity, the lower the value the slower the camera will rotates around the target when draging with the mouse default is 5, values over 5 should have no effect. If you want a significant slow down try values below 1. Only has an effect if smoothMotion is set to true- Parameters:
rotationSensitivity
-
-
isTrailingEnabled
public boolean isTrailingEnabled()
returns true if the trailing is enabled
-
setTrailingEnabled
public void setTrailingEnabled(boolean trailingEnabled)
Enable the camera trailing : The camera smoothly go in the targets trail when it moves. Only has an effect if smoothMotion is set to true- Parameters:
trailingEnabled
-
-
getTrailingRotationInertia
public float getTrailingRotationInertia()
returns the trailing rotation inertia
-
setTrailingRotationInertia
public void setTrailingRotationInertia(float trailingRotationInertia)
Sets the trailing rotation inertia : default is 0.1. This prevent the camera to roughtly stop when the target stops moving before the camera reached the trail position. Only has an effect if smoothMotion is set to true and trailing is enabled- Parameters:
trailingRotationInertia
-
-
getTrailingSensitivity
public float getTrailingSensitivity()
returns the trailing sensitivity
-
setTrailingSensitivity
public void setTrailingSensitivity(float trailingSensitivity)
Only has an effect if smoothMotion is set to true and trailing is enabled Sets the trailing sensitivity, the lower the value, the slower the camera will go in the target trail when it moves. default is 0.5;- Parameters:
trailingSensitivity
-
-
getZoomSensitivity
public float getZoomSensitivity()
returns the zoom sensitivity
-
setZoomSensitivity
public void setZoomSensitivity(float zoomSensitivity)
Sets the zoom sensitivity, the lower the value, the slower the camera will zoom in and out. default is 5.- Parameters:
zoomSensitivity
-
-
setDefaultDistance
public void setDefaultDistance(float defaultDistance)
Sets the default distance at start of applicaiton- Parameters:
defaultDistance
-
-
setDefaultHorizontalRotation
public void setDefaultHorizontalRotation(float angle)
sets the default horizontal rotation of the camera at start of the application- Parameters:
angle
-
-
setDefaultVerticalRotation
public void setDefaultVerticalRotation(float angle)
sets the default vertical rotation of the camera at start of the application- Parameters:
angle
-
-
isDragToRotate
public boolean isDragToRotate()
- Returns:
- If drag to rotate feature is enabled.
- See Also:
FlyByCamera.setDragToRotate(boolean)
-
setDragToRotate
public void setDragToRotate(boolean dragToRotate)
- Parameters:
dragToRotate
- When true, the user must hold the mouse button and drag over the screen to rotate the camera, and the cursor is visible until dragged. Otherwise, the cursor is invisible at all times and holding the mouse button is not needed to rotate the camera. This feature is disabled by default.
-
getDistanceToTarget
public float getDistanceToTarget()
return the current distance from the camera to the target
-
getHorizontalRotation
public float getHorizontalRotation()
returns the current horizontal rotation around the target in radians
-
getVerticalRotation
public float getVerticalRotation()
returns the current vertical rotation around the target in radians.
-
getLookAtOffset
public com.jme3.math.Vector3f getLookAtOffset()
-
setLookAtOffset
public void setLookAtOffset(com.jme3.math.Vector3f lookAtOffset)
Sets the offset from the target's position where the camera looks at- Parameters:
lookAtOffset
-
-
setUpVector
public void setUpVector(com.jme3.math.Vector3f up)
Sets the up vector of the camera used for the lookAt on the target- Parameters:
up
-
-
getUpVector
public com.jme3.math.Vector3f getUpVector()
Returns the up vector of the camera used for the lookAt on the target
-
setInvertVerticalAxis
public void setInvertVerticalAxis(boolean invertYaxis)
invert the vertical axis movement of the mouse- Parameters:
invertYaxis
-
-
setInvertHorizontalAxis
public void setInvertHorizontalAxis(boolean invertXaxis)
invert the Horizontal axis movement of the mouse- Parameters:
invertXaxis
-
-
-