public void Distribute(int depth) { if (containedObjects.Count > maxObjects && depth <= maxDepth) { Split(); for (int i = containedObjects.Count - 1; i >= 0; i--)// (OctreeObject item in containedObjects) { object item = containedObjects[i]; foreach (OctreeLeaf leaf in ChildLeaves) { IOctreeObject o = item as IOctreeObject; BoundingBox bounds = o.GetOctreeBounds(); if (leaf.ContainerBox.Contains(bounds) == ContainmentType.Contains) { leaf.ContainedObjects.Add(item); containedObjects.Remove(item); break; } } } depth++; foreach (OctreeLeaf leaf in ChildLeaves) { leaf.Distribute(depth); } depth--; } }
public virtual void Add(IOctreeObject item) { if (item.GetOctreeBounds() == null) { return; } ContainedObjects.Add(item); Bounds(); base.Distribute(0); }