Dynamic AABB tree.
More...
#include <BroadphaseTree.hpp>
|
| | Tree ()=default |
| Proxy | insertProxy (const WorldAABB &aabb, entt::entity entity) |
| | Insert a leaf at the given AABB.
|
| bool | updateProxy (Proxy p, const WorldAABB &newAabb, glm::vec3 displacement) |
| | Notify the tree that the entity's AABB moved.
|
| void | removeProxy (Proxy p) |
| | Destroy the leaf. The Proxy handle becomes invalid.
|
| void | queryAABB (const WorldAABB &aabb, const std::function< bool(entt::entity)> &visit) const |
| | Walk every leaf whose fat AABB overlaps aabb, calling visit(entity) for each.
|
| void | raycast (glm::vec3 origin, glm::vec3 dir, float maxT, const std::function< bool(entt::entity)> &visit) const |
| | Walk every leaf whose AABB intersects the ray segment [origin, origin + dir * maxT].
|
| void | sweptAABB (glm::vec3 halfExtents, glm::vec3 start, glm::vec3 end, const std::function< bool(entt::entity)> &visit) const |
| | Walk every leaf whose AABB intersects the swept-AABB [start, end] expanded by halfExtents.
|
| void | clear () |
| | Clear all proxies and release pool memory.
|
| int | proxyCount () const noexcept |
| | Current proxy count (live leaves).
|
| int32_t | rootIndex () const noexcept |
| | Root node id (or -1 if empty). Exposed for debug viz.
|
| WorldAABB | nodeAabb (int32_t nodeId) const noexcept |
| | Read-only access to a node's AABB.
|
| bool | isLeaf (int32_t nodeId) const noexcept |
| | True iff the node is a leaf (no children, has entity).
|
| int32_t | leftChild (int32_t nodeId) const noexcept |
| | Left/right child of an interior node (or -1 if leaf / invalid).
|
| int32_t | rightChild (int32_t nodeId) const noexcept |
|
| static constexpr float | k_fatAabbMargin = 4.0f |
| | Margin added to every leaf's AABB so it doesn't reinsert on tiny movements.
|
| static constexpr float | k_motionPredict = 2.0f |
| | How aggressively to extend the fat AABB along the body's motion vector each update — multiplied by the displacement.
|
Dynamic AABB tree.
Not thread-safe — every mutating call must be serialised by the caller (typically the physics thread).
◆ Tree()
| physics::broadphase::Tree::Tree |
( |
| ) |
|
|
default |
◆ aabbArea()
| float physics::broadphase::Tree::aabbArea |
( |
const WorldAABB & | a | ) |
|
|
staticprivate |
◆ aabbContains()
| bool physics::broadphase::Tree::aabbContains |
( |
const WorldAABB & | container, |
|
|
const WorldAABB & | inside ) |
|
staticprivate |
◆ aabbOverlap()
◆ allocNode()
| int32_t physics::broadphase::Tree::allocNode |
( |
| ) |
|
|
private |
◆ balance()
| int32_t physics::broadphase::Tree::balance |
( |
int32_t | a | ) |
|
|
private |
◆ clear()
| void physics::broadphase::Tree::clear |
( |
| ) |
|
Clear all proxies and release pool memory.
◆ combine()
◆ freeNode()
| void physics::broadphase::Tree::freeNode |
( |
int32_t | id | ) |
|
|
private |
◆ insertLeaf()
| void physics::broadphase::Tree::insertLeaf |
( |
int32_t | leaf | ) |
|
|
private |
◆ insertProxy()
| Proxy physics::broadphase::Tree::insertProxy |
( |
const WorldAABB & | aabb, |
|
|
entt::entity | entity ) |
Insert a leaf at the given AABB.
Returns a handle the caller must keep for later update / remove.
◆ isLeaf()
| bool physics::broadphase::Tree::isLeaf |
( |
int32_t | nodeId | ) |
const |
|
nodiscardnoexcept |
True iff the node is a leaf (no children, has entity).
◆ leftChild()
| int32_t physics::broadphase::Tree::leftChild |
( |
int32_t | nodeId | ) |
const |
|
nodiscardnoexcept |
Left/right child of an interior node (or -1 if leaf / invalid).
◆ nodeAabb()
| WorldAABB physics::broadphase::Tree::nodeAabb |
( |
int32_t | nodeId | ) |
const |
|
nodiscardnoexcept |
Read-only access to a node's AABB.
Returns (boundsMin == boundsMax == 0) for an invalid id.
◆ proxyCount()
| int physics::broadphase::Tree::proxyCount |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Current proxy count (live leaves).
◆ queryAABB()
| void physics::broadphase::Tree::queryAABB |
( |
const WorldAABB & | aabb, |
|
|
const std::function< bool(entt::entity)> & | visit ) const |
Walk every leaf whose fat AABB overlaps aabb, calling visit(entity) for each.
The visitor returns false to stop early, true to continue.
◆ raycast()
| void physics::broadphase::Tree::raycast |
( |
glm::vec3 | origin, |
|
|
glm::vec3 | dir, |
|
|
float | maxT, |
|
|
const std::function< bool(entt::entity)> & | visit ) const |
Walk every leaf whose AABB intersects the ray segment [origin, origin + dir * maxT].
Visitor returns false to stop.
◆ removeLeaf()
| void physics::broadphase::Tree::removeLeaf |
( |
int32_t | leaf | ) |
|
|
private |
◆ removeProxy()
| void physics::broadphase::Tree::removeProxy |
( |
Proxy | p | ) |
|
Destroy the leaf. The Proxy handle becomes invalid.
◆ rightChild()
| int32_t physics::broadphase::Tree::rightChild |
( |
int32_t | nodeId | ) |
const |
|
nodiscardnoexcept |
◆ rootIndex()
| int32_t physics::broadphase::Tree::rootIndex |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Root node id (or -1 if empty). Exposed for debug viz.
◆ sweptAABB()
| void physics::broadphase::Tree::sweptAABB |
( |
glm::vec3 | halfExtents, |
|
|
glm::vec3 | start, |
|
|
glm::vec3 | end, |
|
|
const std::function< bool(entt::entity)> & | visit ) const |
Walk every leaf whose AABB intersects the swept-AABB [start, end] expanded by halfExtents.
Used for player / projectile sweeps against dynamic bodies.
◆ updateProxy()
| bool physics::broadphase::Tree::updateProxy |
( |
Proxy | p, |
|
|
const WorldAABB & | newAabb, |
|
|
glm::vec3 | displacement ) |
Notify the tree that the entity's AABB moved.
Returns true if the tree topology was actually adjusted.
- Parameters
-
| p | Proxy from a prior insertProxy. |
| newAabb | Tight AABB of the entity at its new position. |
| displacement | Movement vector; used to fatten the new AABB so the next few frames stay inside the same leaf. |
◆ freeList_
| int32_t physics::broadphase::Tree::freeList_ = -1 |
|
private |
◆ k_fatAabbMargin
| float physics::broadphase::Tree::k_fatAabbMargin = 4.0f |
|
staticconstexpr |
Margin added to every leaf's AABB so it doesn't reinsert on tiny movements.
In world units (matches your Quake-unit scale).
◆ k_motionPredict
| float physics::broadphase::Tree::k_motionPredict = 2.0f |
|
staticconstexpr |
How aggressively to extend the fat AABB along the body's motion vector each update — multiplied by the displacement.
◆ nodes_
| std::vector<Node> physics::broadphase::Tree::nodes_ |
|
private |
◆ proxyCount_
| int physics::broadphase::Tree::proxyCount_ = 0 |
|
private |
◆ root_
| int32_t physics::broadphase::Tree::root_ = -1 |
|
private |
The documentation for this class was generated from the following files: