Example #1
0
 public void export(QuadNode node, List<System.Text.StringBuilder> result)
 {
     //List<string> _Result = new List<string>();
     System.Text.StringBuilder item = new System.Text.StringBuilder("");
     item.Append(String.Format("{0}\t{1}\t{2}\t{3}\t{4}",
                             node._id.ToString().Trim(),
                             node._bounds.X.ToString().Trim(),
                             node._bounds.Y.ToString().Trim(),
                             node._bounds.Width.ToString().Trim(),
                             node._bounds.Height.ToString().Trim()));
     if (node._nodeBL != null)
     {
         export(node._nodeBL, result);
         export(node._nodeBR, result);
         export(node._nodeTL, result);
         export(node._nodeTR, result);
     }
     else
     {
         for (int i = 0; i < node._listObject.Count;++i )
         {
             item.Append( "\t" + node._listObject[i]._id.ToString().Trim());
         }
     }
     result.Add(item);
 }
Example #2
0
        public void buildQuadNode(List<GameObject> listObject)
        {
            //if (Rectangle.Intersect(this.m_Bounds, _obj.m_Bounds).Height == 0) //Kiểm tra bounds của Object và Node có tiếp xúc không
            //    return;
            if (listObject.Count == 0)
                return;
            if (this._bounds.Height > MIN_SIZE_OF_NODE ) //  Kiểm tra kích thước node có vượt giới hạn hay không
            {
                _nodeTL = new QuadNode(this._id * 8 + 1, new Rectangle(this._bounds.X, this._bounds.Y, this._bounds.Width / 2, this._bounds.Height / 2));
                _nodeTR = new QuadNode(this._id * 8 + 2, new Rectangle(this._bounds.X + this._bounds.Width / 2, this._bounds.Y, this._bounds.Width / 2, this._bounds.Height / 2));
                _nodeBL = new QuadNode(this._id * 8 + 3, new Rectangle(this._bounds.X, this._bounds.Y + this._bounds.Height / 2, this._bounds.Width / 2, this._bounds.Height / 2));
                _nodeBR = new QuadNode(this._id * 8 + 4, new Rectangle(this._bounds.X + this._bounds.Width / 2, this._bounds.Y + this._bounds.Height / 2, this._bounds.Width / 2, this._bounds.Height / 2));

                clip(listObject, _nodeTL);
                clip(listObject, _nodeTR);
                clip(listObject, _nodeBL);
                clip(listObject, _nodeBR);

                _nodeTL.buildQuadNode(_nodeTL._listObject);
                _nodeTR.buildQuadNode(_nodeTR._listObject);
                _nodeBL.buildQuadNode(_nodeBL._listObject);
                _nodeBR.buildQuadNode(_nodeBR._listObject);

                this._listObject.Clear();
            }
            else
                return; //Nếu kích thước của node <= MINSIZEOFNODE => đây là node lá
        }
Example #3
0
 public QuadTree(Rectangle bound)
 {
     this._root = new QuadNode(1, bound);
 }
Example #4
0
 public QuadTree(Rectangle bound)
 {
     this._root = new QuadNode(1, bound);
 }
Example #5
0
 public void clip(List<GameObject> listObject, QuadNode node)
 {
     foreach (GameObject objectItem in listObject)
     {
         if (Rectangle.Intersect(objectItem._bounds,node._bounds).Height != 0)
         {
             node._listObject.Add(objectItem);
         }
     }
 }