net.phys2d.raw.collide
Class ColliderFactory

java.lang.Object
  extended bynet.phys2d.raw.collide.ColliderFactory

public class ColliderFactory
extends java.lang.Object

A collider factory to create colliders for arbitrary bodies, or actually their shapes. This was implemented to replace a visitor-pattern based implementation, that required many files to be edited to add a new shape. Furthermore this factory can handle singleton colliders if needed.


Constructor Summary
ColliderFactory()
           
 
Method Summary
 Collider createCollider(Body bodyA, Body bodyB)
          Create a collider for two bodies.
 Collider createColliderFor(Box shapeA, Shape shapeB)
          Creates a collider for a Box and a Shape.
 Collider createColliderFor(Circle shapeA, Shape shapeB)
          Creates a collider for a Circle and a Shape.
 Collider createColliderFor(Line shapeA, Shape shapeB)
          Creates a collider for a Line and a Shape.
 Collider createColliderFor(Polygon shapeA, Shape shapeB)
          Creates a collider for a ConvexPolygon and a Shape.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColliderFactory

public ColliderFactory()
Method Detail

createCollider

public Collider createCollider(Body bodyA,
                               Body bodyB)
                        throws ColliderUnavailableException
Create a collider for two bodies. The decision depends on the body's shapes.

Parameters:
bodyA - First body in the collision test
bodyB - Second body in the collision test
Returns:
A collider that can test wether the two bodies actually collide
Throws:
ColliderUnavailableException - This exception will be thrown if no suitable collider can be found.

createColliderFor

public Collider createColliderFor(Circle shapeA,
                                  Shape shapeB)
                           throws ColliderUnavailableException
Creates a collider for a Circle and a Shape. The choice is based on the kind of Shape that is provided

Parameters:
shapeA - The circle to provide a collider for
shapeB - The shape to provide a collider for
Returns:
a suitable collider
Throws:
ColliderUnavailableException - This exception will be thrown if no suitable collider can be found.

createColliderFor

public Collider createColliderFor(Box shapeA,
                                  Shape shapeB)
                           throws ColliderUnavailableException
Creates a collider for a Box and a Shape. The choice is based on the kind of Shape that is provided

Parameters:
shapeA - The box to provide a collider for
shapeB - The shape to provide a collider for
Returns:
a suitable collider
Throws:
ColliderUnavailableException - This exception will be thrown if no suitable collider can be found.

createColliderFor

public Collider createColliderFor(Line shapeA,
                                  Shape shapeB)
                           throws ColliderUnavailableException
Creates a collider for a Line and a Shape. The choice is based on the kind of Shape that is provided

Parameters:
shapeA - The line to provide a collider for
shapeB - The shape to provide a collider for
Returns:
a suitable collider
Throws:
ColliderUnavailableException - This exception will be thrown if no suitable collider can be found.

createColliderFor

public Collider createColliderFor(Polygon shapeA,
                                  Shape shapeB)
                           throws ColliderUnavailableException
Creates a collider for a ConvexPolygon and a Shape. The choice is based on the kind of Shape that is provided

Parameters:
shapeA - The convex polygon to provide a collider for
shapeB - The shape to provide a collider for
Returns:
a suitable collider
Throws:
ColliderUnavailableException - This exception will be thrown if no suitable collider can be found.