示例#1
0
        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--;
            }
        }
示例#2
0
        public virtual void Add(IOctreeObject item)
        {
            if (item.GetOctreeBounds() == null)
            {
                return;
            }

            ContainedObjects.Add(item);

            Bounds();
            base.Distribute(0);
        }