#include <rimCollisionAlgorithmDispatcher.h>
Public Member Functions | |
CollisionAlgorithmDispatcher () | |
Create a new collision algorithm dispatcher with the default hash table size. | |
CollisionAlgorithmDispatcher (Hash newHashTableSize) | |
Create a new collision algorithm dispatcher with the specified hash table size. | |
CollisionAlgorithmDispatcher (const CollisionAlgorithmDispatcher &dispatcher) | |
Copy a collision algorithm dispatcher, as well as its algorithms. | |
~CollisionAlgorithmDispatcher () | |
Destroy a collision algorithm dispatcher and all the algorithms it contains. | |
CollisionAlgorithmDispatcher & | operator= (const CollisionAlgorithmDispatcher &dispatcher) |
Copy the contents of one algorithm dispatcher to another. | |
void | testForCollisions (CollisionResultSet &result) const |
Test for collisions in each algorithm's batched pairs, adding to the collision result set. | |
bool | testForCollisions (const CollisionPair &pair, CollisionManifold *manifold) |
Test for collisions between two shape instances immediately. | |
void | addPair (const CollisionPair &pair) |
Add a new pair of objects and shapes to dispatch, cache, and later test for collisions. | |
void | addAlgorithm (const CollisionAlgorithm &newAlgorithm) |
Add a new algorithm to the dispatcher, also adding any previously unsupported shape types. | |
template<class AlgorithmType> | |
void | addAlgorithm () |
void | clearAlgorithms () |
Clear all algorithms from the dispatcher. | |
int | getNumberOfAlgorithms () const |
Get the number of algorithms that this dispatcher has. | |
Private Member Functions | |
void | addAlgorithm (CollisionAlgorithm *newAlgorithm, bool typesAreReversed) |
void | resize () |
Resize the hash table until the shape types hash perfectly. | |
Hash | getBucketIndex (Hash shapeTypeID1, Hash shapeTypeID2) const |
Hash | getHashCode (Hash shapeTypeID1, Hash shapeTypeID2) const |
Static Private Member Functions | |
static Hash | nextPrime (Hash n) |
Find the first prime larger than the parameter in the class's static array of primes. | |
Private Attributes | |
ArrayList< CollisionAlgorithm * > | algorithms |
An array list of all collision algorithms that this algorithm dispatcher supports. | |
CollisionAlgorithm ** | algorithmHashTable |
A 2D hash table array which contains all of the collision algorithms in the dispatcher. | |
Hash | hashTableSize |
The size of the collision algorithm hash table. | |
Static Private Attributes | |
static const int | DEFAULT_ALGORITHM_HASH_TABLE_SIZE = 11 |
A constant defining the number of prime constants that this class contains. | |
static const int | NUMBER_OF_PRIMES = 28 |
A constant defining the number of prime constants that this class contains. | |
static const Hash | PRIMES [NUMBER_OF_PRIMES] |
An array of optimal hash table primes (those far away from powers of 2). |
The dispatcher is a collection of collision detection algorithms and its purpose is to differentiate between incoming potentially colliding pairs of rigid objects and their shapes based on shape type and send the pairs to the correct collision detection algorithm. This example of double-dispatch is done using a 2 dimensional hash table where every shape type that the dispatcher supports must hash perfectly in that table, such that there are no collisions. One uses the dispatcher by adding algorithms to it that the user wants supported. Once this is done, the user is able to add possibly colliding pairs of objects to the dispatcher and they will correctly then be dispatched to the proper algorithm. Finally, when all pairs have been added, one calls the method testForCollisions(), where the dispatcher gathers up all colliding pairs and puts them in the user-supplied collision result set object. In addition, the user is also able to do an immediate collision detection test between to shapes, where of the collision is immediately known.
CollisionAlgorithmDispatcher::CollisionAlgorithmDispatcher | ( | ) | [inline] |
Create a new collision algorithm dispatcher with the default hash table size.
CollisionAlgorithmDispatcher::CollisionAlgorithmDispatcher | ( | Hash | newHashTableSize | ) | [inline] |
Create a new collision algorithm dispatcher with the specified hash table size.
RIM_PHYSICS_NAMESPACE_START CollisionAlgorithmDispatcher::CollisionAlgorithmDispatcher | ( | const CollisionAlgorithmDispatcher & | dispatcher | ) |
Copy a collision algorithm dispatcher, as well as its algorithms.
CollisionAlgorithmDispatcher::~CollisionAlgorithmDispatcher | ( | ) |
Destroy a collision algorithm dispatcher and all the algorithms it contains.
CollisionAlgorithmDispatcher & CollisionAlgorithmDispatcher::operator= | ( | const CollisionAlgorithmDispatcher & | dispatcher | ) |
Copy the contents of one algorithm dispatcher to another.
void CollisionAlgorithmDispatcher::testForCollisions | ( | CollisionResultSet & | result | ) | const [inline] |
Test for collisions in each algorithm's batched pairs, adding to the collision result set.
bool CollisionAlgorithmDispatcher::testForCollisions | ( | const CollisionPair & | pair, | |
CollisionManifold * | manifold | |||
) | [inline] |
Test for collisions between two shape instances immediately.
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.
shape1 | - the shape to test for collisions versus the second shape. | |
shape2 | - the shape to test for collisions versus the first shape. |
void CollisionAlgorithmDispatcher::addPair | ( | const CollisionPair & | pair | ) | [inline] |
Add a new pair of objects and shapes to dispatch, cache, and later test for collisions.
void CollisionAlgorithmDispatcher::addAlgorithm | ( | const CollisionAlgorithm & | newAlgorithm | ) | [inline] |
Add a new algorithm to the dispatcher, also adding any previously unsupported shape types.
void CollisionAlgorithmDispatcher::addAlgorithm | ( | ) | [inline] |
void CollisionAlgorithmDispatcher::clearAlgorithms | ( | ) |
Clear all algorithms from the dispatcher.
int CollisionAlgorithmDispatcher::getNumberOfAlgorithms | ( | ) | const [inline] |
Get the number of algorithms that this dispatcher has.
void CollisionAlgorithmDispatcher::addAlgorithm | ( | CollisionAlgorithm * | newAlgorithm, | |
bool | typesAreReversed | |||
) | [private] |
void CollisionAlgorithmDispatcher::resize | ( | ) | [private] |
Resize the hash table until the shape types hash perfectly.
Find the first prime larger than the parameter in the class's static array of primes.
Hash CollisionAlgorithmDispatcher::getBucketIndex | ( | Hash | shapeTypeID1, | |
Hash | shapeTypeID2 | |||
) | const [inline, private] |
Hash CollisionAlgorithmDispatcher::getHashCode | ( | Hash | shapeTypeID1, | |
Hash | shapeTypeID2 | |||
) | const [inline, private] |
An array list of all collision algorithms that this algorithm dispatcher supports.
A 2D hash table array which contains all of the collision algorithms in the dispatcher.
The size of the collision algorithm hash table.
const int CollisionAlgorithmDispatcher::DEFAULT_ALGORITHM_HASH_TABLE_SIZE = 11 [static, private] |
A constant defining the number of prime constants that this class contains.
const int CollisionAlgorithmDispatcher::NUMBER_OF_PRIMES = 28 [static, private] |
A constant defining the number of prime constants that this class contains.
const Hash CollisionAlgorithmDispatcher::PRIMES [static, private] |
Initial value:
{ 11, 23, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, }