ReactPhysics3D
v0.10.2
C++ Physics engine library
|
This class implements a dynamic AABB tree that is used for broad-phase collision detection. More...
#include <include/reactphysics3d/collision/broadphase/DynamicAABBTree.h>
Public Member Functions | |
DynamicAABBTree (MemoryAllocator &allocator, decimal fatAABBInflatePercentage=decimal(0.0)) | |
Constructor. | |
~DynamicAABBTree () | |
Destructor. | |
int32 | addObject (const AABB &aabb, uint32 data) |
Add an object into the tree (where node data are two integers) | |
int32 | addObject (const AABB &aabb, void *data) |
Add an object into the tree (where node data is a pointer) | |
void | removeObject (int32 nodeID) |
Remove an object from the tree. | |
bool | updateObject (int32 nodeID, const AABB &newAABB, bool forceReinsert=false) |
Update the dynamic tree after an object has moved. | |
const AABB & | getFatAABB (int32 nodeID) const |
Return the fat AABB corresponding to a given node ID. | |
int32 | getNodeDataInt (int32 nodeID) const |
Return the pointer to the data array of a given leaf node of the tree. | |
void * | getNodeDataPointer (int32 nodeID) const |
Return the data pointer of a given leaf node of the tree. | |
void | reportAllShapesOverlappingWithShapes (const Array< int32 > &nodesToTest, uint32 startIndex, size_t endIndex, Array< Pair< int32, int32 > > &outOverlappingNodes) const |
Report all shapes overlapping with all the shapes in the map in parameter. | |
void | reportAllShapesOverlappingWithAABB (const AABB &aabb, Array< int > &overlappingNodes) const |
Report all shapes overlapping with the AABB given in parameter. | |
void | raycast (const Ray &ray, DynamicAABBTreeRaycastCallback &callback) const |
Ray casting method. | |
int | computeHeight () |
Compute the height of the tree. | |
const AABB & | getRootAABB () const |
Return the root AABB of the tree. | |
void | reset () |
Clear all the nodes and reset the tree. | |
This class implements a dynamic AABB tree that is used for broad-phase collision detection.
The following implementation is based on the one from Erin Catto in Box2D as described in the book "Introduction to Game Physics with Box2D" by Ian Parberry.
void DynamicAABBTree::reportAllShapesOverlappingWithShapes | ( | const Array< int32 > & | nodesToTest, |
uint32 | startIndex, | ||
size_t | endIndex, | ||
Array< Pair< int32, int32 > > & | outOverlappingNodes | ||
) | const |
Report all shapes overlapping with all the shapes in the map in parameter.
Take an array of shapes to be tested for broad-phase overlap and return an array of pair of overlapping shapes.
bool DynamicAABBTree::updateObject | ( | int32 | nodeID, |
const AABB & | newAABB, | ||
bool | forceReinsert = false |
||
) |
Update the dynamic tree after an object has moved.
If the new AABB of the object that has moved is still inside its fat AABB, then nothing is done.
Otherwise, the corresponding node is removed and reinserted into the tree. The method returns true if the object has been reinserted into the tree. If the "forceReInsert" parameter is true, we force the existing AABB to take the size of the "newAABB" parameter even if it is larger than "newAABB". This can be used to shrink the AABB in the tree for instance if the corresponding collision shape has been shrunk.