public void Insert(ObjectGame obj) { Rectangle r = new Rectangle(obj.location.X, obj.location.Y, obj.bm.Width, obj.bm.Height); if (LeftBot == null) { CreateSubNode(); } if (LeftTop != null && LeftTop.rec.Contains(r)) { LeftTop.Insert(obj); return; } if (RightTop != null && RightTop.rec.Contains(r)) { RightTop.Insert(obj); return; } if (LeftBot != null && LeftBot.rec.Contains(r)) { LeftBot.Insert(obj); return; } if (RightBot != null && RightBot.rec.Contains(r)) { RightBot.Insert(obj); return; } this.listObj.Add(obj); }
public void Save(StreamWriter sw) { int subnode = 0; if (LeftTop != null) { subnode = 4; } sw.Write(rec.X.ToString() + "\t\t\t" + rec.Y.ToString() + "\t\t\t" + rec.Width.ToString() + "\t\t\t" + rec.Height.ToString() + "\t\t\t" + subnode + "\t\t\t" + listObj.Count + "\t\t\t"); if (listObj.Count > 0) { foreach (ObjectGame o in listObj) { sw.Write(o.index + "\t\t"); } } sw.WriteLine(); if (LeftTop != null) { LeftTop.Save(sw); RightTop.Save(sw); LeftBot.Save(sw); RightBot.Save(sw); } }
public void BuildTree() { CreateSubNode(); if (LeftTop == null) { return; } foreach (ObjectGame o in listObj) { Rectangle r = new Rectangle(o.location.X, o.location.Y, o.bm.Width, o.bm.Height); if (LeftTop.rec.IntersectsWith(r)) { LeftTop.listObj.Add(o); } if (RightTop.rec.IntersectsWith(r)) { RightTop.listObj.Add(o); } if (LeftBot.rec.IntersectsWith(r)) { LeftBot.listObj.Add(o); } if (RightBot.rec.IntersectsWith(r)) { RightBot.listObj.Add(o); } } LeftTop.BuildTree(); RightTop.BuildTree(); LeftBot.BuildTree(); RightBot.BuildTree(); listObj.Clear(); }
public void Insert(Object obj) { Rectangle r = new Rectangle(obj._pos_x, obj._pos_y, obj._width, obj._height); if (LeftBot == null) { CreateSubNode(); } if (LeftTop != null && LeftTop.rec.Contains(r)) { LeftTop.Insert(obj); return; } if (RightTop != null && RightTop.rec.Contains(r)) { RightTop.Insert(obj); return; } if (LeftBot != null && LeftBot.rec.Contains(r)) { LeftBot.Insert(obj); return; } if (RightBot != null && RightBot.rec.Contains(r)) { RightBot.Insert(obj); return; } this.listObj.Add(obj); }