jme.controller
Class BaseFPSController

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

public class BaseFPSController
extends AbstractGameController

BaseFPSController creates a base class for developing a first person shooter style control system. That is, the view is controlled via moving forward, backward, strafing to the left and right and changing orientation based on mouse movements. The basic assumption is that the keyboard is used to alter the position of the camera while the mouse is used to alter it's orientation. The key bindings have a default of:

w - forward s - backward a - strafe left d - strafe right.

Addition key bindings are provided by overriding the checkAdditionalKeys method.

Version:
0.1.0
Author:
Mark Powell

Field Summary
protected  float accuracy
           
protected  KeyBindingManager key
           
 
Constructor Summary
BaseFPSController(Camera entity)
          Constructor sets the entity to the given entity and initializes the controller for use.
BaseFPSController(int id)
          Constructor builds a controller with all default values.
 
Method Summary
protected  boolean checkAdditionalKeys()
          checkAdditionalKeys tests the keyboard for any additional key bindings.
 Vector getEntityUp()
          getEntityUp return the orientation of the camera.
 Vector getEntityView()
          getEntityView returns the point that the camera is viewing.
 void move(float speed)
          move changes the position of the camera depending on it's orientation.
 void panView(float angle)
          paneView rotates the entity about it's local Y-Axis.
 void raise(float speed)
          raise alters the position and view of the entity such that it raises or lowers along the local Y-Axis.
 void render()
          render sets the model view matrix to that defined by the Entity's position, view and up vectors.
 void rotate(float angle, Vector axis)
          rotate rotates the camera's view about a given axis.
 void setAccuracy(float value)
          setAccuracy sets the accuracy value for mouse control.
 void setEntityUp(Vector up)
          setEntityUp sets the vector that represents the up or orientation of the entity.
 void setEntityView(Vector view)
          setEntityView sets the point at which the camera is pointed at.
 void setMovementSpeed(float value)
          setMovementSpeed adjusts the speed at which forward/backward movement occurs.
 void strafe(float speed)
          strafe moves the camera along the perpendicular axis of it's view.
 void tiltView(int angle)
          tiltView rotates the entity about it's local X-Axis.
 boolean update(float time)
          update overrides AbstractGameController's update method.
 
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

accuracy

protected float accuracy

key

protected KeyBindingManager key
Constructor Detail

BaseFPSController

public BaseFPSController(int id)
Constructor builds a controller with all default values.


BaseFPSController

public BaseFPSController(Camera entity)
Constructor sets the entity to the given entity and initializes the controller for use.

Parameters:
entity - the entity to control.
Throws:
MonkeyRuntimeException - if the entity is null.
Method Detail

tiltView

public void tiltView(int angle)
tiltView rotates the entity about it's local X-Axis. Allowing the entity to look up and down. The amount of tilting is denoted by the angle parameter, where positive angle is up and negative angle is down.

Parameters:
angle - the amount to tilt.

panView

public void panView(float angle)
paneView rotates the entity about it's local Y-Axis. Allowing the entity to look left and right. The amount of panning is denoted by the angle parameter, where positive angle is right and negative angle is left.

Parameters:
angle - to amount to tilt.

raise

public void raise(float speed)
raise alters the position and view of the entity such that it raises or lowers along the local Y-Axis. The amount of altitude change is denoted by the speed parameter, where positive speed will raise and negative speed will lower.

Parameters:
speed - the amount to raise or lower.

update

public boolean update(float time)
update overrides AbstractGameController's update method. This is intended to be called each frame or round. During an update, the mouse is polled and the change in position reflects in a call to tiltView and panView. A poll is also made to the keyboard, where the key bindings are check against the keyboard state. If necessary, the entity is then moved. 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.

Specified by:
update in class AbstractGameController
Parameters:
time - denotes the current speed of the rendering, to allow for time based movements.
Returns:
boolean true continue for another frame, false stop.

render

public void render()
Description copied from interface: EntityController
render sets the model view matrix to that defined by the Entity's position, view and up vectors.

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

setAccuracy

public void setAccuracy(float value)
setAccuracy sets the accuracy value for mouse control.

Parameters:
value - the new accuracy value.

setMovementSpeed

public void setMovementSpeed(float value)
setMovementSpeed adjusts the speed at which forward/backward movement occurs. Default value is 10.

Parameters:
value - the new speed of movement.

getEntityView

public Vector getEntityView()
getEntityView returns the point that the camera is viewing.

Returns:
the point that the camera is looking at.

getEntityUp

public Vector getEntityUp()
getEntityUp return the orientation of the camera.

Returns:
the orientation of the camera.

setEntityView

public void setEntityView(Vector view)
setEntityView sets the point at which the camera is pointed at.

Parameters:
view - the point the camera is looking at.

setEntityUp

public void setEntityUp(Vector up)
setEntityUp sets the vector that represents the up or orientation of the entity.


rotate

public void rotate(float angle,
                   Vector axis)
rotate rotates the camera's view about a given axis.

Parameters:
angle - the angle to rotate.
axis - the axis to rotate about.

move

public void move(float speed)
move changes the position of the camera depending on it's orientation.

Parameters:
speed - how much to move the camera.

strafe

public void strafe(float speed)
strafe moves the camera along the perpendicular axis of it's view.

Parameters:
speed - how much to strafe the camera.

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.