private void InitLooseQuadtree() { if (autoConfig) { qt = LooseQuadTree <BoidBase> .NewTree(sets.bounds.width, sets.bounds.height, 2); } else { qt = new LooseQuadTree <BoidBase>(sets.bounds.width, sets.bounds.height, elementsPerQuad, maxDepth); } Boid.qt = qt; for (int i = 0; i < sets.testElements; ++i) { Vector3Int pos = new Vector3Int(r.Next(sets.bounds.width), 0, r.Next(sets.bounds.height)); GameObject go = Instantiate(boidPrefab, pos, Quaternion.identity); go.TryGetComponent(out Boid b); b.Init(); UnityEngine.Profiling.Profiler.BeginSample("Insert boids"); b.index_TEMP = ((LooseQuadTree <BoidBase>)qt).BulkInsertPoint(b, b.X, b.Y, b.Width, b.Height); UnityEngine.Profiling.Profiler.EndSample(); ++entityCount; } }
private void Split() { float x = m_bound.center.x; float y = m_bound.center.y; float s = m_baseSize / 2; float h = s / 2; float actLen = s * m_loose; m_children = new LooseQuadTree <T> [4]; m_children[k_TR] = new LooseQuadTree <T>(new QuadTreeBound(x + h, y + h, actLen), s, m_loose, m_capacity, m_minSize); m_children[k_TL] = new LooseQuadTree <T>(new QuadTreeBound(x - h, y + h, actLen), s, m_loose, m_capacity, m_minSize); m_children[k_BL] = new LooseQuadTree <T>(new QuadTreeBound(x - h, y - h, actLen), s, m_loose, m_capacity, m_minSize); m_children[k_BR] = new LooseQuadTree <T>(new QuadTreeBound(x + h, y - h, actLen), s, m_loose, m_capacity, m_minSize); }
void DrawRect(LooseQuadTree <Vector2> tree, int level, int childIndex) { if ((m_showLevel < 0 || level == m_showLevel || (m_containsChildLevel && level >= m_showLevel)) && (m_showChild < 0 || m_showChild == childIndex)) { DrawRect(tree.Bound, Color.white); for (int i = 0; i < tree.Items.Count; i++) { DrawPoint(tree.Items[i].elem, Color.blue); } } if (tree.Children != null) { level++; for (int i = 0; i < tree.Children.Length; i++) { DrawRect(tree.Children[i], level, i); } } }
void Start() { m_mat = new Material(Shader.Find("Unlit/Color")); m_quadTree = new LooseQuadTree <Vector2>(new QuadTreeBound(m_maxSize, m_maxSize, m_maxSize), m_maxSize, m_loose, m_capacity, m_minSize); }