Exemple #1
0
        private void _InitRegion()
        {
            if (m_quadtree == null)
            {
                return;
            }
            m_lstRegions.Clear();
            //m_lstIgnore.Clear();

            m_leaves = m_quadtree.GetAllLeaves();

            for (int i = 0; i < m_leaves.Count; ++i)
            {
                QuadtreeLeaf leaf = m_leaves[i];

                CombineRegion combineRegion = new CombineRegion();
                combineRegion.Init();

                for (int j = 0, count = leaf.objects.Count; j < count; ++j)
                {
                    CombineMeshData data = new CombineMeshData(leaf.objects[j]);
                    combineRegion.AddCombineData(data);
                }
                m_lstRegions.Add(combineRegion);
            }
        }
Exemple #2
0
 public void DrawDebugLine(float fDebugLine)
 {
     for (int i = 0; i < m_leaves.Count; ++i)
     {
         QuadtreeLeaf leaf = m_leaves[i];
         if (leaf.bSelect)
         {
             DrawRect(leaf.Bound, fDebugLine, Color.red, 0.2f);
         }
         else
         {
             DrawRect(leaf.Bound, fDebugLine, Color.white, 0.2f);
         }
     }
 }
Exemple #3
0
        private void BuildRecursively(QuadtreeNode node)
        {
            float subWidth   = node.Bound.width * 0.5f;
            float subHeight  = node.Bound.height * 0.5f;
            bool  isPartible = subWidth > cellSize && subHeight > cellSize;
            // create subnodes
            QuadtreeCreateNode _nodeCreator = (bnd) => {
                return(new QuadtreeNode(bnd));
            };

            QuadtreeCreateNode _leafCreator = (bnd) => {
                QuadtreeLeaf leaf = new QuadtreeLeaf(bnd);
                m_leaves.Add(leaf);
                return(leaf);
            };

            QuadtreeCreateNode creator = isPartible ? _nodeCreator : _leafCreator;

            node.SetSubNodes(new QuadtreeNode[QuadtreeNode.SubCount]
            {
                creator(new Rect(node.Bound.xMin, node.Bound.yMin, subWidth, subHeight)),
                creator(new Rect(node.Bound.xMin + subWidth, node.Bound.yMin, subWidth, subHeight)),
                creator(new Rect(node.Bound.xMin, node.Bound.yMin + subHeight, subWidth, subHeight)),
                creator(new Rect(node.Bound.xMin + subWidth, node.Bound.yMin + subHeight, subWidth, subHeight)),
            }

                             );

            // do it recursively
            if (isPartible)
            {
                foreach (var sub in node.SubNodes)
                {
                    BuildRecursively(sub);
                }
            }
        }