Box2D  3.0.0
A Real-Time-Oriented 2-D Physics Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
box2d::BroadPhase Class Reference

Broad phase assistant. More...

#include <BroadPhase.hpp>

Classes

struct  Conf
 

Public Types

enum  : size_type { e_nullProxy = static_cast<size_type>(-1) }
 
using size_type = std::remove_const< decltype(MaxContacts)>::type
 
using QueryCallback = std::function< bool(size_type)>
 
using RayCastCallback = std::function< RealNum(const RayCastInput &, size_type)>
 

Public Member Functions

 BroadPhase (const Conf conf=GetDefaultConf())
 
 ~BroadPhase () noexcept
 
 BroadPhase (const BroadPhase &copy)=delete
 
BroadPhaseoperator= (const BroadPhase &)=delete
 
size_type CreateProxy (const AABB &aabb, void *userData)
 Creates a proxy with an initial AABB. More...
 
void DestroyProxy (size_type proxyId)
 Destroys a proxy. It is up to the client to remove any pairs. More...
 
bool UpdateProxy (const size_type proxyId, const AABB &aabb, const Length2D displacement, const RealNum multiplier=1, const Length extension=Length{0})
 Updates the proxy. More...
 
void TouchProxy (size_type proxyId) noexcept
 Call to trigger a re-processing of it's pairs on the next call to UpdatePairs. More...
 
AABB GetFatAABB (size_type proxyId) const
 Gets the fat AABB for a proxy. More...
 
void * GetUserData (size_type proxyId) const
 Gets user data from a proxy. More...
 
size_type GetProxyCount () const noexcept
 Get the number of proxies. More...
 
size_type UpdatePairs (std::function< bool(void *, void *)> callback)
 Updates the pairs. More...
 
void Query (const AABB aabb, QueryCallback callback) const
 Query an AABB for overlapping proxies. The callback class is called for each proxy that overlaps the supplied AABB. More...
 
void RayCast (const RayCastInput &input, RayCastCallback callback) const
 Ray-cast against the proxies in the tree. This relies on the callback to perform an exact ray-cast in the case were the proxy contains a shape. The callback also performs the any collision filtering. This has performance roughly equal to k * log(n), where k is the number of collisions and n is the number of proxies in the tree. More...
 
size_type GetTreeHeight () const noexcept
 Gets the height of the embedded tree. More...
 
size_type GetTreeBalance () const
 Gets the balance of the embedded tree. More...
 
RealNum GetTreeQuality () const
 Gets the quality metric of the embedded tree. More...
 
void ShiftOrigin (const Length2D newOrigin)
 Shifts the world origin. Useful for large worlds. The shift formula is: position -= newOrigin. More...
 
size_type GetPairCapacity () const noexcept
 
size_type GetMoveCapacity () const noexcept
 
size_type GetMoveCount () const noexcept
 
size_type GetPairCount () const noexcept
 

Static Public Member Functions

static constexpr Conf GetDefaultConf () noexcept
 

Detailed Description

Broad phase assistant.

The broad-phase is used for computing pairs and performing volume queries and ray casts. This broad-phase does not persist pairs. Instead, this reports potentially new pairs. It is up to the client to consume the new pairs and to track subsequent overlap.

Note
This data structure is 56-bytes large (on at least one 64-bit platform).

Member Typedef Documentation

◆ QueryCallback

using box2d::BroadPhase::QueryCallback = std::function<bool(size_type)>

◆ RayCastCallback

◆ size_type

using box2d::BroadPhase::size_type = std::remove_const<decltype(MaxContacts)>::type

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : size_type
Enumerator
e_nullProxy 

Null proxy ID.

Constructor & Destructor Documentation

◆ BroadPhase() [1/2]

BroadPhase::BroadPhase ( const Conf  conf = GetDefaultConf())

◆ ~BroadPhase()

BroadPhase::~BroadPhase ( )
noexcept

◆ BroadPhase() [2/2]

box2d::BroadPhase::BroadPhase ( const BroadPhase copy)
delete

Member Function Documentation

◆ CreateProxy()

BroadPhase::size_type BroadPhase::CreateProxy ( const AABB aabb,
void *  userData 
)

Creates a proxy with an initial AABB.

Note
Pairs are not reported until UpdatePairs is called.

◆ DestroyProxy()

void BroadPhase::DestroyProxy ( size_type  proxyId)

Destroys a proxy. It is up to the client to remove any pairs.

◆ GetDefaultConf()

static constexpr Conf box2d::BroadPhase::GetDefaultConf ( )
inlinestaticnoexcept

◆ GetFatAABB()

AABB box2d::BroadPhase::GetFatAABB ( size_type  proxyId) const
inline

Gets the fat AABB for a proxy.

Warning
Behavior is undefined if the given proxy ID is not a valid ID.

◆ GetMoveCapacity()

BroadPhase::size_type box2d::BroadPhase::GetMoveCapacity ( ) const
inlinenoexcept

◆ GetMoveCount()

BroadPhase::size_type box2d::BroadPhase::GetMoveCount ( ) const
inlinenoexcept

◆ GetPairCapacity()

BroadPhase::size_type box2d::BroadPhase::GetPairCapacity ( ) const
inlinenoexcept

◆ GetPairCount()

size_type box2d::BroadPhase::GetPairCount ( ) const
noexcept

◆ GetProxyCount()

BroadPhase::size_type box2d::BroadPhase::GetProxyCount ( ) const
inlinenoexcept

Get the number of proxies.

◆ GetTreeBalance()

BroadPhase::size_type box2d::BroadPhase::GetTreeBalance ( ) const
inline

Gets the balance of the embedded tree.

◆ GetTreeHeight()

BroadPhase::size_type box2d::BroadPhase::GetTreeHeight ( ) const
inlinenoexcept

Gets the height of the embedded tree.

◆ GetTreeQuality()

RealNum box2d::BroadPhase::GetTreeQuality ( ) const
inline

Gets the quality metric of the embedded tree.

Returns
Value of zero or more.

◆ GetUserData()

void * box2d::BroadPhase::GetUserData ( size_type  proxyId) const
inline

Gets user data from a proxy.

◆ operator=()

BroadPhase& box2d::BroadPhase::operator= ( const BroadPhase )
delete

◆ Query()

void box2d::BroadPhase::Query ( const AABB  aabb,
QueryCallback  callback 
) const
inline

Query an AABB for overlapping proxies. The callback class is called for each proxy that overlaps the supplied AABB.

◆ RayCast()

void box2d::BroadPhase::RayCast ( const RayCastInput input,
RayCastCallback  callback 
) const
inline

Ray-cast against the proxies in the tree. This relies on the callback to perform an exact ray-cast in the case were the proxy contains a shape. The callback also performs the any collision filtering. This has performance roughly equal to k * log(n), where k is the number of collisions and n is the number of proxies in the tree.

Parameters
inputthe ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
callbacka callback class that is called for each proxy that is hit by the ray.

◆ ShiftOrigin()

void box2d::BroadPhase::ShiftOrigin ( const Length2D  newOrigin)
inline

Shifts the world origin. Useful for large worlds. The shift formula is: position -= newOrigin.

Parameters
newOriginthe new origin with respect to the old origin

◆ TouchProxy()

void box2d::BroadPhase::TouchProxy ( size_type  proxyId)
inlinenoexcept

Call to trigger a re-processing of it's pairs on the next call to UpdatePairs.

◆ UpdatePairs()

BroadPhase::size_type BroadPhase::UpdatePairs ( std::function< bool(void *, void *)>  callback)

Updates the pairs.

This results in pair callbacks. This can only add pairs.

Parameters
callbackCallback that's called for AABB overlapping pairs.

◆ UpdateProxy()

bool box2d::BroadPhase::UpdateProxy ( const size_type  proxyId,
const AABB aabb,
const Length2D  displacement,
const RealNum  multiplier = 1,
const Length  extension = Length{0} 
)
inline

Updates the proxy.

Call this as many times as you like, then when you are done call UpdatePairs to finalize the proxy pairs (for your time step).

Parameters
proxyIdProxy ID. Behavior is undefined if this is the null proxy ID.
aabbAxis aligned bounding box.
displacementDisplacement. Behavior is undefined if this is an invalid value.
multiplierMultiplier to displacement amount for new AABB. This is used to predict the future position based on the current displacement. This is a dimensionless multiplier.
extensionExtension. Amount to extend the AABB by. This is used to fatten AABBs in the dynamic tree.

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