Jolt Physics
A multi core friendly Game Physics Engine
|
#include <QuadTree.h>
Classes | |
struct | AddState |
Temporary data structure to pass information between AddBodiesPrepare and AddBodiesFinalize/Abort. More... | |
struct | Tracking |
Data to track location of a Body in the tree. More... | |
struct | UpdateState |
Public Types | |
using | Allocator = FixedSizeFreeList< Node > |
Class that allocates tree nodes, can be shared between multiple trees. More... | |
using | TrackingVector = Array< Tracking > |
Public Member Functions | |
~QuadTree () | |
Destructor. More... | |
void | SetName (const char *inName) |
Name of the tree for debugging purposes. More... | |
const char * | GetName () const |
bool | HasBodies () const |
Check if there is anything in the tree. More... | |
bool | IsDirty () const |
Check if the tree needs an UpdatePrepare/Finalize() More... | |
bool | CanBeUpdated () const |
Check if this tree can get an UpdatePrepare/Finalize() or if it needs a DiscardOldTree() first. More... | |
void | Init (Allocator &inAllocator) |
Initialization. More... | |
void | DiscardOldTree () |
Will throw away the previous frame's nodes so that we can start building a new tree in the background. More... | |
AABox | GetBounds () const |
Get the bounding box for this tree. More... | |
void | UpdatePrepare (const BodyVector &inBodies, TrackingVector &ioTracking, UpdateState &outUpdateState, bool inFullRebuild) |
void | UpdateFinalize (const BodyVector &inBodies, const TrackingVector &inTracking, const UpdateState &inUpdateState) |
void | AddBodiesPrepare (const BodyVector &inBodies, TrackingVector &ioTracking, BodyID *ioBodyIDs, int inNumber, AddState &outState) |
void | AddBodiesFinalize (TrackingVector &ioTracking, int inNumberBodies, const AddState &inState) |
Finalize adding bodies to the quadtree, supply the same number of bodies as in AddBodiesPrepare. More... | |
void | AddBodiesAbort (TrackingVector &ioTracking, const AddState &inState) |
void | RemoveBodies (const BodyVector &inBodies, TrackingVector &ioTracking, const BodyID *ioBodyIDs, int inNumber) |
Remove inNumber bodies in ioBodyIDs from the quadtree. More... | |
void | NotifyBodiesAABBChanged (const BodyVector &inBodies, const TrackingVector &inTracking, const BodyID *ioBodyIDs, int inNumber) |
Call whenever the aabb of a body changes. More... | |
void | CastRay (const RayCast &inRay, RayCastBodyCollector &ioCollector, const ObjectLayerFilter &inObjectLayerFilter, const TrackingVector &inTracking) const |
Cast a ray and get the intersecting bodies in ioCollector. More... | |
void | CollideAABox (const AABox &inBox, CollideShapeBodyCollector &ioCollector, const ObjectLayerFilter &inObjectLayerFilter, const TrackingVector &inTracking) const |
Get bodies intersecting with inBox in ioCollector. More... | |
void | CollideSphere (Vec3Arg inCenter, float inRadius, CollideShapeBodyCollector &ioCollector, const ObjectLayerFilter &inObjectLayerFilter, const TrackingVector &inTracking) const |
Get bodies intersecting with a sphere in ioCollector. More... | |
void | CollidePoint (Vec3Arg inPoint, CollideShapeBodyCollector &ioCollector, const ObjectLayerFilter &inObjectLayerFilter, const TrackingVector &inTracking) const |
Get bodies intersecting with a point and any hits to ioCollector. More... | |
void | CollideOrientedBox (const OrientedBox &inBox, CollideShapeBodyCollector &ioCollector, const ObjectLayerFilter &inObjectLayerFilter, const TrackingVector &inTracking) const |
Get bodies intersecting with an oriented box and any hits to ioCollector. More... | |
void | CastAABox (const AABoxCast &inBox, CastShapeBodyCollector &ioCollector, const ObjectLayerFilter &inObjectLayerFilter, const TrackingVector &inTracking) const |
Cast a box and get intersecting bodies in ioCollector. More... | |
void | FindCollidingPairs (const BodyVector &inBodies, const BodyID *inActiveBodies, int inNumActiveBodies, float inSpeculativeContactDistance, BodyPairCollector &ioPairCollector, const ObjectLayerPairFilter &inObjectLayerPairFilter) const |
Find all colliding pairs between dynamic bodies, calls ioPairCollector for every pair found. More... | |
Public Member Functions inherited from NonCopyable | |
NonCopyable ()=default | |
NonCopyable (const NonCopyable &)=delete | |
void | operator= (const NonCopyable &)=delete |
Internal tree structure in broadphase, is essentially a quad AABB tree. Tree is lockless (except for UpdatePrepare/Finalize() function), modifying objects in the tree will widen the aabbs of parent nodes to make the node fit. During the UpdatePrepare/Finalize() call the tree is rebuilt to achieve a tight fit again.
using QuadTree::Allocator = FixedSizeFreeList<Node> |
Class that allocates tree nodes, can be shared between multiple trees.
using QuadTree::TrackingVector = Array<Tracking> |
QuadTree::~QuadTree | ( | ) |
Destructor.
void QuadTree::AddBodiesAbort | ( | TrackingVector & | ioTracking, |
const AddState & | inState | ||
) |
Abort adding bodies to the quadtree, supply the same bodies and state as in AddBodiesPrepare. This can be done on a background thread without influencing the broadphase.
void QuadTree::AddBodiesFinalize | ( | TrackingVector & | ioTracking, |
int | inNumberBodies, | ||
const AddState & | inState | ||
) |
Finalize adding bodies to the quadtree, supply the same number of bodies as in AddBodiesPrepare.
void QuadTree::AddBodiesPrepare | ( | const BodyVector & | inBodies, |
TrackingVector & | ioTracking, | ||
BodyID * | ioBodyIDs, | ||
int | inNumber, | ||
AddState & | outState | ||
) |
Prepare adding inNumber bodies at ioBodyIDs to the quad tree, returns the state in outState that should be used in AddBodiesFinalize. This can be done on a background thread without influencing the broadphase. ioBodyIDs may be shuffled around by this function.
|
inline |
Check if this tree can get an UpdatePrepare/Finalize() or if it needs a DiscardOldTree() first.
void QuadTree::CastAABox | ( | const AABoxCast & | inBox, |
CastShapeBodyCollector & | ioCollector, | ||
const ObjectLayerFilter & | inObjectLayerFilter, | ||
const TrackingVector & | inTracking | ||
) | const |
Cast a box and get intersecting bodies in ioCollector.
Constructor
Returns true if further processing of the tree should be aborted
Returns true if this node / body should be visited, false if no hit can be generated
Visit nodes, returns number of hits found and sorts ioChildNodeIDs so that they are at the beginning of the vector.
Visit a body, returns false if the algorithm should terminate because no hits can be generated anymore
void QuadTree::CastRay | ( | const RayCast & | inRay, |
RayCastBodyCollector & | ioCollector, | ||
const ObjectLayerFilter & | inObjectLayerFilter, | ||
const TrackingVector & | inTracking | ||
) | const |
Cast a ray and get the intersecting bodies in ioCollector.
Constructor
Returns true if further processing of the tree should be aborted
Returns true if this node / body should be visited, false if no hit can be generated
Visit nodes, returns number of hits found and sorts ioChildNodeIDs so that they are at the beginning of the vector.
Visit a body, returns false if the algorithm should terminate because no hits can be generated anymore
void QuadTree::CollideAABox | ( | const AABox & | inBox, |
CollideShapeBodyCollector & | ioCollector, | ||
const ObjectLayerFilter & | inObjectLayerFilter, | ||
const TrackingVector & | inTracking | ||
) | const |
Get bodies intersecting with inBox in ioCollector.
Constructor
Returns true if further processing of the tree should be aborted
Returns true if this node / body should be visited, false if no hit can be generated
Visit nodes, returns number of hits found and sorts ioChildNodeIDs so that they are at the beginning of the vector.
Visit a body, returns false if the algorithm should terminate because no hits can be generated anymore
void QuadTree::CollideOrientedBox | ( | const OrientedBox & | inBox, |
CollideShapeBodyCollector & | ioCollector, | ||
const ObjectLayerFilter & | inObjectLayerFilter, | ||
const TrackingVector & | inTracking | ||
) | const |
Get bodies intersecting with an oriented box and any hits to ioCollector.
Constructor
Returns true if further processing of the tree should be aborted
Returns true if this node / body should be visited, false if no hit can be generated
Visit nodes, returns number of hits found and sorts ioChildNodeIDs so that they are at the beginning of the vector.
Visit a body, returns false if the algorithm should terminate because no hits can be generated anymore
void QuadTree::CollidePoint | ( | Vec3Arg | inPoint, |
CollideShapeBodyCollector & | ioCollector, | ||
const ObjectLayerFilter & | inObjectLayerFilter, | ||
const TrackingVector & | inTracking | ||
) | const |
Get bodies intersecting with a point and any hits to ioCollector.
Constructor
Returns true if further processing of the tree should be aborted
Returns true if this node / body should be visited, false if no hit can be generated
Visit nodes, returns number of hits found and sorts ioChildNodeIDs so that they are at the beginning of the vector.
Visit a body, returns false if the algorithm should terminate because no hits can be generated anymore
void QuadTree::CollideSphere | ( | Vec3Arg | inCenter, |
float | inRadius, | ||
CollideShapeBodyCollector & | ioCollector, | ||
const ObjectLayerFilter & | inObjectLayerFilter, | ||
const TrackingVector & | inTracking | ||
) | const |
Get bodies intersecting with a sphere in ioCollector.
Constructor
Returns true if further processing of the tree should be aborted
Returns true if this node / body should be visited, false if no hit can be generated
Visit nodes, returns number of hits found and sorts ioChildNodeIDs so that they are at the beginning of the vector.
Visit a body, returns false if the algorithm should terminate because no hits can be generated anymore
void QuadTree::DiscardOldTree | ( | ) |
Will throw away the previous frame's nodes so that we can start building a new tree in the background.
void QuadTree::FindCollidingPairs | ( | const BodyVector & | inBodies, |
const BodyID * | inActiveBodies, | ||
int | inNumActiveBodies, | ||
float | inSpeculativeContactDistance, | ||
BodyPairCollector & | ioPairCollector, | ||
const ObjectLayerPairFilter & | inObjectLayerPairFilter | ||
) | const |
Find all colliding pairs between dynamic bodies, calls ioPairCollector for every pair found.
AABox QuadTree::GetBounds | ( | ) | const |
Get the bounding box for this tree.
|
inline |
|
inline |
Check if there is anything in the tree.
void QuadTree::Init | ( | Allocator & | inAllocator | ) |
Initialization.
|
inline |
Check if the tree needs an UpdatePrepare/Finalize()
void QuadTree::NotifyBodiesAABBChanged | ( | const BodyVector & | inBodies, |
const TrackingVector & | inTracking, | ||
const BodyID * | ioBodyIDs, | ||
int | inNumber | ||
) |
Call whenever the aabb of a body changes.
void QuadTree::RemoveBodies | ( | const BodyVector & | inBodies, |
TrackingVector & | ioTracking, | ||
const BodyID * | ioBodyIDs, | ||
int | inNumber | ||
) |
Remove inNumber bodies in ioBodyIDs from the quadtree.
|
inline |
Name of the tree for debugging purposes.
void QuadTree::UpdateFinalize | ( | const BodyVector & | inBodies, |
const TrackingVector & | inTracking, | ||
const UpdateState & | inUpdateState | ||
) |
void QuadTree::UpdatePrepare | ( | const BodyVector & | inBodies, |
TrackingVector & | ioTracking, | ||
UpdateState & | outUpdateState, | ||
bool | inFullRebuild | ||
) |
Update the broadphase, needs to be called regularly to achieve a tight fit of the tree when bodies have been modified. UpdatePrepare() will build the tree, UpdateFinalize() will lock the root of the tree shortly and swap the trees and afterwards clean up temporary data structures.