예제 #1
0
파일: QuardTree.cs 프로젝트: harryqk/Newbie
        /// <summary>
        /// 刷新
        /// </summary>
        public void Refresh(QuardTree root)
        {
            if (root == null)
            {
                root = this;
            }
            List <Rectangle> removed1 = new List <Rectangle>();
            List <Rectangle> removed2 = new List <Rectangle>();

            foreach (Rectangle rectangle in objs)
            {
                int index = GetIndex(rectangle);
                // 如果矩形不属于该象限,则将该矩形重新插入
                if (!GraphicUtil.isInner(rectangle, bound))
                {
                    if (this != root)
                    {
                        removed1.Add(rectangle);
                    }

                    // 如果矩形属于该象限 且 该象限具有子象限,则
                    // 将该矩形安插到子象限中
                }
                else if (trees.Count > 0 &&
                         index != -1)
                {
                    trees[index].Insert(rectangle);
                    removed2.Add(rectangle);
                }
            }

            for (int i = 0; i < removed1.Count; i++)
            {
                root.Insert(removed1[i]);
                objs.Remove(removed1[i]);
            }
            removed1.Clear();

            for (int i = 0; i < removed2.Count; i++)
            {
                objs.Remove(removed2[i]);
            }
            removed2.Clear();
            foreach (QuardTree quardTree in trees)
            {
                quardTree.Refresh(root);
            }
        }
예제 #2
0
파일: QuardTree.cs 프로젝트: harryqk/Newbie
        public void NarrowPhase()
        {
            foreach (Rectangle a in objs)
            {
                LinkedList <Rectangle> list = GetCheckList(a);
                foreach (Rectangle rect in list)
                {
                    if (a.collision != null &&
                        GraphicUtil.isOverlap(a, rect) &&
                        !ReferenceEquals(a, rect))
                    {
                        a.collision.onCollision();
                    }
                }
            }

            for (int i = 0; i < trees.Count; i++)
            {
                trees[i].NarrowPhase();
            }
        }