public QuadTree(int maxDepth, int splitThreshold, AABB2D bounds) { m_MaxDepth = maxDepth; m_NodeSplitThreshold = splitThreshold; Root = new QuadNode(); Root.SetData(0, QuadNodeDirection.None, bounds); }
//结点达到分裂的限定,进行结点的分裂 private void SplitNode(QuadNode node) { AABB2D bounds = node.Bounds; Vector2 childNodeExtents = bounds.HalfExtents; QuadNode childNode = m_NodePool.Get(); childNode.SetData(node.Depth + 1, QuadNodeDirection.LB, new AABB2D(bounds.Center - childNodeExtents, childNodeExtents)); node[QuadNodeDirection.LB] = childNode; childNode = m_NodePool.Get(); childNode.SetData(node.Depth + 1, QuadNodeDirection.RB, new AABB2D(bounds.Center + new Vector2(childNodeExtents.x, -childNodeExtents.y), childNodeExtents)); node[QuadNodeDirection.RB] = childNode; childNode = m_NodePool.Get(); childNode.SetData(node.Depth + 1, QuadNodeDirection.LT, new AABB2D(bounds.Center + new Vector2(-childNodeExtents.x, childNodeExtents.y), childNodeExtents)); node[QuadNodeDirection.LT] = childNode; childNode = m_NodePool.Get(); childNode.SetData(node.Depth + 1, QuadNodeDirection.RT, new AABB2D(bounds.Center + childNodeExtents, childNodeExtents)); node[QuadNodeDirection.RT] = childNode; }