Esempio n. 1
0
        public void Insert(Rigidbody rb)
        {
            if (m_children != null)
            {
                for (int i = 0; i < 4; ++i)
                {
                    if (Intersections.DoIntersectAABBAABB(rb.ColliderData.GlobalAABB, m_children[i].f_aabb))
                    {
                        m_children[i].Insert(rb);
                    }
                }
            }
            else if (f_depth < MAX_DEPTH && f_elements.Count == MAX_ELEMENTS)
            {
                // This means I have to split the QT
                m_children = new QuadTree[4];

                m_children[0] = QuadTree.New(f_aabb.BottomLeftAABB, f_depth + 1);
                m_children[1] = QuadTree.New(f_aabb.BottomRightAABB, f_depth + 1);
                m_children[2] = QuadTree.New(f_aabb.TopLeftAABB, f_depth + 1);
                m_children[3] = QuadTree.New(f_aabb.TopRightAABB, f_depth + 1);

                for (int i = 0; i < f_elements.Count; ++i)
                {
                    Insert(f_elements[i]);
                }
                Insert(rb);
                f_elements.Clear();
                s_elementCount -= MAX_ELEMENTS;
            }
            else
            {
                if (f_elements.Count == 0)
                {
                    --s_emptyNodes;
                }
                f_elements.Add(rb);
                ++s_elementCount;
            }
        }
Esempio n. 2
0
 public QuadTreePM()
 {
     f_quadtree = QuadTree.New(2 * Level.Instance.LevelBounds + -Level.Instance.LevelBounds.Centre, 0);
 }