/// <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); } } }
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); } } }
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); }
public bool OnMap(Collidable obj) { return(Area.Contains(obj.GetBounds())); }
/// <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()); }
/// <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; } } }
/// <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())); }
public override bool IsCollidingWith(Collidable c) { return(_snapShotManager.GetBoundsSnapShot().IntersectsWith(c.GetBounds())); }
public override bool IsCollidingWith(Collidable c) { return _snapShotManager.GetBoundsSnapShot().IntersectsWith(c.GetBounds()); }
public bool OnMap(Collidable obj) { return Area.Contains(obj.GetBounds()); }