Example #1
0
        protected void Split()
        {
            if (children != null)
            {
                return;
            }

            Vector3 half = ContainerBox.Max - ContainerBox.Min;

            half *= 0.5f;
            Vector3 halfx = new Vector3(half.X, 0, 0);
            Vector3 halfy = new Vector3(0, half.Y, 0);
            Vector3 halfz = new Vector3(0, 0, half.Z);

            children = new List <OctreeLeaf>();

            ChildLeaves.Add(new OctreeLeaf(new BoundingBox(ContainerBox.Min, ContainerBox.Min + half)));
            ChildLeaves.Add(new OctreeLeaf(new BoundingBox(ContainerBox.Min + halfx, ContainerBox.Max - half + halfx)));
            ChildLeaves.Add(new OctreeLeaf(new BoundingBox(ContainerBox.Min + halfz, ContainerBox.Min + half + halfz)));
            ChildLeaves.Add(new OctreeLeaf(new BoundingBox(ContainerBox.Min + halfx + halfz, ContainerBox.Max - halfy)));
            ChildLeaves.Add(new OctreeLeaf(new BoundingBox(ContainerBox.Min + halfy, ContainerBox.Max - halfx - halfz)));
            ChildLeaves.Add(new OctreeLeaf(new BoundingBox(ContainerBox.Min + halfy + halfx, ContainerBox.Max - halfz)));
            ChildLeaves.Add(new OctreeLeaf(new BoundingBox(ContainerBox.Min + halfy + halfz, ContainerBox.Max - halfx)));
            ChildLeaves.Add(new OctreeLeaf(new BoundingBox(ContainerBox.Min + half, ContainerBox.Max)));
        }
Example #2
0
        public void FastRemove(object 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);
                }
            }
        }