/** * Construct a world object. * * @param gravity the world gravity vector. */ public World(Vec2 gravity, IWorldPool pool) { this(gravity, pool, new DynamicTree()); }
++count; } else { freeNode(node); DynamicTreeNode child2 = m_nodes[index2]; DynamicTreeNode parent = allocateNode(); parent.child1 = child1; parent.child2 = child2; validate();
@Override public void drawTree(DebugDraw argDraw) { if (m_root == null) { return; } int height = computeHeight(); drawTree(argDraw, m_root, 0, height); }
@Override public final void destroyProxy(int proxyId) { assert (0 <= proxyId && proxyId < m_nodeCapacity); DynamicTreeNode node = m_nodes[proxyId]; assert (node.child1 == null); removeLeaf(node); freeNode(node); }
/** * Validate this tree. For testing. */ public void validate() { validateStructure(m_root); validateMetrics(m_root); int freeCount = 0; DynamicTreeNode freeNode = m_freeList != NULL_NODE ? m_nodes[m_freeList] : null; while (freeNode != null) { assert (0 <= freeNode.id && freeNode.id < m_nodeCapacity); assert (freeNode == m_nodes[freeNode.id]); freeNode = freeNode.parent; ++freeCount; } assert (getHeight() == computeHeight()); assert (m_nodeCount + freeCount == m_nodeCapacity); }
@Override public final int createProxy(final AABB aabb, Object userData) { assert(aabb.isValid()); final DynamicTreeNode node = allocateNode(); int proxyId = node.id; // Fatten the aabb final AABB nodeAABB = node.aabb; nodeAABB.lowerBound.x = aabb.lowerBound.x - Settings.aabbExtension; nodeAABB.lowerBound.y = aabb.lowerBound.y - Settings.aabbExtension; nodeAABB.upperBound.x = aabb.upperBound.x + Settings.aabbExtension; nodeAABB.upperBound.y = aabb.upperBound.y + Settings.aabbExtension; node.userData = userData; insertLeaf(proxyId); return proxyId; }
removeLeaf(node); insertLeaf(proxyId); return true;
final DynamicTreeNode newParent = allocateNode(); newParent.parent = oldParent; newParent.userData = null; index = balance(index);
@Override public final int computeHeight() { return computeHeight(m_root); }
public void drawTree(DebugDraw argDraw, DynamicTreeNode node, int spot, int height) { node.aabb.getVertices(drawVecs); color.set(1, (height - spot) * 1f / height, (height - spot) * 1f / height); argDraw.drawPolygon(drawVecs, 4, color); argDraw.getViewportTranform().getWorldToScreen(node.aabb.upperBound, textVec); argDraw.drawString(textVec.x, textVec.y, node.id + "-" + (spot + 1) + "/" + height, color); if (node.child1 != null) { drawTree(argDraw, node.child1, spot + 1, height); } if (node.child2 != null) { drawTree(argDraw, node.child2, spot + 1, height); } } }
/** * Validate this tree. For testing. */ public void validate() { validateStructure(m_root); validateMetrics(m_root); int freeCount = 0; DynamicTreeNode freeNode = m_freeList != NULL_NODE ? m_nodes[m_freeList] : null; while (freeNode != null) { assert (0 <= freeNode.id && freeNode.id < m_nodeCapacity); assert (freeNode == m_nodes[freeNode.id]); freeNode = freeNode.parent; ++freeCount; } assert (getHeight() == computeHeight()); assert (m_nodeCount + freeCount == m_nodeCapacity); }
@Override public void drawTree(DebugDraw argDraw) { if (m_root == null) { return; } int height = computeHeight(); drawTree(argDraw, m_root, 0, height); }
@Override public final void destroyProxy(int proxyId) { assert (0 <= proxyId && proxyId < m_nodeCapacity); DynamicTreeNode node = m_nodes[proxyId]; assert (node.child1 == null); removeLeaf(node); freeNode(node); }
@Override public final int createProxy(final AABB aabb, Object userData) { assert(aabb.isValid()); final DynamicTreeNode node = allocateNode(); int proxyId = node.id; // Fatten the aabb final AABB nodeAABB = node.aabb; nodeAABB.lowerBound.x = aabb.lowerBound.x - Settings.aabbExtension; nodeAABB.lowerBound.y = aabb.lowerBound.y - Settings.aabbExtension; nodeAABB.upperBound.x = aabb.upperBound.x + Settings.aabbExtension; nodeAABB.upperBound.y = aabb.upperBound.y + Settings.aabbExtension; node.userData = userData; insertLeaf(proxyId); return proxyId; }
removeLeaf(node); insertLeaf(proxyId); return true;
final DynamicTreeNode newParent = allocateNode(); newParent.parent = oldParent; newParent.userData = null; index = balance(index);
private final int computeHeight(DynamicTreeNode node) { assert (0 <= node.id && node.id < m_nodeCapacity); if (node.child1 == null) { return 0; } int height1 = computeHeight(node.child1); int height2 = computeHeight(node.child2); return 1 + MathUtils.max(height1, height2); }
public void drawTree(DebugDraw argDraw, DynamicTreeNode node, int spot, int height) { node.aabb.getVertices(drawVecs); color.set(1, (height - spot) * 1f / height, (height - spot) * 1f / height); argDraw.drawPolygon(drawVecs, 4, color); argDraw.getViewportTranform().getWorldToScreen(node.aabb.upperBound, textVec); argDraw.drawString(textVec.x, textVec.y, node.id + "-" + (spot + 1) + "/" + height, color); if (node.child1 != null) { drawTree(argDraw, node.child1, spot + 1, height); } if (node.child2 != null) { drawTree(argDraw, node.child2, spot + 1, height); } } }
/** * Validate this tree. For testing. */ public void validate() { validateStructure(m_root); validateMetrics(m_root); int freeCount = 0; DynamicTreeNode freeNode = m_freeList != NULL_NODE ? m_nodes[m_freeList] : null; while (freeNode != null) { assert (0 <= freeNode.id && freeNode.id < m_nodeCapacity); assert (freeNode == m_nodes[freeNode.id]); freeNode = freeNode.parent; ++freeCount; } assert (getHeight() == computeHeight()); assert (m_nodeCount + freeCount == m_nodeCapacity); }