30#include <entt/entt.hpp>
32#include <glm/vec3.hpp>
43 [[nodiscard]]
bool valid() const noexcept {
return id >= 0; }
79 void queryAABB(
const WorldAABB& aabb,
const std::function<
bool(entt::entity)>& visit)
const;
83 void raycast(glm::vec3 origin, glm::vec3 dir,
float maxT,
const std::function<
bool(entt::entity)>& visit)
const;
91 const std::function<
bool(entt::entity)>& visit)
const;
107 [[nodiscard]]
bool isLeaf(int32_t nodeId)
const noexcept;
110 [[nodiscard]] int32_t
leftChild(int32_t nodeId)
const noexcept;
111 [[nodiscard]] int32_t
rightChild(int32_t nodeId)
const noexcept;
Swept AABB and sphere collision queries against world geometry.
static constexpr float k_motionPredict
How aggressively to extend the fat AABB along the body's motion vector each update — multiplied by th...
Definition BroadphaseTree.hpp:57
void removeLeaf(int32_t leaf)
Definition BroadphaseTree.cpp:198
bool isLeaf(int32_t nodeId) const noexcept
True iff the node is a leaf (no children, has entity).
Definition BroadphaseTree.cpp:431
int32_t leftChild(int32_t nodeId) const noexcept
Left/right child of an interior node (or -1 if leaf / invalid).
Definition BroadphaseTree.cpp:438
static bool aabbContains(const WorldAABB &container, const WorldAABB &inside)
Definition BroadphaseTree.cpp:41
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.
Definition BroadphaseTree.cpp:402
bool updateProxy(Proxy p, const WorldAABB &newAabb, glm::vec3 displacement)
Notify the tree that the entity's AABB moved.
Definition BroadphaseTree.cpp:84
int32_t allocNode()
Definition BroadphaseTree.cpp:47
void freeNode(int32_t id)
Definition BroadphaseTree.cpp:60
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.
Definition BroadphaseTree.cpp:328
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].
Definition BroadphaseTree.cpp:354
int32_t rightChild(int32_t nodeId) const noexcept
Definition BroadphaseTree.cpp:445
int32_t rootIndex() const noexcept
Root node id (or -1 if empty). Exposed for debug viz.
Definition BroadphaseTree.hpp:100
static constexpr float k_fatAabbMargin
Margin added to every leaf's AABB so it doesn't reinsert on tiny movements.
Definition BroadphaseTree.hpp:53
int32_t freeList_
Definition BroadphaseTree.hpp:126
static WorldAABB combine(const WorldAABB &a, const WorldAABB &b)
Definition BroadphaseTree.cpp:21
Proxy insertProxy(const WorldAABB &aabb, entt::entity entity)
Insert a leaf at the given AABB.
Definition BroadphaseTree.cpp:68
static bool aabbOverlap(const WorldAABB &a, const WorldAABB &b)
Definition BroadphaseTree.cpp:35
void clear()
Clear all proxies and release pool memory.
Definition BroadphaseTree.cpp:416
static float aabbArea(const WorldAABB &a)
Definition BroadphaseTree.cpp:29
void insertLeaf(int32_t leaf)
Definition BroadphaseTree.cpp:119
void removeProxy(Proxy p)
Destroy the leaf. The Proxy handle becomes invalid.
Definition BroadphaseTree.cpp:110
int proxyCount_
Definition BroadphaseTree.hpp:127
int proxyCount() const noexcept
Current proxy count (live leaves).
Definition BroadphaseTree.hpp:97
WorldAABB nodeAabb(int32_t nodeId) const noexcept
Read-only access to a node's AABB.
Definition BroadphaseTree.cpp:424
std::vector< Node > nodes_
Definition BroadphaseTree.hpp:124
int32_t root_
Definition BroadphaseTree.hpp:125
int32_t balance(int32_t a)
Definition BroadphaseTree.cpp:238
Definition BroadphaseTree.cpp:11
An axis-aligned box in world space, used as static collision geometry.
Definition SweptCollision.hpp:35
Stable handle to a tree leaf.
Definition BroadphaseTree.hpp:41
bool valid() const noexcept
Definition BroadphaseTree.hpp:43
Definition BroadphaseTree.hpp:115
int32_t height
0 = leaf; -1 = free.
Definition BroadphaseTree.hpp:121
int32_t right
Definition BroadphaseTree.hpp:120
int32_t left
Definition BroadphaseTree.hpp:119
int32_t parent
Definition BroadphaseTree.hpp:118
entt::entity entity
Leaf only.
Definition BroadphaseTree.hpp:117
WorldAABB aabb
Definition BroadphaseTree.hpp:116