Exemplo n.º 1
0
        /// <summary> Remove a OctreeLeaf out of the tree at a location.
        ///
        /// </summary>
        /// <param name="leaf">object-location composite

        /// <returns> the object removed, null if the object not found.
        /// </returns>
        public object RemoveNode(OctreeLeaf leaf)
        {
            if (branch == null)
            {
                // This must be the node that has it...
                for (int i = 0; i < items.Count; i++)
                {
                    OctreeLeaf qtl = (OctreeLeaf)items[i];
                    if (leaf.LeafObject == qtl.LeafObject)
                    {
                        items.RemoveAt(i);
                        return(qtl.LeafObject);
                    }
                }
            }
            else
            {
                OctreeNode node = getChild(leaf.X, leaf.Y, leaf.Z);
                if (node != null)
                {
                    return(node.RemoveNode(leaf));
                }
            }
            return(null);
        }
Exemplo n.º 2
0
 /// <summary> Get all the objects within a bounding box.</summary>
 /// <param name="rect">boundary of area to fill.</param>
 /// <param name="vector">current vector of objects.</param>
 /// <returns> updated Vector of objects.</returns>
 public ArrayList GetNode(OctreeBox rect, ArrayList nodes)
 {
     if (branch == null)
     {
         IEnumerator things = this.items.GetEnumerator();
         while (things.MoveNext())
         {
             OctreeLeaf qtl = (OctreeLeaf)things.Current;
             if (rect.pointWithinBounds(qtl.X, qtl.Y, qtl.Z))
             {
                 nodes.Add(qtl.LeafObject);
             }
         }
     }
     else
     {
         for (int i = 0; i < branch.Length; i++)
         {
             if (branch[i].bounds.within(rect))
             {
                 branch[i].GetNode(rect, nodes);
             }
         }
     }
     return(nodes);
 }
Exemplo n.º 3
0
        /// <summary> Add a OctreeLeaf into the tree at a location.</summary>
        /// <param name="leaf">object-location composite</param>
        /// <returns> true if the pution worked.</returns>
        public bool AddNode(OctreeLeaf leaf)
        {
            if (branch == null)
            {
                this.items.Add(leaf);
                if (this.items.Count == 1)
                {
                    this.allTheSamePoint = true;
                    this.firstX          = leaf.X;
                    this.firstY          = leaf.Y;
                    this.firstZ          = leaf.Z;
                }
                else
                {
                    if (this.firstX != leaf.X || this.firstY != leaf.Y || this.firstZ != leaf.Z)
                    {
                        this.allTheSamePoint = false;
                    }
                }

                if (this.items.Count > maxItems && !this.allTheSamePoint)
                {
                    split();
                }
                return(true);
            }
            else
            {
                OctreeNode node = getChild(leaf.X, leaf.Y, leaf.Z);
                if (node != null)
                {
                    return(node.AddNode(leaf));
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        /// <summary> Remove a OctreeLeaf out of the tree at a location.
        /// 
        /// </summary>
        /// <param name="leaf">object-location composite

        /// <returns> the object removed, null if the object not found.
        /// </returns>
        public object RemoveNode(OctreeLeaf leaf)
        {
            if (branch == null)
            {
                // This must be the node that has it...
                for (int i = 0; i < items.Count; i++)
                {
                    OctreeLeaf qtl = (OctreeLeaf)items[i];
                    if (leaf.LeafObject == qtl.LeafObject)
                    {
                        items.RemoveAt(i);
                        return qtl.LeafObject;
                    }
                }
            }
            else
            {
                OctreeNode node = getChild(leaf.X, leaf.Y, leaf.Z);
                if (node != null)
                {
                    return node.RemoveNode(leaf);
                }
            }
            return null;
        }
Exemplo n.º 5
0
        /// <summary> Add a OctreeLeaf into the tree at a location.</summary>
        /// <param name="leaf">object-location composite</param>
        /// <returns> true if the pution worked.</returns>
        public bool AddNode(OctreeLeaf leaf)
        {
            if (branch == null)
            {
                this.items.Add(leaf);
                if (this.items.Count == 1)
                {
                    this.allTheSamePoint = true;
                    this.firstX = leaf.X;
                    this.firstY = leaf.Y;
                    this.firstZ = leaf.Z;
                }
                else
                {
                    if (this.firstX != leaf.X || this.firstY != leaf.Y || this.firstZ != leaf.Z)
                    {
                        this.allTheSamePoint = false;
                    }
                }

                if (this.items.Count > maxItems && !this.allTheSamePoint)
                    split();
                return true;
            }
            else
            {
                OctreeNode node = getChild(leaf.X, leaf.Y, leaf.Z);
                if (node != null)
                {
                    return node.AddNode(leaf);
                }
            }
            return false;
        }