espresso3d.engine.collision
Class E3DCollisionDetect

java.lang.Object
  extended byespresso3d.engine.base.E3DEngineItem
      extended byespresso3d.engine.collision.E3DCollisionDetect

public class E3DCollisionDetect
extends E3DEngineItem

Author:
espresso3d This contains collision detection helpers and the main collision detection routine for checking collisions in the world.

Field Summary
static java.lang.String SOURCE_COLLISIONTYPE_AABOUNDINGBOX
          TODO: Not Implemented Axially Aligned Bounding Box collision for the source object
static java.lang.String SOURCE_COLLISIONTYPE_BOUNDINGSPHERE_ACCURATE
          Bounding sphere collision for the source object.
static java.lang.String SOURCE_COLLISIONTYPE_BOUNDINGSPHERE_FAST
          Bounding sphere collision for the source object.
static java.lang.String SOURCE_COLLISIONTYPE_SEGMENT
          Basic line segment collision detection for the source object
static java.lang.String SOURCE_COLLISIONTYPE_TRIANGLES
          Triangle collision detection for the source object to check if triangle in the source model collides with the dest object Can be -very- slow if the source has lots of triangles in its model
 
Constructor Summary
E3DCollisionDetect(E3DEngine engine)
           
 
Method Summary
 E3DCollision checkCollision(java.lang.String sourceDetectorName, boolean useBoundingObjectsIfPossible, boolean notifyAllObjectsCollided, E3DCollisionDetectableObject sourceObject, E3DVector3F startPos, E3DVector3F endPos, E3DWorld world)
          Will perform a collision check to see if the sourceActor collides with anything else in the world between startPos and endPos.
static boolean checkFastCollisionWithPlane(E3DVector3F startPos, E3DVector3F endPos, E3DTriangle triangle)
          Will probably be moved.
 E3DSector checkForPortalCollisionsAndGetSectorChange(E3DVector3F startPos, E3DVector3F endPos, E3DSector sector)
          This method is used mainly by the engine to see when it translates objects, if they collide with a portal.
static E3DVector3F checkSegmentTriangleCollision(E3DVector3F startPos, E3DVector3F endPos, E3DTriangle triangle)
          Will probably be moved.
static E3DVector3F checkTriangleTriangleCollision(E3DTriangle colliderTriangle, E3DVector3F startPos, E3DVector3F endPos, E3DTriangle collideeTriangle)
          Will probably be moved.
 java.util.HashMap getCollisionDetectors()
           
static E3DVector3F getIntersectionPoint(E3DVector3F startPos, E3DVector3F endPos, E3DTriangle triangle)
          Will probably be moved.
static double getSegmentTriangleDistance(E3DVector3F pos, E3DTriangle triangle)
          Return the distance between a segment and triangle.
 void registerCollisionDetector(java.lang.String detectorName, E3DCollisionDetector detector)
          If you want to create your own collisiondetector, this is where you register it.
 
Methods inherited from class espresso3d.engine.base.E3DEngineItem
getEngine, setEngine
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOURCE_COLLISIONTYPE_SEGMENT

public static final java.lang.String SOURCE_COLLISIONTYPE_SEGMENT
Basic line segment collision detection for the source object

See Also:
Constant Field Values

SOURCE_COLLISIONTYPE_AABOUNDINGBOX

public static final java.lang.String SOURCE_COLLISIONTYPE_AABOUNDINGBOX
TODO: Not Implemented Axially Aligned Bounding Box collision for the source object

See Also:
Constant Field Values

SOURCE_COLLISIONTYPE_BOUNDINGSPHERE_FAST

public static final java.lang.String SOURCE_COLLISIONTYPE_BOUNDINGSPHERE_FAST
Bounding sphere collision for the source object. This is a fast, but not quite as accurate version. It only detects collisions if the object runs head on into another triangle. It doesn't detect if there are triangles to the left or right side of the forward vec that may be within the bounding sphere

See Also:
Constant Field Values

SOURCE_COLLISIONTYPE_BOUNDINGSPHERE_ACCURATE

public static final java.lang.String SOURCE_COLLISIONTYPE_BOUNDINGSPHERE_ACCURATE
Bounding sphere collision for the source object. This is the completely accurate, but slower bounding sphere. it will detect any collision withing the bounding sphere

See Also:
Constant Field Values

SOURCE_COLLISIONTYPE_TRIANGLES

public static final java.lang.String SOURCE_COLLISIONTYPE_TRIANGLES
Triangle collision detection for the source object to check if triangle in the source model collides with the dest object Can be -very- slow if the source has lots of triangles in its model

See Also:
Constant Field Values
Constructor Detail

E3DCollisionDetect

public E3DCollisionDetect(E3DEngine engine)
Method Detail

checkCollision

public E3DCollision checkCollision(java.lang.String sourceDetectorName,
                                   boolean useBoundingObjectsIfPossible,
                                   boolean notifyAllObjectsCollided,
                                   E3DCollisionDetectableObject sourceObject,
                                   E3DVector3F startPos,
                                   E3DVector3F endPos,
                                   E3DWorld world)
Will perform a collision check to see if the sourceActor collides with anything else in the world between startPos and endPos.

Parameters:
sourceDetectorName - Name of the source collisionType to use for the sourceActor when checking for collisions. Can be a built in (check static SOURCE_COLLISIONTYPE_* types), or the name of one that has been created and registered into the collision detector
useBoundingObjectsIfPossible - If true, when checking collisions against other actors, it will use their bounding object (if possible) instead of checking against every triangle in the actor. World geometry is still checked per-trianle. Recommended to be set to true for speed.
notifyAllObjectsCollided - If true, all objects that are collided with will receive an onCollision notification. However, only the closest collision will be returned. This should be true if you have an object that could potential "plow through" multiple objects (ie: its collision handler doesn't stop it when it collides into another object)
sourceObject - This is the object to see if it hits anything
startPos - The starting position of the sourceActor
endPos - The end pos of the vector that we use to see if sourceActor hits anything.
world - The world to check for the collision in
Returns:
Returns a E3DCollision object for the nearest collision if a collision was found, otherwise null

checkForPortalCollisionsAndGetSectorChange

public E3DSector checkForPortalCollisionsAndGetSectorChange(E3DVector3F startPos,
                                                            E3DVector3F endPos,
                                                            E3DSector sector)
This method is used mainly by the engine to see when it translates objects, if they collide with a portal. This is necessary for the engine to keep track of the sector objects are in. This always uses a line segment (vs triangle) collision detector.

Parameters:
startPos - The starting position of the object we are checking against portals
endPos - The ending position of the object we are checking against portals
sector - The sector the object is currently in
Returns:
Returns the sector the object should be placed in or null if there is no portal collision

registerCollisionDetector

public void registerCollisionDetector(java.lang.String detectorName,
                                      E3DCollisionDetector detector)
If you want to create your own collisiondetector, this is where you register it. You give it a unique name and a detector that you have written to handle the detection between various objects, and then when you call checkCollision call it with this detectorName. Normally, the provided collision detectors should be sufficient.

Parameters:
detectorName -
detector -

getCollisionDetectors

public java.util.HashMap getCollisionDetectors()
Returns:
Returns thecollisionDetectors currently registered

getSegmentTriangleDistance

public static double getSegmentTriangleDistance(E3DVector3F pos,
                                                E3DTriangle triangle)
Return the distance between a segment and triangle. This will probably be moved to be part of E3DTriangle or E3DLine


checkFastCollisionWithPlane

public static boolean checkFastCollisionWithPlane(E3DVector3F startPos,
                                                  E3DVector3F endPos,
                                                  E3DTriangle triangle)
Will probably be moved. Checks if startPos and endPos are on opposite sides of the plane created by triangle

Parameters:
startPos -
endPos -
triangle -
Returns:
returns true if they are opposite, othewise false

getIntersectionPoint

public static E3DVector3F getIntersectionPoint(E3DVector3F startPos,
                                               E3DVector3F endPos,
                                               E3DTriangle triangle)
Will probably be moved. Gets the intersection point of the line segment formed between startPos and endPos and the triangle

Parameters:
startPos -
endPos -
triangle -
Returns:
returns intersection point

checkSegmentTriangleCollision

public static E3DVector3F checkSegmentTriangleCollision(E3DVector3F startPos,
                                                        E3DVector3F endPos,
                                                        E3DTriangle triangle)
Will probably be moved. Checks for full fledged collision between the line segment formed between startPos and endPos and the triangle

Returns:
Returns the intersection point vector if there is a collision between the line segment (startPos, endPos) and triangle. Otherwise, returns null;

checkTriangleTriangleCollision

public static E3DVector3F checkTriangleTriangleCollision(E3DTriangle colliderTriangle,
                                                         E3DVector3F startPos,
                                                         E3DVector3F endPos,
                                                         E3DTriangle collideeTriangle)
Will probably be moved. Checks for a collision between two triangles by checking to see if any of vertices when moved along a line segment of length endPos - startPos collide with the collideeTriangle. TODO: This should also check the edges of the colliderTriangle...

Parameters:
colliderTriangle -
startPos -
endPos -
collideeTriangle -
Returns: