private void insert(AlignedBoundingBox newBounds, QuadtreeNode current) { newBounds.ContainerTree = this; if (current.isColliding(newBounds) && current.Depth < MaxDepth) { if (current[0] == null) { current.Subdivide(); } insert(newBounds, current[0]); insert(newBounds, current[1]); insert(newBounds, current[2]); insert(newBounds, current[3]); } else if (current.isColliding(newBounds)) { current.InsertBounds(newBounds); } }
private void collisionSearch(AlignedBoundingBox searchBounds, QuadtreeNode current, ref LinkedList <AlignedBoundingBox> list) { if (current.isColliding(searchBounds) && current[0] != null) { collisionSearch(searchBounds, current[0], ref list); collisionSearch(searchBounds, current[1], ref list); collisionSearch(searchBounds, current[2], ref list); collisionSearch(searchBounds, current[3], ref list); } else if (current[0] == null) { if (current.Boxes.Count != 0) { foreach (AlignedBoundingBox b in current.Boxes) { if (b.isColliding(searchBounds) && !list.Contains(b) && b != searchBounds) { list.AddFirst(b); } } } } }