public QuadTree(double x, double y, double w, double h) : base(x, y, w, h) { Objects = new VectorList<ICollidable>(); Offset = new Vector2D(); root = this; Enabled = false; sprite = new PrimitiveLine() { Colour = Color.Red }; sprite.CreateRectangle(this); }
private QuadTree(double x, double y, double w, double h, QuadTree root) : this(x, y, w, h) { this.root = root; }
public void Split() { if(Children != null) { for (int i = 0; i < Children.Length; i++) { Children[i].Split(); } } else { var hW = W / 2; var hY = H / 2; Children = new QuadTree[4]; Children[0] = new QuadTree(X, Y, hW, hY, root); Children[1] = new QuadTree(X + hW, Y, hW, hY, root); Children[2] = new QuadTree(X, Y + hY, hW, hY, root); Children[3] = new QuadTree(X + hW, Y + hY, hW, hY, root); } }