Example #1
0
        /// <summary>
        /// Updates the object and returns whether it still belongs to this node
        /// </summary>
        /// <param name="obj">Object to Update in the quad tree</param>
        /// <returns>Whether the object moved</returns>
        private bool UpdateObject(Collidable obj)
        {
            obj.ClearMapArea();
            lock (_locker)
            {
                this.Contents.Remove(obj);
            }

            // Check if object has left the bounds of this node and is not root
            if (!this.Bounds.Contains(obj.GetBounds()) && this.Parent != null)
            {
                // We now belong to a parent
                this.Parent.ReverseInsert(obj);
                return(true);
            }
            else // We're within the same node, but could be in children, must insert
            {
                this.Insert(obj);
                // If we didn't move quad tree nodes
                if (obj.GetMapArea() == this)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Example #2
0
 public void ReverseInsert(Collidable obj)
 {
     // Check if object has left the bounds of this node then go up another level
     if (!this.Bounds.Contains(obj.GetBounds()))
     {
         // NOTE: If you get an error here chances are an object is out of bounds. aka off the quad tree map.
         // In order to avoid an additional check we assume that the obj is smaller than
         // the root node.
         if (this.Parent != null)
         {
             this.Parent.ReverseInsert(obj);
         }
         else
         {
             obj.SetMapArea(this);
             lock (_locker)
             {
                 this.Contents.Add(obj);
             }
         }
     }
     else
     {
         obj.SetMapArea(this);
         lock (_locker)
         {
             this.Contents.Add(obj);
         }
     }
 }
Example #3
0
        public void Insert(Collidable obj)
        {
            foreach (QuadTreeNode node in Children)
            {
                if (node.Bounds.Contains(obj.GetBounds()))
                {
                    node.Insert(obj);
                    return;
                }
            }

            // When we get here we're then "this" is currently the largest node to fit our object OR
            // We're at a leaf node caused by the smallest possible partition width/height.
            lock (_locker)
            {
                Contents.Add(obj);
            }
            obj.SetMapArea(this);
        }
Example #4
0
 public bool OnMap(Collidable obj)
 {
     return(Area.Contains(obj.GetBounds()));
 }
Example #5
0
 /// <summary>
 /// Calculates whether me and the collidable object <paramref name="c"/> are colliding.
 /// </summary>
 /// <param name="c">The object to check the collision against.</param>
 /// <returns>Whether or not I am colliding with <paramref name="c"/>.</returns>
 public virtual bool IsCollidingWith(Collidable c)
 {
     return _bounds.IntersectsWith(c.GetBounds());
 }
Example #6
0
        /// <summary>
        /// Updates the object and returns whether it still belongs to this node
        /// </summary>
        /// <param name="obj">Object to Update in the quad tree</param>
        /// <returns>Whether the object moved</returns>
        private bool UpdateObject(Collidable obj)
        {
            obj.ClearMapArea();
            lock (_locker)
            {
                this.Contents.Remove(obj);
            }

            // Check if object has left the bounds of this node and is not root
            if (!this.Bounds.Contains(obj.GetBounds()) && this.Parent != null)
            {
                // We now belong to a parent
                this.Parent.ReverseInsert(obj);
                return true;
            }
            else // We're within the same node, but could be in children, must insert
            {
                this.Insert(obj);
                // If we didn't move quad tree nodes
                if (obj.GetMapArea() == this)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }
Example #7
0
        public void Insert(Collidable obj)
        {
            foreach (QuadTreeNode node in Children)
            {
                if (node.Bounds.Contains(obj.GetBounds()))
                {
                    node.Insert(obj);
                    return;
                }
            }

            // When we get here we're then "this" is currently the largest node to fit our object OR
            // We're at a leaf node caused by the smallest possible partition width/height.
            lock (_locker)
            {
                Contents.Add(obj);
            }
            obj.SetMapArea(this);
        }
Example #8
0
 public void ReverseInsert(Collidable obj)
 {
     // Check if object has left the bounds of this node then go up another level
     if (!this.Bounds.Contains(obj.GetBounds()))
     {
         // NOTE: If you get an error here chances are an object is out of bounds. aka off the quad tree map.
         // In order to avoid an additional check we assume that the obj is smaller than
         // the root node.
         if (this.Parent != null)
         {
             this.Parent.ReverseInsert(obj);
         }
         else
         {
             obj.SetMapArea(this);
             lock (_locker)
             {
                 this.Contents.Add(obj);
             }
         }
     }
     else
     {
         obj.SetMapArea(this);
         lock (_locker)
         {
             this.Contents.Add(obj);
         }
     }
 }
Example #9
0
 /// <summary>
 /// Calculates whether me and the collidable object <paramref name="c"/> are colliding.
 /// </summary>
 /// <param name="c">The object to check the collision against.</param>
 /// <returns>Whether or not I am colliding with <paramref name="c"/>.</returns>
 public virtual bool IsCollidingWith(Collidable c)
 {
     return(_bounds.IntersectsWith(c.GetBounds()));
 }
Example #10
0
 public override bool IsCollidingWith(Collidable c)
 {
     return(_snapShotManager.GetBoundsSnapShot().IntersectsWith(c.GetBounds()));
 }
Example #11
0
 public override bool IsCollidingWith(Collidable c)
 {
     return _snapShotManager.GetBoundsSnapShot().IntersectsWith(c.GetBounds());
 }
Example #12
0
 public bool OnMap(Collidable obj)
 {
     return Area.Contains(obj.GetBounds());
 }