Example #1
0
        /// <summary>
        /// Creates sub-nodes for the node.
        /// </summary>
        protected internal void CreateSubNodes()
        {
            var subBoundsSize = Bounds.size * .5f;

            if (subBoundsSize.x < TreeRoot.MinimumPossibleNodeSize ||
                subBoundsSize.z < TreeRoot.MinimumPossibleNodeSize)
            {
                // new sub-node bounds are too small
                return;
            }

            var centerOffset = subBoundsSize * .5f;

            // top left node [-x +z]
            centerOffset.x *= -1f;
            SubNodes.Insert((int)IntraLocation.UPPER_LEFT, new TNode()
            {
                TreeRoot   = TreeRoot,
                ParentNode = (TNode)this,
                Bounds     = new Bounds(Bounds.center + centerOffset, subBoundsSize),
            });

            // top right node [+x +z]
            centerOffset.x *= -1f;
            SubNodes.Insert((int)IntraLocation.UPPER_RIGHT, new TNode()
            {
                TreeRoot   = TreeRoot,
                ParentNode = (TNode)this,
                Bounds     = new Bounds(Bounds.center + centerOffset, subBoundsSize),
            });

            // bottom right node [+x -z]
            centerOffset.z *= -1f;
            SubNodes.Insert((int)IntraLocation.LOWER_RIGHT, new TNode()
            {
                TreeRoot   = TreeRoot,
                ParentNode = (TNode)this,
                Bounds     = new Bounds(Bounds.center + centerOffset, subBoundsSize),
            });

            // bottom left node [-x -z]
            centerOffset.x *= -1f;
            SubNodes.Insert((int)IntraLocation.LOWER_LEFT, new TNode()
            {
                TreeRoot   = TreeRoot,
                ParentNode = (TNode)this,
                Bounds     = new Bounds(Bounds.center + centerOffset, subBoundsSize),
            });
        }