示例#1
0
        /// <summary>
        /// Gives a list of Objects that are nearby enough for collision
        /// </summary>
        /// <param name="area"></param>
        /// <returns></returns>
        public List <QuadTreeData> Query(Rectangle area)
        {
            List <QuadTreeData> result = new List <QuadTreeData>();

            if (!Collisions.RectangleRectangle(area, nodeBounds))
            {
                return(result);
            }
            if (IsLeaf())
            {
                for (int i = 0; i < contents.Count; i++)
                {
                    if (Collisions.RectangleRectangle(contents[i].bounds, area))
                    {
                        result.Add(contents[i]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < children.Count; i++)
                {
                    List <QuadTreeData> recurse = children[i].Query(area);
                    if (recurse.Count > 0)
                    {
                        result.InsertRange(result.Count - 1, recurse);
                    }
                }
            }
            return(result);
        }
示例#2
0
 /// <summary>
 /// Insert object into a new node
 /// </summary>
 /// <param name="data"></param>
 public void Insert(QuadTreeData data)
 {
     if (!Collisions.RectangleRectangle(data.bounds, nodeBounds))
     {
         return;
     }
     if (IsLeaf() && contents.Count + 1 > maxObjectsPerNode)
     {
         Split();
     }
     if (IsLeaf())
     {
         contents.Add(data);
     }
     else
     {
         for (int i = 0; i < children.Count; i++)
         {
             children[i].Insert(data);
         }
     }
 }