public void AddCollisionShape(CollisionShape shape) { // Called with this equal to the root of the tree shapesAdded++; SphereTreeNode s = new SphereTreeNode(shape, this); if (MO.DoLog) { MO.Log("Adding shape {0} to leaf {1}", shape, s); } root.InsertSphereTreeNode(s); root.AddToIntersectingShapes(shape); Debug.Assert(shapesAdded - shapesRemoved <= nodeCount, "shapesAdded - shapesRemoved > nodeCount!"); MaybeVerifyOrDump(); }
public void AddToIntersectingShapes(CollisionShape shape) { if (shape == containedShape || !SphereOverlap(shape)) { return; } for (int i = 0; i < childCount; i++) { SphereTreeNode child = children[i]; if (child != null) { if (child.Contains(shape)) { child.AddToIntersectingShapes(shape); return; } } } // Not wholly contained in a child so add it to our list AddIntersectingShape(shape); // Add it to any child that overlaps AddToChildIntersectingShapes(shape); }