Beispiel #1
0
        public OctreeCell(OctreeCell parent,
                          Vector3 childPos,
                          float halfDimension,
                          List <OctreePoint> potentialItems,
                          int subdivisions)
        {
            Parent          = parent;
            m_position      = childPos;
            m_halfDimension = halfDimension;
            m_subdivisions  = subdivisions;

            m_bounds = new Bounds(m_position, Vector3.one * halfDimension * 2f);

            foreach (var item in potentialItems)
            {
                ProcessPoint(item);
            }
        }
Beispiel #2
0
        private void Subdivide()
        {
            if (m_subdivisions == 0)
            {
                return;
            }
            //remove this cell from all contained point
            //because it will be subdivided
            foreach (var octreePoint in ContainedPoints)
            {
                octreePoint.Cells.Remove(this);
            }

            //create upper cells
            var extents = m_bounds.extents / 2f;

            for (var i = 0; i < 4; i++)
            {
                var childPosition = m_position + extents;
                m_childCells[i] =
                    new OctreeCell(this, childPosition, m_halfDimension / 2, ContainedPoints,
                                   m_subdivisions - 1);
                extents = Quaternion.Euler(0f, -90f, 0f) * extents;
            }

            //create lower cells
            extents   = m_bounds.extents / 2f;
            extents.y = -extents.y;

            for (var i = 4; i < 8; i++)
            {
                var childPosition = m_position + extents;
                m_childCells[i] =
                    new OctreeCell(this, childPosition, m_halfDimension / 2, ContainedPoints,
                                   m_subdivisions - 1);
                extents = Quaternion.Euler(0f, -90f, 0f) * extents;
            }

            ContainedPoints.Clear();
        }