com.brackeen.javagamebook.game
Class CollisionDetection

java.lang.Object
  extended bycom.brackeen.javagamebook.game.CollisionDetection
Direct Known Subclasses:
CollisionDetectionWithSliding

public class CollisionDetection
extends java.lang.Object

The CollisionDetection class handles collision detection between the GameObjects, and between GameObjects and a BSP tree. When a collision occurs, the GameObject stops.


Constructor Summary
CollisionDetection(BSPTree bspTree)
          Creates a new CollisionDetection object for the specified BSP tree.
 
Method Summary
 boolean checkBSP(GameObject object, Vector3D oldLocation, long elapsedTime)
          Checks a GameObject against the BSP tree.
 boolean checkObject(GameObject objectA, GameObject objectB, Vector3D oldLocation)
          Returns true if the two specified objects collide.
 boolean checkObject(GameObject objectA, java.util.List objects, Vector3D oldLocation)
          Checks if the specified object collisions with any other object in the specified list.
 BSPPolygon checkWalls(GameObject object, Vector3D oldLocation, long elapsedTime)
          Checks for a game object collision with the walls of the BSP tree.
 BSPPolygon getFirstWallIntersection(float x1, float z1, float x2, float z2, float yBottom, float yTop)
          Gets the first intersection, if any, of the path (x1,z1)-> (x2,z2) with the walls of the BSP tree.
 void getFloorAndCeiling(GameObject object)
          Gets the floor and ceiling values for the specified GameObject.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollisionDetection

public CollisionDetection(BSPTree bspTree)
Creates a new CollisionDetection object for the specified BSP tree.

Method Detail

checkBSP

public boolean checkBSP(GameObject object,
                        Vector3D oldLocation,
                        long elapsedTime)
Checks a GameObject against the BSP tree. Returns true if a wall collision occurred.


getFloorAndCeiling

public void getFloorAndCeiling(GameObject object)
Gets the floor and ceiling values for the specified GameObject. Calls object.setFloorHeight() and object.setCeilHeight() to set the floor and ceiling values.


checkWalls

public BSPPolygon checkWalls(GameObject object,
                             Vector3D oldLocation,
                             long elapsedTime)
Checks for a game object collision with the walls of the BSP tree. Returns the first wall collided with, or null if there was no collision.


getFirstWallIntersection

public BSPPolygon getFirstWallIntersection(float x1,
                                           float z1,
                                           float x2,
                                           float z2,
                                           float yBottom,
                                           float yTop)
Gets the first intersection, if any, of the path (x1,z1)-> (x2,z2) with the walls of the BSP tree. Returns the first BSPPolygon intersection, or null if no intersection occurred.


checkObject

public boolean checkObject(GameObject objectA,
                           java.util.List objects,
                           Vector3D oldLocation)
Checks if the specified object collisions with any other object in the specified list.


checkObject

public boolean checkObject(GameObject objectA,
                           GameObject objectB,
                           Vector3D oldLocation)
Returns true if the two specified objects collide. Object A is the moving object, and Object B is the object to check. Uses bounding upright cylinders (circular base and top) to determine collisions.