/// <summary> /// Get the objects in this tree that intersect with the specified rectangle. /// </summary> /// <param name="searchRect">The rectangle to find objects in.</param> internal List <T> GetObjects(BoundingBox2D searchRect) { List <T> results = new List <T>(); GetObjects(searchRect, ref results); return(results); }
/// <summary> /// Get the objects in this tree that intersect with the specified rectangle. /// </summary> /// <param name="searchRect">The rectangle to find objects in.</param> /// <param name="results">A reference to a list that will be populated with the results.</param> internal void GetObjects(BoundingBox2D searchRect, ref List <T> results) { // We can't do anything if the results list doesn't exist if (results != null) { if (searchRect.Contains(this.rect)) { // If the search area completely contains this quad, just get every object this quad and all it's children have GetAllObjects(ref results); } else if (searchRect.Intersects(this.rect)) { // Otherwise, if the quad isn't fully contained, only add objects that intersect with the search rectangle if (objects != null) { for (int i = 0; i < objects.Count; i++) { if (searchRect.Intersects(objects[i].Data.BoundingBox2D)) { results.Add(objects[i].Data); } } } // Get the objects for the search rectangle from the children if (childTL != null) { childTL.GetObjects(searchRect, ref results); childTR.GetObjects(searchRect, ref results); childBL.GetObjects(searchRect, ref results); childBR.GetObjects(searchRect, ref results); } } } }
protected BoundingBox2D(BoundingBox2D old) { this.boundingBox = new RectangleF(old.boundingBox.X, old.boundingBox.Y, old.boundingBox.Width, old.boundingBox.Height); this.Offset = old.Offset; this.Name = old.Name; this.Active = old.Active; this.Position = new Vector2(old.Position.X, old.Position.Y); }
private QuadTreeNode(QuadTreeNode <T> parent, BoundingBox2D rect) : this(rect) { this.parent = parent; }
/// <summary> /// Creates a QuadTree for the specified area. /// </summary> /// <param name="x">The top-left position of the area rectangle.</param> /// <param name="y">The top-right position of the area rectangle.</param> /// <param name="width">The width of the area rectangle.</param> /// <param name="height">The height of the area rectangle.</param> public QuadTreeNode(int x, int y, int width, int height) { rect = new BoundingBox2D(new RectangleF(x, y, width, height)); }
/// <summary> /// Creates a QuadTree for the specified area. /// </summary> /// <param name="rect">The area this QuadTree object will encompass.</param> public QuadTreeNode(BoundingBox2D rect) { this.rect = rect; }
/// <summary> /// Get the objects in this tree that intersect with the specified rectangle. /// </summary> /// <param name="rect">The rectangle to find objects in.</param> /// <param name="results">A reference to a list that will be populated with the results.</param> public void GetObjects(BoundingBox2D rect, ref List <T> results) { quadTreeRoot.GetObjects(rect, ref results); }
/// <summary> /// Get the objects in this tree that intersect with the specified rectangle. /// </summary> /// <param name="rect">The rectangle to find objects in.</param> public List <T> GetObjects(BoundingBox2D rect) { return(quadTreeRoot.GetObjects(rect)); }
/// <summary> /// Creates a QuadTree for the specified area. /// </summary> /// <param name="rect">The area this QuadTree object will encompass.</param> public QuadTree(BoundingBox2D rect) { quadTreeRoot = new QuadTreeNode <T>(rect); quadTreeObjectPool = new PoolNew <QuadTreeObject <T> >(typeof(QuadTreeObject <T>), 1000); objectRemovedCount = 0; }
public bool Contains(ICollision collisionObject) { BoundingBox2D otherObject = collisionObject as BoundingBox2D; return(otherObject != null && this.boundingBox.Contains(otherObject.Box)); }
public bool Intersects(ICollision collisionObject) { BoundingBox2D otherObject = collisionObject as BoundingBox2D; return(otherObject != null && this.boundingBox.Intersects(otherObject.Box)); }
public CollisionComponent(BoundingBox2D boundingBox) : this() { BoundingBox2D = boundingBox; }
public CollisionComponent() { CollisionPriority = int.MaxValue; Solid = true; BoundingBox2D = new BoundingBox2D(); }
public override void Deserialize(XElement element) { if (element.Element("boundingBox") != null) { if (BoundingBox2D == null) BoundingBox2D = new BoundingBox2D(); BoundingBox2D.Deserialize(element.Element("boundingBox")); } int collisionPriority = int.MaxValue; if (element.Element("priority") != null) { int.TryParse(element.Element("priority").Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out collisionPriority); } CollisionPriority = collisionPriority; bool solid = true; if (element.Element("solid") != null) { bool.TryParse(element.Element("solid").Value, out solid); } Solid = solid; }