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

java.lang.Object
  extended by org.jrabbit.standard.game.world.camera.components.CameraViewChecker
All Implemented Interfaces:
Updateable, RotationListener, ScalarListener, Viewer

public class CameraViewChecker
extends java.lang.Object
implements Viewer, RotationListener, ScalarListener, Updateable

A CameraViewCheck handles checking to see if objects in the game world are being viewed by the camera. This allows the game to stop offscreen objects from being rendered, speeding up render time. This onscreen-checking is fairly optimized, but it is a bit complex. Basically, the CameraViewChecker caches all variables used in calculations that can be cached, and uses a "lossy" equation to determine onscreen-ness that is much faster than calculating trig variables for each check.

Author:
Chris Molini

Field Summary
(package private)  boolean needsRecalc
          Whether or not the CameraViewChecker should recalculate the variables it uses to determine culling.
protected  float radiusScale
          The amount to scale the indicated
protected  Rotation rotation
          The rotation that determines the angle of the viewed scene.
protected  Scalar scalar
          The Scalar that determines the scale of the viewed scene.
protected  float viewHeightVal
          Half the height of the viewed scene; used in culling.
protected  float viewWidthVal
          Half the width of the viewed scene; used in culling.
protected  float xToX
          A variable used to transform the unrotated coordinates into sensible values.
protected  float xToY
          A variable used to transform the unrotated coordinates into sensible values.
protected  float yToX
          A variable used to transform the unrotated coordinates into sensible values.
protected  float yToY
          A variable used to transform the unrotated coordinates into sensible values.
 
Constructor Summary
CameraViewChecker(Rotation rotation, Scalar scalar)
          Creates a CameraViewChecker that uses the indicated rotation and scaling objects to calculate culling.
 
Method Summary
 void flipped(Scalar scalar)
          Flipping does not actually affect the results of culling, so this is safely ignored.
 void recalculate()
          Recalculates all values used to optimize viewing checking.
 void rotated(Rotation rotation)
          Flags that recalculation needs to occur, since the rotation of the view has been changed.
 void scaled(Scalar scalar)
          Flags that recalculation needs to occur, since the scaling of the view has been changed.
 void update(int delta)
          Resets the viewing dimensions, and checks to see if culling variables need to be recalculated.
 boolean views(float x, float y, float radius)
          Determines if the object described is onscreen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rotation

protected Rotation rotation
The rotation that determines the angle of the viewed scene.


scalar

protected Scalar scalar
The Scalar that determines the scale of the viewed scene.


needsRecalc

boolean needsRecalc
Whether or not the CameraViewChecker should recalculate the variables it uses to determine culling.


viewWidthVal

protected float viewWidthVal
Half the width of the viewed scene; used in culling.


viewHeightVal

protected float viewHeightVal
Half the height of the viewed scene; used in culling.


xToX

protected float xToX
A variable used to transform the unrotated coordinates into sensible values.


xToY

protected float xToY
A variable used to transform the unrotated coordinates into sensible values.


yToX

protected float yToX
A variable used to transform the unrotated coordinates into sensible values.


yToY

protected float yToY
A variable used to transform the unrotated coordinates into sensible values.


radiusScale

protected float radiusScale
The amount to scale the indicated

Constructor Detail

CameraViewChecker

public CameraViewChecker(Rotation rotation,
                         Scalar scalar)
Creates a CameraViewChecker that uses the indicated rotation and scaling objects to calculate culling.

Parameters:
rotation - The Rotation to use for culling.
scalar - The Scalar to use for culling.
Method Detail

views

public boolean views(float x,
                     float y,
                     float radius)
Determines if the object described is onscreen.

Specified by:
views in interface Viewer
Parameters:
x - The relative x coordinate to the center of the view.
y - The relative y coordinate to the center of the view.
radius - The radius that the object fits within.
Returns:
True if the object can conceivably be viewed, regardless of its rotation, otherwise false.

rotated

public void rotated(Rotation rotation)
Flags that recalculation needs to occur, since the rotation of the view has been changed.

Specified by:
rotated in interface RotationListener
Parameters:
rotation - The Rotation that was rotated.

flipped

public void flipped(Scalar scalar)
Flipping does not actually affect the results of culling, so this is safely ignored.

Specified by:
flipped in interface ScalarListener
Parameters:
scalar - The Scalar that was flipped.

scaled

public void scaled(Scalar scalar)
Flags that recalculation needs to occur, since the scaling of the view has been changed.

Specified by:
scaled in interface ScalarListener
Parameters:
scalar - The Scalar that was scaled.

recalculate

public void recalculate()
Recalculates all values used to optimize viewing checking.


update

public void update(int delta)
Resets the viewing dimensions, and checks to see if culling variables need to be recalculated.

Specified by:
update in interface Updateable
Parameters:
delta - The number of microseconds that have passed.