jme.controller
Class TrackingController

java.lang.Object
  extended byjme.controller.AbstractGameController
      extended byjme.controller.TrackingController
All Implemented Interfaces:
EntityController, KeyboardController, MouseController

public class TrackingController
extends AbstractGameController

TrackingController defines a controller that uses a camera to "follow" a given entity. It is intended to be used such that the user is directly controlling an entity. As that entity moves away, the camera trackings it by updating it's view. If the entity is getting too far away, the camera moves to maintain a minimal distance. Movement of the entity is handled by the entity's PhysicsModule. If no such module exists, the entity will not be moved via TrackingController.

Author:
Mark Powell

Field Summary
protected  KeyBindingManager key
           
 
Fields inherited from class jme.controller.AbstractGameController
entity
 
Constructor Summary
TrackingController(Entity entity, Camera camera)
          Constructor instantiates a new TrackingController object.
 
Method Summary
protected  boolean checkAdditionalKeys()
          checkAdditionalKeys tests the keyboard for any additional key bindings.
 void render()
          render calls the render method for the camera updating the camera's viewport.
 void setTrackingDistance(float trackingDistance)
          setTrackingDistance sets the distance to follow behind the entity.
 void setTrackingSpeed(float trackingSpeed)
          setTrackingSpeed sets the speed at which the camera follows the entity.
 boolean update(float time)
          update refreshes the camera and checks the tracking distance.
 
Methods inherited from class jme.controller.AbstractGameController
getAbsoluteMousePositionX, getAbsoluteMousePositionY, getEntityPosition, getMouseDeltaX, getMouseDeltaY, getMousePositionX, getMousePositionY, getNumberOfButtons, isButtonDown, isKeyDown, next, pollKeyboard, pollMouse, setBuffered, setEntityPitch, setEntityPosition, setEntityRoll, setEntityYaw, setMousePosition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

key

protected KeyBindingManager key
Constructor Detail

TrackingController

public TrackingController(Entity entity,
                          Camera camera)
Constructor instantiates a new TrackingController object. During instantiation, it sets the input devices for use and the key bindings are set.

Parameters:
entity - the entity to track.
camera - the camera to use for tracking.
Throws:
MonkeyRuntimeException - if entity or camera are null.
Method Detail

render

public void render()
render calls the render method for the camera updating the camera's viewport.

Specified by:
render in interface EntityController
Specified by:
render in class AbstractGameController
See Also:
EntityController.render()

update

public boolean update(float time)
update refreshes the camera and checks the tracking distance. Key presses are then checked and the entity is updated if needed.

Specified by:
update in class AbstractGameController
Parameters:
time - the time between updates.

setTrackingDistance

public void setTrackingDistance(float trackingDistance)
setTrackingDistance sets the distance to follow behind the entity. If the camera is further than this tracking distance, the camera will move towards the entity. The speed at which the camera moves is dependant on the tracking speed.

Parameters:
trackingDistance - the minimal distance the camera is allowed to follow behind.

setTrackingSpeed

public void setTrackingSpeed(float trackingSpeed)
setTrackingSpeed sets the speed at which the camera follows the entity.

Parameters:
trackingSpeed - the speed at which the camera follows the entity.

checkAdditionalKeys

protected boolean checkAdditionalKeys()
checkAdditionalKeys tests the keyboard for any additional key bindings. It is recommended that this be overridden by any subclass to add additional key bindings. The method returns a boolean. This boolean notifies if the game should be stopped or not. Default false is generated by hitting the escape key.