19 #ifndef B2_DYNAMIC_TREE_H
20 #define B2_DYNAMIC_TREE_H
23 #include <Box2D/Common/b2GrowableStack.h>
25 #define b2_nullNode (-1)
32 return child1 == b2_nullNode;
101 template <
typename T>
128 int32 AllocateNode();
129 void FreeNode(int32 node);
131 void InsertLeaf(int32 node);
132 void RemoveLeaf(int32 node);
134 int32 Balance(int32 index);
136 int32 ComputeHeight()
const;
137 int32 ComputeHeight(int32 nodeId)
const;
139 void ValidateStructure(int32 index)
const;
140 void ValidateMetrics(int32 index)
const;
146 int32 m_nodeCapacity;
153 int32 m_insertionCount;
158 b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);
159 return m_nodes[proxyId].userData;
164 b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);
165 return m_nodes[proxyId].
aabb;
168 template <
typename T>
174 while (stack.GetCount() > 0)
176 int32 nodeId = stack.Pop();
177 if (nodeId == b2_nullNode)
188 bool proceed = callback->QueryCallback(nodeId);
189 if (proceed ==
false)
196 stack.Push(node->child1);
197 stack.Push(node->child2);
203 template <
typename T>
213 b2Vec2 v = b2Cross(1.0f, r);
219 float32 maxFraction = input.maxFraction;
224 b2Vec2 t = p1 + maxFraction * (p2 - p1);
232 while (stack.GetCount() > 0)
234 int32 nodeId = stack.Pop();
235 if (nodeId == b2_nullNode)
251 float32 separation = b2Abs(b2Dot(v, p1 - c)) - b2Dot(abs_v, h);
252 if (separation > 0.0f)
260 subInput.p1 = input.p1;
261 subInput.p2 = input.p2;
262 subInput.maxFraction = maxFraction;
264 float32 value = callback->RayCastCallback(subInput, nodeId);
276 b2Vec2 t = p1 + maxFraction * (p2 - p1);
283 stack.Push(node->child1);
284 stack.Push(node->child2);
b2DynamicTree()
Constructing the tree initializes the node pool.
Definition: b2DynamicTree.cpp:24
b2Vec2 GetExtents() const
Get the extents of the AABB (half-widths).
Definition: b2Collision.h:174
b2Vec2 GetCenter() const
Get the center of the AABB.
Definition: b2Collision.h:168
b2Vec2 lowerBound
the lower vertex
Definition: b2Collision.h:214
b2AABB aabb
Enlarged AABB.
Definition: b2DynamicTree.h:36
Definition: b2DynamicTree.h:61
void RayCast(T *callback, const b2RayCastInput &input) const
Definition: b2DynamicTree.h:204
float32 Normalize()
Convert this vector into a unit vector. Returns the length.
Definition: b2Math.h:117
bool MoveProxy(int32 proxyId, const b2AABB &aabb1, const b2Vec2 &displacement)
Definition: b2DynamicTree.cpp:132
int32 GetHeight() const
Definition: b2DynamicTree.cpp:522
void RebuildBottomUp()
Build an optimal tree. Very expensive. For testing.
Definition: b2DynamicTree.cpp:700
~b2DynamicTree()
Destroy the tree, freeing the node pool.
Definition: b2DynamicTree.cpp:48
void DestroyProxy(int32 proxyId)
Destroy a proxy. This asserts if the id is invalid.
Definition: b2DynamicTree.cpp:123
void ShiftOrigin(const b2Vec2 &newOrigin)
Definition: b2DynamicTree.cpp:776
b2Vec2 upperBound
the upper vertex
Definition: b2Collision.h:215
float32 GetAreaRatio() const
Get the ratio of the sum of the node areas to the root area.
Definition: b2DynamicTree.cpp:533
An axis aligned bounding box.
Definition: b2Collision.h:162
void * GetUserData(int32 proxyId) const
Definition: b2DynamicTree.h:156
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: b2Collision.cpp:233
void Query(T *callback, const b2AABB &aabb) const
Definition: b2DynamicTree.h:169
Definition: b2GrowableStack.h:30
int32 GetMaxBalance() const
Definition: b2DynamicTree.cpp:678
int32 CreateProxy(const b2AABB &aabb, void *userData)
Create a proxy. Provide a tight fitting AABB and a userData pointer.
Definition: b2DynamicTree.cpp:107
void Validate() const
Validate this tree. For testing.
Definition: b2DynamicTree.cpp:659
A 2D column vector.
Definition: b2Math.h:56
float32 LengthSquared() const
Definition: b2Math.h:111
A node in the dynamic tree. The client does not interact with this directly.
Definition: b2DynamicTree.h:28
const b2AABB & GetFatAABB(int32 proxyId) const
Get the fat AABB for a proxy.
Definition: b2DynamicTree.h:162