Box2D
3.0.0
A Real-Time-Oriented 2-D Physics Engine
|
A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt. More...
#include <DynamicTree.hpp>
Public Types | |
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 | |
DynamicTree (const size_type nodeCapacity=GetDefaultInitialNodeCapacity()) | |
Constructing the tree initializes the node pool. More... | |
~DynamicTree () noexcept | |
Destroys the tree, freeing the node pool. More... | |
DynamicTree (const DynamicTree ©)=delete | |
DynamicTree & | operator= (const DynamicTree &)=delete |
size_type | CreateProxy (const AABB aabb, void *userData) |
Creates a new proxy. More... | |
void | DestroyProxy (const size_type index) |
Destroys a proxy. More... | |
bool | UpdateProxy (const size_type index, const AABB aabb, const Length2D displacement, const RealNum multiplier=1, const Length extension=Length{0}) |
Updates a proxy. More... | |
void * | GetUserData (const size_type index) const noexcept |
Gets the user data for the node identified by the given identifier. More... | |
AABB | GetFatAABB (const size_type index) const noexcept |
Gets the fat AABB for a proxy. 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 a exact ray-cast in the case were the proxy contains a shape. The callback also performs the any collision filtering. More... | |
bool | Validate () const |
Validates this tree. More... | |
bool | ValidateStructure (const size_type index) const noexcept |
Validates the structure of this tree from the given index. More... | |
bool | ValidateMetrics (size_type index) const noexcept |
Validates the metrics of this tree from the given index. More... | |
size_type | GetHeight () const noexcept |
Gets the height of the binary tree. More... | |
size_type | GetMaxBalance () const |
Gets the maximum balance. More... | |
RealNum | GetAreaRatio () const noexcept |
Gets the ratio of the sum of the perimeters of nodes to the root perimeter. More... | |
void | RebuildBottomUp () |
Builds an optimal tree. More... | |
void | ShiftOrigin (const Length2D newOrigin) |
Shifts the world origin. More... | |
size_type | ComputeHeight (const size_type nodeId) const noexcept |
Computes the height of the tree from a given node. More... | |
size_type | ComputeHeight () const noexcept |
Computes the height of the tree from its root. More... | |
size_type | GetNodeCapacity () const noexcept |
Gets the current node capacity of this tree. More... | |
size_type | GetNodeCount () const noexcept |
Gets the current node count. More... | |
size_type | FindLowestCostNode (const AABB leafAABB) const noexcept |
Finds the lowest cost node. More... | |
Static Public Member Functions | |
static constexpr size_type | GetDefaultInitialNodeCapacity () noexcept |
Static Public Attributes | |
static constexpr auto | AabbMultiplier = 2 |
static constexpr size_type | InvalidIndex = static_cast<size_type>(-1) |
Invalid index value. More... | |
A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt.
A dynamic tree arranges data in a binary tree to accelerate queries such as volume queries and ray casts. Leafs are proxies with an AABB. In the tree we expand the proxy AABB by AabbMultiplier so that the proxy AABB is bigger than the client object. This allows the client object to move by small amounts without triggering a tree update.
Nodes are pooled and relocatable, so we use node indices rather than pointers.
using box2d::DynamicTree::QueryCallback = std::function<bool(size_type)> |
using box2d::DynamicTree::RayCastCallback = std::function<RealNum(const RayCastInput&, size_type)> |
using box2d::DynamicTree::size_type = std::remove_const<decltype(MaxContacts)>::type |
DynamicTree::DynamicTree | ( | const size_type | nodeCapacity = GetDefaultInitialNodeCapacity() | ) |
Constructing the tree initializes the node pool.
|
noexcept |
Destroys the tree, freeing the node pool.
|
delete |
|
noexcept |
Computes the height of the tree from a given node.
nodeId | ID of node to compute height from. |
|
inlinenoexcept |
Computes the height of the tree from its root.
DynamicTree::size_type DynamicTree::CreateProxy | ( | const AABB | aabb, |
void * | userData | ||
) |
Creates a new proxy.
Creates a proxy for a tight fitting AABB and a userData pointer.
void DynamicTree::DestroyProxy | ( | const size_type | index | ) |
Destroys a proxy.
|
noexcept |
Finds the lowest cost node.
|
noexcept |
Gets the ratio of the sum of the perimeters of nodes to the root perimeter.
|
staticnoexcept |
Gets the fat AABB for a proxy.
index | Proxy ID. Must be a valid ID. |
|
inlinenoexcept |
Gets the height of the binary tree.
DynamicTree::size_type DynamicTree::GetMaxBalance | ( | ) | const |
Gets the maximum balance.
This gets the maximum balance of nodes in the tree.
|
inlinenoexcept |
Gets the current node capacity of this tree.
|
inlinenoexcept |
Gets the current node count.
|
inlinenoexcept |
Gets the user data for the node identified by the given identifier.
index | Identifier of node to get the user data for. |
|
delete |
void DynamicTree::Query | ( | const AABB | aabb, |
QueryCallback | callback | ||
) | const |
void DynamicTree::RayCast | ( | const RayCastInput & | input, |
RayCastCallback | callback | ||
) | const |
Ray-cast against the proxies in the tree. This relies on the callback to perform a exact ray-cast in the case were the proxy contains a shape. The callback also performs the any collision filtering.
input | the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1). |
callback | a callback class that is called for each proxy that is hit by the ray. |
void DynamicTree::RebuildBottomUp | ( | ) |
Builds an optimal tree.
void DynamicTree::ShiftOrigin | ( | const Length2D | newOrigin | ) |
Shifts the world origin.
newOrigin | the new origin with respect to the old origin |
bool DynamicTree::UpdateProxy | ( | const size_type | index, |
const AABB | aabb, | ||
const Length2D | displacement, | ||
const RealNum | multiplier = 1 , |
||
const Length | extension = Length{0} |
||
) |
Updates a proxy.
index | Proxy ID. Behavior is undefined if this is not a valid ID. |
aabb | New axis aligned bounding box of the proxy. |
displacement | Displacement of the proxy. Behavior undefined if not a valid value. |
multiplier | Multiplier to displacement amount for new AABB. This is used to predict the future position based on the current displacement. This is a dimensionless multiplier. |
extension | Extension. Amount to fatten the given AABB by if the proxy does not contain it. |
bool DynamicTree::Validate | ( | ) | const |
Validates this tree.
true
if valid, false
otherwise.
|
noexcept |
Validates the metrics of this tree from the given index.
true
if valid, false
otherwise.
|
noexcept |
Validates the structure of this tree from the given index.
true
if valid, false
otherwise.
|
static |
Invalid index value.