23#ifndef B2_DYNAMIC_TREE_H
24#define B2_DYNAMIC_TREE_H
28#include "b2_growable_stack.h"
30#define b2_nullNode (-1)
37 return child1 == b2_nullNode;
91 void* GetUserData(int32 proxyId)
const;
93 bool WasMoved(int32 proxyId)
const;
94 void ClearMoved(int32 proxyId);
97 const b2AABB& GetFatAABB(int32 proxyId)
const;
101 template <
typename T>
102 void Query(T* callback,
const b2AABB& aabb)
const;
111 template <
typename T>
138 int32 AllocateNode();
139 void FreeNode(int32 node);
141 void InsertLeaf(int32 node);
142 void RemoveLeaf(int32 node);
144 int32 Balance(int32 index);
146 int32 ComputeHeight()
const;
147 int32 ComputeHeight(int32 nodeId)
const;
149 void ValidateStructure(int32 index)
const;
150 void ValidateMetrics(int32 index)
const;
156 int32 m_nodeCapacity;
160 int32 m_insertionCount;
165 b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);
166 return m_nodes[proxyId].userData;
169inline bool b2DynamicTree::WasMoved(int32 proxyId)
const
171 b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);
172 return m_nodes[proxyId].moved;
175inline void b2DynamicTree::ClearMoved(int32 proxyId)
177 b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);
178 m_nodes[proxyId].moved =
false;
183 b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);
184 return m_nodes[proxyId].
aabb;
193 while (stack.GetCount() > 0)
195 int32 nodeId = stack.Pop();
196 if (nodeId == b2_nullNode)
207 bool proceed = callback->QueryCallback(nodeId);
208 if (proceed ==
false)
215 stack.Push(node->child1);
216 stack.Push(node->child2);
232 b2Vec2 v = b2Cross(1.0f, r);
238 float maxFraction = input.maxFraction;
243 b2Vec2 t = p1 + maxFraction * (p2 - p1);
251 while (stack.GetCount() > 0)
253 int32 nodeId = stack.Pop();
254 if (nodeId == b2_nullNode)
270 float separation = b2Abs(b2Dot(v, p1 - c)) - b2Dot(abs_v, h);
271 if (separation > 0.0f)
279 subInput.p1 = input.p1;
280 subInput.p2 = input.p2;
281 subInput.maxFraction = maxFraction;
283 float value = callback->RayCastCallback(subInput, nodeId);
295 b2Vec2 t = p1 + maxFraction * (p2 - p1);
302 stack.Push(node->child1);
303 stack.Push(node->child2);
B2_API bool b2TestOverlap(const b2Shape *shapeA, int32 indexA, const b2Shape *shapeB, int32 indexB, const b2Transform &xfA, const b2Transform &xfB)
Determine if two generic shapes overlap.
Definition b2_dynamic_tree.h:69
float GetAreaRatio() const
Get the ratio of the sum of the node areas to the root area.
void Query(T *callback, const b2AABB &aabb) const
Definition b2_dynamic_tree.h:188
int32 GetMaxBalance() const
void DestroyProxy(int32 proxyId)
Destroy a proxy. This asserts if the id is invalid.
const b2AABB & GetFatAABB(int32 proxyId) const
Get the fat AABB for a proxy.
Definition b2_dynamic_tree.h:181
bool MoveProxy(int32 proxyId, const b2AABB &aabb1, const b2Vec2 &displacement)
b2DynamicTree()
Constructing the tree initializes the node pool.
~b2DynamicTree()
Destroy the tree, freeing the node pool.
void * GetUserData(int32 proxyId) const
Definition b2_dynamic_tree.h:163
void RebuildBottomUp()
Build an optimal tree. Very expensive. For testing.
int32 CreateProxy(const b2AABB &aabb, void *userData)
Create a proxy. Provide a tight fitting AABB and a userData pointer.
void Validate() const
Validate this tree. For testing.
void RayCast(T *callback, const b2RayCastInput &input) const
Definition b2_dynamic_tree.h:223
void ShiftOrigin(const b2Vec2 &newOrigin)
Definition b2_growable_stack.h:35
An axis aligned bounding box.
Definition b2_collision.h:169
b2Vec2 GetExtents() const
Get the extents of the AABB (half-widths).
Definition b2_collision.h:180
b2Vec2 GetCenter() const
Get the center of the AABB.
Definition b2_collision.h:174
b2Vec2 lowerBound
the lower vertex
Definition b2_collision.h:220
b2Vec2 upperBound
the upper vertex
Definition b2_collision.h:221
A node in the dynamic tree. The client does not interact with this directly.
Definition b2_dynamic_tree.h:34
b2AABB aabb
Enlarged AABB.
Definition b2_dynamic_tree.h:41
A 2D column vector.
Definition b2_math.h:42
float LengthSquared() const
Definition b2_math.h:96
float Normalize()
Convert this vector into a unit vector. Returns the length.
Definition b2_math.h:102