org.jrabbit.standard.game.world.camera.components
Class CameraShaker

java.lang.Object
  extended by org.jrabbit.standard.game.world.camera.components.CameraShaker
All Implemented Interfaces:
Updateable

public class CameraShaker
extends java.lang.Object
implements Updateable

A CameraShaker "shakes" the Camera as a game progresses, giving the impression that the gameworld is being violently affected. It has two controls - a boolean for whether or not it should be active, and a value for how strong the shaking effect should be. The default setup found here simply randomly shifts the viewpoint, rotates the camera's rotation, and slightly affects the camera's zoom by an amount determined shaking strength.

Author:
Chris Molini

Field Summary
protected  boolean active
          Whether or not the shaking should be considered active.
protected  Rotation rotation
          The rotation to affect.
protected  Scalar scalar
          The scaling to affect.
protected  float strength
          How strong the affect should be.
protected  Vector2f viewpoint
          This is the viewpoint to affect.
 
Constructor Summary
CameraShaker(Vector2f viewpoint, Rotation rotation, Scalar scalar)
          Creates a CameraShaker that will jitter the supplied Camera.
 
Method Summary
 boolean active()
          Accesses the shaking controls.
 void reset()
          This resets the shaking controls to what they are initially - enabled but strength at 0.
 void set(float strength)
          Redefines how strong the shaking should be.
 void setActive(boolean active)
          Redefines the active flag.
 float strength()
          Accesses the shaking controls.
 void update(int delta)
          Advances the shaking effect.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

viewpoint

protected Vector2f viewpoint
This is the viewpoint to affect.


rotation

protected Rotation rotation
The rotation to affect.


scalar

protected Scalar scalar
The scaling to affect.


active

protected boolean active
Whether or not the shaking should be considered active.


strength

protected float strength
How strong the affect should be.

Constructor Detail

CameraShaker

public CameraShaker(Vector2f viewpoint,
                    Rotation rotation,
                    Scalar scalar)
Creates a CameraShaker that will jitter the supplied Camera. NOTE: When initially created, shaking is enabled but the strength is set to 0.

Parameters:
viewpoint - The Vector2f to affect.
rotation - The Rotation to affect.
scalar - The Scalar to affect.
Method Detail

reset

public void reset()
This resets the shaking controls to what they are initially - enabled but strength at 0.


strength

public float strength()
Accesses the shaking controls.

Returns:
How strong the shaking effect is set to be.

set

public void set(float strength)
Redefines how strong the shaking should be. Depending on the shaking implementation, different scales of "strong" might be in place; as it is, this shaking value gets somewhat out of control at values past 5. 1-5 is a good range for shaking that should be overtly noticeable, but levels less than 1.0 are good for subtle "tremors."

Parameters:
strength - How strong the shaking should be.

active

public boolean active()
Accesses the shaking controls.

Returns:
Whether or not shaking is active.

setActive

public void setActive(boolean active)
Redefines the active flag.

Parameters:
active - Whether or not shaking is enabled.

update

public void update(int delta)
Advances the shaking effect. If set to active, the viewpoint, rotation and scalar are shaken about.

Specified by:
update in interface Updateable
Parameters:
delta - The number of microseconds that has elapsed since the last update.