CollisionAlgorithm Class Reference

The base class for a Rigid Object vs. Rigid Object batched collision detection algorithm. More...

#include <rimCollisionAlgorithm.h>

Inheritance diagram for CollisionAlgorithm:

Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual ~CollisionAlgorithm ()
 Destroy an algorithm along with all cached pairs to test for collisions.
CollisionAlgorithmoperator= (const CollisionAlgorithm &algorithm)
 Assign the contents of one algorithm to another.
virtual void testForCollisions (CollisionResultSet &result)=0
 Iterate through all cached pairs and add all colliding pairs to the result set.
virtual bool testForCollisions (const CollisionPair &pair, CollisionManifold *manifold)=0
 Test for collisions between a pair of objects/shapes.
void addPair (const CollisionPair &newPair)
 Add a new pair of objects and shapes to later test for collisions.
void clearPairs ()
 Clear all possibly colliding pairs object objects from the algorithm.
int getNumberOfPairs () const
 Get the number of potentially colliding pairs of objects that the algorithm will test.
virtual CollisionAlgorithmclone () const =0
 Polymorphically create a copy of this object on the heap and return its address.
virtual const CollisionShapeTypegetShapeType1 () const =0
 Get a reference to the type of the first shape type this algorithm tests.
virtual const CollisionShapeTypegetShapeType2 () const =0
 Get a reference to the type of the second shape type this algorithm tests.
bool getShapeTypesAreReversed () const
 Get whether or not the algorithm interprets the received shapes as reversed in type.
void setShapeTypesAreReversed (bool newShapeTypesAreReversed)
 Set whether or not the algorithm interprets the received shapes as reversed in type.

Protected Member Functions

 CollisionAlgorithm ()
 Create a collision algorithm with the default pair array size.
 CollisionAlgorithm (int newPairArraySize)
 Create a collision algorithm with the specified pair array size.
 CollisionAlgorithm (const CollisionAlgorithm &algorithm)
 Copy a collision algorithm and all pairs contained in it.

Protected Attributes

CollisionPairpairs
 An array of rigid objects which are being tested for collisions.
int pairArraySize
 The capacity of the algorithm's batch pair array.
int numPairs
 The number of pairs that have been added to the algorithm's batch pair array.
bool shapeTypesAreReversed
 Whether or not the algorithm interprets the received shapes as reversed in type.

Static Private Attributes

static const int DEFAULT_PAIR_ARRAY_SIZE = 128
 The default size of the pair array.


Detailed Description

The base class for a Rigid Object vs. Rigid Object batched collision detection algorithm.

The purpose of this class is to provide all of the boiler-plate code for a batch processing collision detection algorithm. The reason that a batched system is used is to reduce the number of virtual function calls and increase cache coherency of collision detection. In order to add a pair of objects to test for collisions to an algorithm, the addPair() method is called, which caches the pair. When all pairs have been added to the algorithm, the user calls the virtual method testForCollisions() once, which processes all of the cached pairs and test for collisions. This is much more efficient than the other method of immediately testing for collisions between shapes, because the collision detection logic function (which must be virtual) is only called once versus many times. Additionally, the addPair method will likely be inlined, which means that the function call overhead is O(1) for N pairs.

In practice, a user would derive from this class and then implement the testForCollisions() method. In that method, the implementor would iterate through each pair in the protected pair array, testing for collisions between the shapes.


Constructor & Destructor Documentation

virtual CollisionAlgorithm::~CollisionAlgorithm (  )  [inline, virtual]

Destroy an algorithm along with all cached pairs to test for collisions.

CollisionAlgorithm::CollisionAlgorithm (  )  [inline, protected]

Create a collision algorithm with the default pair array size.

CollisionAlgorithm::CollisionAlgorithm ( int  newPairArraySize  )  [inline, protected]

Create a collision algorithm with the specified pair array size.

CollisionAlgorithm::CollisionAlgorithm ( const CollisionAlgorithm algorithm  )  [inline, protected]

Copy a collision algorithm and all pairs contained in it.


Member Function Documentation

CollisionAlgorithm& CollisionAlgorithm::operator= ( const CollisionAlgorithm algorithm  )  [inline]

Assign the contents of one algorithm to another.

virtual void CollisionAlgorithm::testForCollisions ( CollisionResultSet result  )  [pure virtual]

Iterate through all cached pairs and add all colliding pairs to the result set.

Implemented in CollisionAlgorithmBoxVsBox, CollisionAlgorithmCapsuleVsCapsule, CollisionAlgorithmContainerVsContainer, CollisionAlgorithmContainerVsShape, CollisionAlgorithmSphereVsBox, CollisionAlgorithmSphereVsCapsule, CollisionAlgorithmSphereVsCylinder, and CollisionAlgorithmSphereVsSphere.

virtual bool CollisionAlgorithm::testForCollisions ( const CollisionPair pair,
CollisionManifold manifold 
) [pure virtual]

Test for collisions between a pair of objects/shapes.

If the manifold parameter is equal to NULL, then no contact information is stored. Otherwise, the contact points of the colliding shapes are added to the object pointed to by the manifold parameter if there are any. The method returns a boolean value indicating whether or not the shapes are colliding.

Parameters:
pair - An object containing pointers to the objects/shapes to test for collisions
Returns:
whether or not the shapes are colliding.

Implemented in CollisionAlgorithmBoxVsBox, CollisionAlgorithmCapsuleVsCapsule, CollisionAlgorithmContainerVsContainer, CollisionAlgorithmContainerVsShape, CollisionAlgorithmSphereVsBox, CollisionAlgorithmSphereVsCapsule, CollisionAlgorithmSphereVsCylinder, and CollisionAlgorithmSphereVsSphere.

void CollisionAlgorithm::addPair ( const CollisionPair newPair  )  [inline]

Add a new pair of objects and shapes to later test for collisions.

void CollisionAlgorithm::clearPairs (  )  [inline]

Clear all possibly colliding pairs object objects from the algorithm.

int CollisionAlgorithm::getNumberOfPairs (  )  const [inline]

Get the number of potentially colliding pairs of objects that the algorithm will test.

virtual CollisionAlgorithm* CollisionAlgorithm::clone (  )  const [pure virtual]

Polymorphically create a copy of this object on the heap and return its address.

Implemented in CollisionAlgorithmBoxVsBox, CollisionAlgorithmCapsuleVsCapsule, CollisionAlgorithmContainerVsContainer, CollisionAlgorithmContainerVsShape, CollisionAlgorithmSphereVsBox, CollisionAlgorithmSphereVsCapsule, CollisionAlgorithmSphereVsCylinder, and CollisionAlgorithmSphereVsSphere.

virtual const CollisionShapeType& CollisionAlgorithm::getShapeType1 (  )  const [pure virtual]

Get a reference to the type of the first shape type this algorithm tests.

Implemented in CollisionAlgorithmBoxVsBox, CollisionAlgorithmCapsuleVsCapsule, CollisionAlgorithmContainerVsContainer, CollisionAlgorithmContainerVsShape, CollisionAlgorithmSphereVsBox, CollisionAlgorithmSphereVsCapsule, CollisionAlgorithmSphereVsCylinder, and CollisionAlgorithmSphereVsSphere.

virtual const CollisionShapeType& CollisionAlgorithm::getShapeType2 (  )  const [pure virtual]

Get a reference to the type of the second shape type this algorithm tests.

Implemented in CollisionAlgorithmBoxVsBox, CollisionAlgorithmCapsuleVsCapsule, CollisionAlgorithmContainerVsContainer, CollisionAlgorithmContainerVsShape, CollisionAlgorithmSphereVsBox, CollisionAlgorithmSphereVsCapsule, CollisionAlgorithmSphereVsCylinder, and CollisionAlgorithmSphereVsSphere.

bool CollisionAlgorithm::getShapeTypesAreReversed (  )  const [inline]

Get whether or not the algorithm interprets the received shapes as reversed in type.

The algorithm has two shape types that it tests for collisions between. If this function returns FALSE, then whenever the algorithm receives a pair of shapes, it will interpret them as being of <type 1>, <type 2> in that order. If the function returns TRUE, then the algorithm interprets them as being in reverse order (<type 2>, <type 1>), and reverses how they are placed in the shape and object arrays. The implementor of a collision algorithm does not have to worry about this. Shapes from the shapes1 array will always be of <type 1> and shapes from the shapes2 array will always be of <type 2>.

void CollisionAlgorithm::setShapeTypesAreReversed ( bool  newShapeTypesAreReversed  )  [inline]

Set whether or not the algorithm interprets the received shapes as reversed in type.

The algorithm has two shape types that it tests for collisions between. If this function's parameter is FALSE, then whenever the algorithm receives a pair of shapes, it will interpret them as being of <type 1>, <type 2> in that order. If the function's parameter is TRUE, then the algorithm interprets them as being in reverse order (<type 2>, <type 1>), and reverses how they are placed in the shape and object arrays. The implementor of a collision algorithm does not have to worry about this. Shapes from the shapes1 array will always be of <type 1> and shapes from the shapes2 array will always be of <type 2>.


Member Data Documentation

CollisionPair* CollisionAlgorithm::pairs [protected]

An array of rigid objects which are being tested for collisions.

Each element in this array is a rigid object which has the shape at the same index in the shapes1 array. Each object is being tested against the object with the same index in the rigidObjects2 array.

int CollisionAlgorithm::pairArraySize [protected]

The capacity of the algorithm's batch pair array.

int CollisionAlgorithm::numPairs [protected]

The number of pairs that have been added to the algorithm's batch pair array.

bool CollisionAlgorithm::shapeTypesAreReversed [protected]

Whether or not the algorithm interprets the received shapes as reversed in type.

The algorithm has two shape types that it tests for collisions between. If this value is set to FALSE, then whenever the algorithm receives a pair of shapes, it will interpret them as being of <type 1>, <type 2> in that order. If the value is set to TRUE, then the algorithm interprets them as being in reverse order (<type 2>, <type 1>), and reverses how they are placed in the shape and object arrays. The implementor of a collision algorithm does not have to worry about this. Shapes from the shapes1 array will always be of <type 1> and shapes from the shapes2 array will always be of <type 2>.

const int CollisionAlgorithm::DEFAULT_PAIR_ARRAY_SIZE = 128 [static, private]

The default size of the pair array.


The documentation for this class was generated from the following file:
Generated on Tue Aug 26 00:03:17 2008 for Rim Physics by  doxygen 1.5.4