org.xith3d.physics.collision
Class CollisionEngine

java.lang.Object
  extended by org.xith3d.physics.collision.CollisionEngine
All Implemented Interfaces:
org.jagatoo.datatypes.Enableable, Updatable

public abstract class CollisionEngine
extends java.lang.Object
implements Updatable, org.jagatoo.datatypes.Enableable

A Collision Engine. The base implementation is the JOODE one, but any engine can be implemented... even your own one ! Put your imagination at work !

A Collision Engine is in charge of : creating every CollideableGroup or Collideable,

Many thanks to the ODE Team for design ideas..


Nested Class Summary
 class CollisionEngine.NotImplementedYetError
          Error thrown when the user tries to create a Collideable which type hasn't been implemented in the engine he uses.
 
Constructor Summary
CollisionEngine()
           
 
Method Summary
 void addCollisionCheck(CollisionCheck cc)
          Adds a CollisionCheck to the list, that is handled each frame.
 java.util.ArrayList<Collision> checkCollisions(Collideable c1, Collideable c2, boolean ignoreStatic)
          Checks two Collideables (or collideable groups) for collision (n x m collision check)
abstract  int checkCollisions(Collideable c1, Collideable c2, boolean ignoreStatic, java.util.ArrayList<Collision> collisions)
          Checks two Collideables (or collideable groups) for collision (n x m collision check)
abstract  int checkCollisions(Collideable c1, Collideable c2, boolean ignoreStatic, CollisionListener listener)
          Checks two Collideables (or collideable groups) for collision (n x m collision check) The listener is notified of any collision.
 java.util.ArrayList<Collision> checkCollisions(CollideableGroup group, boolean ignoreStatic)
          Does an n x n collision check for all Collideables in the Group.
abstract  int checkCollisions(CollideableGroup group, boolean ignoreStatic, java.util.ArrayList<Collision> collisions)
          Does an n x n collision check for all Collideables in the Group.
abstract  int checkCollisions(CollideableGroup group, boolean ignoreStatic, CollisionListener listener)
          Does an n x n collision check for all Collideables in the Group.
 CollisionListener getDefaultCollisionListener()
           
abstract  java.util.List<CollideableGroupType> getGroupTypes()
           
abstract  CollisionEngineVendorInformation getVendorInformation()
           
 boolean isEnabled()
           
 BoxCollideable newBox(org.openmali.spatial.bodies.Box box)
          Creates a new box collideable
 BoxCollideable newBox(float xSize, float ySize, float zSize)
          Creates a new box collideable
 BoxCollideable newBox(Shape3D shape)
          Creates a new box collideable
 BoxCollideable newBox(org.openmali.vecmath2.Tuple3f size)
          Creates a new box collideable
 BoxCollideable newBox(org.openmali.spatial.VertexContainer vertexContainer)
          Creates a new box collideable
 CollideableGroup newBoxGroup(GroupNode group)
          Creates a new CollideableGroup filled with Boxes derived from the contained Shape3Ds.
 CollideableGroup newBoxOutline(org.openmali.spatial.bodies.Box box)
          Creates a new box collideable
 CollideableGroup newBoxOutline(Shape3D shape)
          Creates a new "box outline" collideable
 CollideableGroup newBoxOutline(org.openmali.spatial.VertexContainer vertexContainer)
          Creates a new "box outline" collideable
 CapsuleCollideable newCapsule(float radius, float length)
          Creates a new capsule collideable
 CylinderCollideable newCylinder(float radius, float length)
          Creates a new cylinder collideable
abstract  CollideableGroup newGroup()
          Creates a new group of the "best" available type (by best we mean the best compromise between speed and memory, the one which would be fine for most situations).
abstract  CollideableGroup newGroup(java.lang.String type)
          Creates a new group of a specified type.
 PlaneCollideable newPlane(float a, float b, float c, float d)
          Creates a new plane collideable
 PlaneCollideable newPlane(org.openmali.spatial.bodies.Plane plane)
          Creates a new plane collideable
 PlaneCollideable newPlane(org.openmali.vecmath2.Vector3f normal, float d)
          Creates a new plane collideable
 PlaneCollideable newPlane(org.openmali.vecmath2.Vector3f normal, org.openmali.vecmath2.Point3f point)
          Creates a new plane collideable
 RayCollideable newRay(float originX, float originY, float originZ, float directionX, float directionY, float directionZ)
          Creates a new ray collideable
 RayCollideable newRay(org.openmali.vecmath2.Ray3f ray)
          Creates a new ray collideable
 RayCollideable newRay(Shape3D shape)
          Creates a new ray collideable
 RayCollideable newRay(org.openmali.vecmath2.Tuple3f origin, org.openmali.vecmath2.Tuple3f direction)
          Creates a new ray collideable
 RayCollideable newRay(org.openmali.spatial.VertexContainer vertexContainer)
          Creates a new ray collideable
 SphereCollideable newSphere(float radius)
          Creates a new sphere collideable
 SphereCollideable newSphere(Shape3D shape)
          Creates a new sphere collideable
 SphereCollideable newSphere(org.openmali.spatial.bodies.Sphere sphere)
          Creates a new sphere collideable
 SphereCollideable newSphere(org.openmali.spatial.VertexContainer vertexContainer)
          Creates a new sphere collideable
 CollideableGroup newSphereGroup(GroupNode group)
          Creates a new CollideableGroup filled with Spheres derived from the contained Shape3Ds.
 TriMeshCollideable newTriMesh(Geometry geometry)
          Creates a new triangle mesh collideable
 TriMeshCollideable newTriMesh(Shape3D shape)
          Creates a new triangle mesh collideable
 TriMeshCollideable newTriMesh(org.openmali.spatial.TriangleContainer triangleContainer)
          Creates a new triangle mesh collideable
 TriMeshCollideable newTriMesh(org.openmali.vecmath2.Tuple3f[] vertices)
          Creates a new triangle mesh collideable
 TriMeshCollideable newTriMesh(org.openmali.vecmath2.Tuple3f[] vertices, int[] indices)
          Creates a new triangle mesh collideable
 TriMeshCollideable newTriMesh(org.openmali.spatial.VertexContainer vertexContainer)
          Creates a new triangle mesh collideable
 TriMeshCollideable newTriMesh(org.openmali.spatial.VertexContainer vertexContainer, org.openmali.spatial.IndexContainer indexContainer)
          Creates a new triangle mesh collideable
 CollideableGroup newTriMeshGroup(GroupNode group)
          Creates a new CollideableGroup filled with TriMeshes derived from the contained Shape3Ds.
 void removeCollisionCheck(CollisionCheck cc)
          Removes a CollisionCheck from the list, that is handled each frame.
 void setDefaultCollisionListener(CollisionListener cl)
          Sets the CollisionListener, that is being used, if a CollisionCheck doesn't define an own CollisionListener.
 void setEnabled(boolean enabled)
          Sets this CollisionEngine enabled/disabled.
 void update(long gameTime, long frameTime, UpdatingThread.TimingMode timingMode)
          Updates this Updatable object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollisionEngine

public CollisionEngine()
Method Detail

getGroupTypes

public abstract java.util.List<CollideableGroupType> getGroupTypes()
Returns:
a list of all group types

newGroup

public abstract CollideableGroup newGroup()
Creates a new group of the "best" available type (by best we mean the best compromise between speed and memory, the one which would be fine for most situations). To create a group of a specific type :

Returns:
The newly created Group
See Also:
To know all implemented group types, getGroupTypes()

newGroup

public abstract CollideableGroup newGroup(java.lang.String type)
Creates a new group of a specified type.

Parameters:
type -
Returns:
The newly created Group
See Also:
getGroupTypes()

newRay

public RayCollideable newRay(float originX,
                             float originY,
                             float originZ,
                             float directionX,
                             float directionY,
                             float directionZ)
Creates a new ray collideable

Parameters:
originX -
originY -
originZ -
directionX -
directionY -
directionZ -
Returns:
a ray collideable

newRay

public final RayCollideable newRay(org.openmali.vecmath2.Tuple3f origin,
                                   org.openmali.vecmath2.Tuple3f direction)
Creates a new ray collideable

Parameters:
origin -
direction -
Returns:
a ray collideable

newRay

public final RayCollideable newRay(org.openmali.vecmath2.Ray3f ray)
Creates a new ray collideable

Parameters:
ray - the template ray to create the RayCollideable from
Returns:
a ray collideable

newRay

public final RayCollideable newRay(org.openmali.spatial.VertexContainer vertexContainer)
Creates a new ray collideable

Parameters:
vertexContainer - the VertexContainer to take the vertex coordinates from
Returns:
a ray collideable

newRay

public final RayCollideable newRay(Shape3D shape)
Creates a new ray collideable

Parameters:
shape - the tempalte shape
Returns:
a ray collideable

newSphere

public SphereCollideable newSphere(float radius)
Creates a new sphere collideable

Parameters:
radius - The radius of the sphere
Returns:
a sphere collideable

newSphere

public final SphereCollideable newSphere(org.openmali.spatial.bodies.Sphere sphere)
Creates a new sphere collideable

Parameters:
sphere - the template sphere to create the SphereCollideable from
Returns:
a sphere collideable

newSphere

public final SphereCollideable newSphere(org.openmali.spatial.VertexContainer vertexContainer)
Creates a new sphere collideable

Parameters:
vertexContainer - the VertexContainer to take the vertex coordinates from
Returns:
a sphere collideable

newSphere

public final SphereCollideable newSphere(Shape3D shape)
Creates a new sphere collideable

Parameters:
shape - the tempalte shape
Returns:
a sphere collideable

newBox

public final BoxCollideable newBox(org.openmali.vecmath2.Tuple3f size)
Creates a new box collideable

Parameters:
size - The size of the box
Returns:
a box collideable

newBox

public BoxCollideable newBox(float xSize,
                             float ySize,
                             float zSize)
Creates a new box collideable

Parameters:
xSize - The size of the box along the X axis
ySize - The size of the box along the Y axis
zSize - The size of the box along the Z axis
Returns:
a box collideable

newBox

public final BoxCollideable newBox(org.openmali.spatial.bodies.Box box)
Creates a new box collideable

Parameters:
box - the template box to create the BoxCollideable from
Returns:
a box collideable

newBox

public final BoxCollideable newBox(org.openmali.spatial.VertexContainer vertexContainer)
Creates a new box collideable

Parameters:
vertexContainer - the VertexContainer to take the vertex coordinates from
Returns:
a box collideable

newBox

public final BoxCollideable newBox(Shape3D shape)
Creates a new box collideable

Parameters:
shape - the template shape
Returns:
a box collideable

newBoxOutline

public final CollideableGroup newBoxOutline(org.openmali.spatial.bodies.Box box)
Creates a new box collideable

Parameters:
box - the template box to create the BoxCollideable from
Returns:
a box collideable

newBoxOutline

public final CollideableGroup newBoxOutline(org.openmali.spatial.VertexContainer vertexContainer)
Creates a new "box outline" collideable

Parameters:
vertexContainer - the VertexContainer to take the vertex coordinates from
Returns:
the created CollideableGroup

newBoxOutline

public final CollideableGroup newBoxOutline(Shape3D shape)
Creates a new "box outline" collideable

Parameters:
shape - the template shape
Returns:
the created CollideableGroup

newCapsule

public CapsuleCollideable newCapsule(float radius,
                                     float length)
Creates a new capsule collideable

Parameters:
radius - The radius of the capsule
length - The length of the capsule
Returns:
a capsule collideable

newCylinder

public CylinderCollideable newCylinder(float radius,
                                       float length)
Creates a new cylinder collideable

Parameters:
radius - The radius of the capsule
length - The length of the capsule
Returns:
a cylinder collideable

newPlane

public PlaneCollideable newPlane(org.openmali.vecmath2.Vector3f normal,
                                 org.openmali.vecmath2.Point3f point)
Creates a new plane collideable

Parameters:
normal - The normal of the plane to be created
point - A point by which this plane is defined
Returns:
a plane collideable

newPlane

public PlaneCollideable newPlane(org.openmali.vecmath2.Vector3f normal,
                                 float d)
Creates a new plane collideable

Parameters:
normal - The normal of the plane to be created
d - The d-parameter by which this plane is defined
Returns:
a plane collideable

newPlane

public PlaneCollideable newPlane(float a,
                                 float b,
                                 float c,
                                 float d)
Creates a new plane collideable

Parameters:
a - the x-component of the plane's normal
b - the y-component of the plane's normal
c - the z-component of the plane's normal
d - The d-parameter by which this plane is defined
Returns:
a plane collideable

newPlane

public final PlaneCollideable newPlane(org.openmali.spatial.bodies.Plane plane)
Creates a new plane collideable

Parameters:
plane - the Plane, the new PlaneCollideable is defained off.
Returns:
a plane collideable

newTriMesh

public TriMeshCollideable newTriMesh(org.openmali.spatial.VertexContainer vertexContainer,
                                     org.openmali.spatial.IndexContainer indexContainer)
Creates a new triangle mesh collideable

Parameters:
vertexContainer - A vertex container of a Triangle-based mesh (All Geometry types implements that interface)
indexContainer - An index container of a Triangle-based mesh (Indexed Geometry types implements that interface) If your geometry is not indexed, see the newTriMesh(VertexContainer) method.
Returns:
a triangle mesh collideable

newTriMesh

public final TriMeshCollideable newTriMesh(org.openmali.spatial.VertexContainer vertexContainer)
Creates a new triangle mesh collideable

Parameters:
vertexContainer - A vertex container of a Triangle-based mesh (All Geometry types implements that interface)
Returns:
a triangle mesh collideable

newTriMesh

public TriMeshCollideable newTriMesh(org.openmali.spatial.TriangleContainer triangleContainer)
Creates a new triangle mesh collideable

Parameters:
triangleContainer - A vertex container of a Triangle-based mesh (All Geometry types implements that interface)
Returns:
a triangle mesh collideable

newTriMesh

public final TriMeshCollideable newTriMesh(Geometry geometry)
Creates a new triangle mesh collideable

Parameters:
geometry - A Xith3D geometry
Returns:
a triangle mesh collideable

newTriMesh

public final TriMeshCollideable newTriMesh(Shape3D shape)
Creates a new triangle mesh collideable

Parameters:
shape - A Xith3D Shape3D
Returns:
a triangle mesh collideable

newTriMesh

public TriMeshCollideable newTriMesh(org.openmali.vecmath2.Tuple3f[] vertices,
                                     int[] indices)
Creates a new triangle mesh collideable

Parameters:
vertices - The vertex data which is indexed
indices - The vertices to chose from the vertex data
Returns:
a triangle mesh collideable

newTriMesh

public final TriMeshCollideable newTriMesh(org.openmali.vecmath2.Tuple3f[] vertices)
Creates a new triangle mesh collideable

Parameters:
vertices - The vertices of the triangle mesh (three vertices = one triangle)
Returns:
a triangle mesh collideable

newTriMeshGroup

public final CollideableGroup newTriMeshGroup(GroupNode group)
Creates a new CollideableGroup filled with TriMeshes derived from the contained Shape3Ds.

Parameters:
group - A Xith3D GroupNode
Returns:
a collideable group

newSphereGroup

public final CollideableGroup newSphereGroup(GroupNode group)
Creates a new CollideableGroup filled with Spheres derived from the contained Shape3Ds.

Parameters:
group - A Xith3D GroupNode
Returns:
a collideable group

newBoxGroup

public final CollideableGroup newBoxGroup(GroupNode group)
Creates a new CollideableGroup filled with Boxes derived from the contained Shape3Ds.

Parameters:
group - A Xith3D GroupNode
Returns:
a collideable group

checkCollisions

public abstract int checkCollisions(Collideable c1,
                                    Collideable c2,
                                    boolean ignoreStatic,
                                    java.util.ArrayList<Collision> collisions)
Checks two Collideables (or collideable groups) for collision (n x m collision check)

Parameters:
c1 - A Collideable or CollideableGroup
c2 - A Collideable or CollideableGroup
ignoreStatic -
collisions - the list to write collisions to
Returns:
the number of detected collisions

checkCollisions

public final java.util.ArrayList<Collision> checkCollisions(Collideable c1,
                                                            Collideable c2,
                                                            boolean ignoreStatic)
Checks two Collideables (or collideable groups) for collision (n x m collision check)

Parameters:
c1 - A Collideable or CollideableGroup
c2 - A Collideable or CollideableGroup
ignoreStatic -
Returns:
An ArrayList containing all the collision, or an empty list if there's none.

checkCollisions

public abstract int checkCollisions(Collideable c1,
                                    Collideable c2,
                                    boolean ignoreStatic,
                                    CollisionListener listener)
Checks two Collideables (or collideable groups) for collision (n x m collision check) The listener is notified of any collision.

Parameters:
c1 - A Collideable or CollideableGroup
c2 - A Collideable or CollideableGroup
ignoreStatic -
listener - The CollisionListener to be notified, when a collision is detected.
Returns:
the number of detected collisions

checkCollisions

public abstract int checkCollisions(CollideableGroup group,
                                    boolean ignoreStatic,
                                    java.util.ArrayList<Collision> collisions)
Does an n x n collision check for all Collideables in the Group. If there's any collision it's put in the returned array list

Parameters:
group -
ignoreStatic -
collisions - the list to write collisions to
Returns:
the number of detected collisions

checkCollisions

public final java.util.ArrayList<Collision> checkCollisions(CollideableGroup group,
                                                            boolean ignoreStatic)
Does an n x n collision check for all Collideables in the Group. If there's any collision it's put in the returned array list

Parameters:
group -
ignoreStatic -
Returns:
a list of collisions

checkCollisions

public abstract int checkCollisions(CollideableGroup group,
                                    boolean ignoreStatic,
                                    CollisionListener listener)
Does an n x n collision check for all Collideables in the Group. The listener is notified of any collision.

Parameters:
group -
ignoreStatic -
listener -
Returns:
the number of detected collisions

getVendorInformation

public abstract CollisionEngineVendorInformation getVendorInformation()
Returns:
the CollisionEngine's vendor information

addCollisionCheck

public final void addCollisionCheck(CollisionCheck cc)
Adds a CollisionCheck to the list, that is handled each frame.

Parameters:
cc -

removeCollisionCheck

public final void removeCollisionCheck(CollisionCheck cc)
Removes a CollisionCheck from the list, that is handled each frame.

Parameters:
cc -

setDefaultCollisionListener

public final void setDefaultCollisionListener(CollisionListener cl)
Sets the CollisionListener, that is being used, if a CollisionCheck doesn't define an own CollisionListener.

Parameters:
cl -

getDefaultCollisionListener

public final CollisionListener getDefaultCollisionListener()
Returns:
the CollisionListener, that is being used, if a CollisionCheck doesn't define an own CollisionListener.

setEnabled

public final void setEnabled(boolean enabled)
Sets this CollisionEngine enabled/disabled.
If not enabled, the update() method will do nothing.

Specified by:
setEnabled in interface org.jagatoo.datatypes.Enableable
Parameters:
enabled -

isEnabled

public final boolean isEnabled()
Specified by:
isEnabled in interface org.jagatoo.datatypes.Enableable
Returns:
if this CollisionEngine is enabled.
If not enabled, the update() method will do nothing.

update

public void update(long gameTime,
                   long frameTime,
                   UpdatingThread.TimingMode timingMode)
Updates this Updatable object.

Specified by:
update in interface Updatable
Parameters:
gameTime - the gameTime in Milliseconds
frameTime - the frameTime in Milliseconds (needed time for the last frame)
timingMode - the TimingMode to use for frameTime.