|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjme.controller.AbstractGameController
jme.controller.BaseFPSController
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.
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 |
protected float accuracy
protected KeyBindingManager key
Constructor Detail |
public BaseFPSController(int id)
public BaseFPSController(Camera entity)
entity
- the entity to control.
MonkeyRuntimeException
- if the entity is null.Method Detail |
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.
angle
- the amount to tilt.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.
angle
- to amount to tilt.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.
speed
- the amount to raise or lower.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.
update
in class AbstractGameController
time
- denotes the current speed of the rendering, to allow
for time based movements.
public void render()
EntityController
render
sets the model view matrix to that defined by the
Entity's position, view and up vectors.
render
in interface EntityController
render
in class AbstractGameController
EntityController.render()
public void setAccuracy(float value)
setAccuracy
sets the accuracy value for mouse control.
value
- the new accuracy value.public void setMovementSpeed(float value)
setMovementSpeed
adjusts the speed at which forward/backward
movement occurs. Default value is 10.
value
- the new speed of movement.public Vector getEntityView()
getEntityView
returns the point that the camera is
viewing.
public Vector getEntityUp()
getEntityUp
return the orientation of the camera.
public void setEntityView(Vector view)
setEntityView
sets the point at which the camera is
pointed at.
view
- the point the camera is looking at.public void setEntityUp(Vector up)
setEntityUp
sets the vector that represents the
up or orientation of the entity.
public void rotate(float angle, Vector axis)
rotate
rotates the camera's view about a given axis.
angle
- the angle to rotate.axis
- the axis to rotate about.public void move(float speed)
move
changes the position of the camera depending on
it's orientation.
speed
- how much to move the camera.public void strafe(float speed)
strafe
moves the camera along the perpendicular axis of
it's view.
speed
- how much to strafe the camera.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.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |