示例#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);
        }
示例#3
0
        public void FastRemove(IOctreeObject item)
        {
            if (ContainedObjects.Contains(item))
            {
                List <OctreeLeaf> toRemove = new List <OctreeLeaf>();

                ContainedObjects.Remove(item);
                foreach (OctreeLeaf leaf in ChildLeaves)
                {
                    leaf.FastRemove(item);
                    if (leaf.children == null || leaf.children.Count == 0)
                    {
                        toRemove.Add(leaf);
                    }
                }

                foreach (OctreeLeaf leaf in toRemove)
                {
                    ChildLeaves.Remove(leaf);
                }
            }
        }