Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
BroadPhase Class Referenceabstract

Used to do coarse collision detection operations to quickly prune out bodies that will not collide. More...

#include <BroadPhase.h>

Inheritance diagram for BroadPhase:
BroadPhaseQuery NonCopyable BroadPhaseBruteForce BroadPhaseQuadTree

Classes

struct  UpdateState
 Context used during broadphase update. More...
 

Public Types

using AddState = void *
 Handle used during adding bodies to the broadphase. More...
 

Public Member Functions

virtual void Init (BodyManager *inBodyManager, const BroadPhaseLayerInterface &inLayerInterface)
 
virtual void Optimize ()
 Should be called after many objects have been inserted to make the broadphase more efficient, usually done on startup only. More...
 
virtual void FrameSync ()
 Must be called just before updating the broadphase when none of the body mutexes are locked. More...
 
virtual void LockModifications ()
 Must be called before UpdatePrepare to prevent modifications from being made to the tree. More...
 
virtual UpdateState UpdatePrepare ()
 
virtual void UpdateFinalize (const UpdateState &inUpdateState)
 Finalizing the update will quickly apply the changes. More...
 
virtual void UnlockModifications ()
 Must be called after UpdateFinalize to allow modifications to the broadphase. More...
 
virtual AddState AddBodiesPrepare (BodyID *ioBodies, int inNumber)
 
virtual void AddBodiesFinalize (BodyID *ioBodies, int inNumber, AddState inAddState)=0
 
virtual void AddBodiesAbort (BodyID *ioBodies, int inNumber, AddState inAddState)
 
virtual void RemoveBodies (BodyID *ioBodies, int inNumber)=0
 
virtual void NotifyBodiesAABBChanged (BodyID *ioBodies, int inNumber, bool inTakeLock=true)=0
 
virtual void NotifyBodiesLayerChanged (BodyID *ioBodies, int inNumber)=0
 Call whenever the layer (and optionally the aabb as well) of a body changes (can change order of ioBodies array) More...
 
virtual void FindCollidingPairs (BodyID *ioActiveBodies, int inNumActiveBodies, float inSpeculativeContactDistance, const ObjectVsBroadPhaseLayerFilter &inObjectVsBroadPhaseLayerFilter, const ObjectLayerPairFilter &inObjectLayerPairFilter, BodyPairCollector &ioPairCollector) const =0
 
virtual void CastAABoxNoLock (const AABoxCast &inBox, CastShapeBodyCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter) const =0
 Same as BroadPhaseQuery::CastAABox but can be implemented in a way to take no broad phase locks. More...
 
virtual AABox GetBounds () const =0
 Get the bounding box of all objects in the broadphase. More...
 
- Public Member Functions inherited from BroadPhaseQuery
virtual ~BroadPhaseQuery ()=default
 Virtual destructor. More...
 
virtual void CastRay (const RayCast &inRay, RayCastBodyCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter={ }, const ObjectLayerFilter &inObjectLayerFilter={ }) const =0
 Cast a ray and add any hits to ioCollector. More...
 
virtual void CollideAABox (const AABox &inBox, CollideShapeBodyCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter={ }, const ObjectLayerFilter &inObjectLayerFilter={ }) const =0
 Get bodies intersecting with inBox and any hits to ioCollector. More...
 
virtual void CollideSphere (Vec3Arg inCenter, float inRadius, CollideShapeBodyCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter={ }, const ObjectLayerFilter &inObjectLayerFilter={ }) const =0
 Get bodies intersecting with a sphere and any hits to ioCollector. More...
 
virtual void CollidePoint (Vec3Arg inPoint, CollideShapeBodyCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter={ }, const ObjectLayerFilter &inObjectLayerFilter={ }) const =0
 Get bodies intersecting with a point and any hits to ioCollector. More...
 
virtual void CollideOrientedBox (const OrientedBox &inBox, CollideShapeBodyCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter={ }, const ObjectLayerFilter &inObjectLayerFilter={ }) const =0
 Get bodies intersecting with an oriented box and any hits to ioCollector. More...
 
virtual void CastAABox (const AABoxCast &inBox, CastShapeBodyCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter={ }, const ObjectLayerFilter &inObjectLayerFilter={ }) const =0
 Cast a box and add any hits to ioCollector. More...
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Protected Attributes

BodyManagermBodyManager = nullptr
 Link to the body manager that manages the bodies in this broadphase. More...
 

Detailed Description

Used to do coarse collision detection operations to quickly prune out bodies that will not collide.

Member Typedef Documentation

◆ AddState

using BroadPhase::AddState = void *

Handle used during adding bodies to the broadphase.

Member Function Documentation

◆ AddBodiesAbort()

virtual void BroadPhase::AddBodiesAbort ( BodyID ioBodies,
int  inNumber,
AddState  inAddState 
)
inlinevirtual

Abort adding bodies to the broadphase, supply the return value of AddBodiesPrepare in inAddState. This can be done on a background thread without influencing the broadphase. Please ensure that the ioBodies array passed to AddBodiesPrepare is unmodified and passed again to this function.

Reimplemented in BroadPhaseQuadTree.

◆ AddBodiesFinalize()

virtual void BroadPhase::AddBodiesFinalize ( BodyID ioBodies,
int  inNumber,
AddState  inAddState 
)
pure virtual

Finalize adding bodies to the broadphase, supply the return value of AddBodiesPrepare in inAddState. Please ensure that the ioBodies array passed to AddBodiesPrepare is unmodified and passed again to this function.

Implemented in BroadPhaseBruteForce, and BroadPhaseQuadTree.

◆ AddBodiesPrepare()

virtual AddState BroadPhase::AddBodiesPrepare ( BodyID ioBodies,
int  inNumber 
)
inlinevirtual

Prepare adding inNumber bodies at ioBodies to the broadphase, returns a handle that should be used in AddBodiesFinalize/Abort. This can be done on a background thread without influencing the broadphase. ioBodies may be shuffled around by this function and should be kept that way until AddBodiesFinalize/Abort is called.

Reimplemented in BroadPhaseQuadTree.

◆ CastAABoxNoLock()

virtual void BroadPhase::CastAABoxNoLock ( const AABoxCast inBox,
CastShapeBodyCollector ioCollector,
const BroadPhaseLayerFilter inBroadPhaseLayerFilter,
const ObjectLayerFilter inObjectLayerFilter 
) const
pure virtual

Same as BroadPhaseQuery::CastAABox but can be implemented in a way to take no broad phase locks.

Implemented in BroadPhaseBruteForce, and BroadPhaseQuadTree.

◆ FindCollidingPairs()

virtual void BroadPhase::FindCollidingPairs ( BodyID ioActiveBodies,
int  inNumActiveBodies,
float  inSpeculativeContactDistance,
const ObjectVsBroadPhaseLayerFilter inObjectVsBroadPhaseLayerFilter,
const ObjectLayerPairFilter inObjectLayerPairFilter,
BodyPairCollector ioPairCollector 
) const
pure virtual

Find all colliding pairs between dynamic bodies Note that this function is very specifically tailored for the PhysicsSystem::Update function, hence it is not part of the BroadPhaseQuery interface. One of the assumptions it can make is that no locking is needed during the query as it will only be called during a very particular part of the update.

Parameters
ioActiveBodiesis a list of bodies for which we need to find colliding pairs (this function can change the order of the ioActiveBodies array). This can be a subset of the set of active bodies in the system.
inNumActiveBodiesis the size of the ioActiveBodies array.
inSpeculativeContactDistanceDistance at which speculative contact points will be created.
inObjectVsBroadPhaseLayerFilteris the filter that determines if an object can collide with a broadphase layer.
inObjectLayerPairFilteris the filter that determines if two objects can collide.
ioPairCollectorreceives callbacks for every body pair found.

Implemented in BroadPhaseBruteForce, and BroadPhaseQuadTree.

◆ FrameSync()

virtual void BroadPhase::FrameSync ( )
inlinevirtual

Must be called just before updating the broadphase when none of the body mutexes are locked.

Reimplemented in BroadPhaseQuadTree.

◆ GetBounds()

virtual AABox BroadPhase::GetBounds ( ) const
pure virtual

Get the bounding box of all objects in the broadphase.

Implemented in BroadPhaseBruteForce, and BroadPhaseQuadTree.

◆ Init()

JPH_NAMESPACE_BEGIN void BroadPhase::Init ( BodyManager inBodyManager,
const BroadPhaseLayerInterface inLayerInterface 
)
virtual

Initialize the broadphase.

Parameters
inBodyManagerThe body manager singleton
inLayerInterfaceInterface that maps object layers to broadphase layers. Note that the broadphase takes a pointer to the data inside inObjectToBroadPhaseLayer so this object should remain static.

Reimplemented in BroadPhaseQuadTree.

◆ LockModifications()

virtual void BroadPhase::LockModifications ( )
inlinevirtual

Must be called before UpdatePrepare to prevent modifications from being made to the tree.

Reimplemented in BroadPhaseQuadTree.

◆ NotifyBodiesAABBChanged()

virtual void BroadPhase::NotifyBodiesAABBChanged ( BodyID ioBodies,
int  inNumber,
bool  inTakeLock = true 
)
pure virtual

Call whenever the aabb of a body changes (can change order of ioBodies array) inTakeLock should be false if we're between LockModifications/UnlockModificiations in which case care needs to be taken to not call this between UpdatePrepare/UpdateFinalize

Implemented in BroadPhaseBruteForce, and BroadPhaseQuadTree.

◆ NotifyBodiesLayerChanged()

virtual void BroadPhase::NotifyBodiesLayerChanged ( BodyID ioBodies,
int  inNumber 
)
pure virtual

Call whenever the layer (and optionally the aabb as well) of a body changes (can change order of ioBodies array)

Implemented in BroadPhaseBruteForce, and BroadPhaseQuadTree.

◆ Optimize()

virtual void BroadPhase::Optimize ( )
inlinevirtual

Should be called after many objects have been inserted to make the broadphase more efficient, usually done on startup only.

Reimplemented in BroadPhaseQuadTree.

◆ RemoveBodies()

virtual void BroadPhase::RemoveBodies ( BodyID ioBodies,
int  inNumber 
)
pure virtual

Remove inNumber bodies in ioBodies from the broadphase. ioBodies may be shuffled around by this function.

Implemented in BroadPhaseBruteForce, and BroadPhaseQuadTree.

◆ UnlockModifications()

virtual void BroadPhase::UnlockModifications ( )
inlinevirtual

Must be called after UpdateFinalize to allow modifications to the broadphase.

Reimplemented in BroadPhaseQuadTree.

◆ UpdateFinalize()

virtual void BroadPhase::UpdateFinalize ( const UpdateState inUpdateState)
inlinevirtual

Finalizing the update will quickly apply the changes.

Reimplemented in BroadPhaseQuadTree.

◆ UpdatePrepare()

virtual UpdateState BroadPhase::UpdatePrepare ( )
inlinevirtual

Update the broadphase, needs to be called frequently to update the internal state when bodies have been modified. The UpdatePrepare() function can run in a background thread without influencing the broadphase

Reimplemented in BroadPhaseQuadTree.

Member Data Documentation

◆ mBodyManager

BodyManager* BroadPhase::mBodyManager = nullptr
protected

Link to the body manager that manages the bodies in this broadphase.


The documentation for this class was generated from the following files: