示例#1
0
        public FourNodeBounds Subdivide()
        {
            FourNodeBounds bounds = new FourNodeBounds();

            var extents = Extents;

            bounds.Bl = new NodeBounds
            {
                min = min,
                max = min + extents
            };

            bounds.Tl     = new NodeBounds();
            bounds.Tl.min = new float2(min.x, min.y + extents.y);
            bounds.Tl.max = bounds.Tl.min + extents;


            bounds.Br     = new NodeBounds();
            bounds.Br.min = new float2(min.x + extents.x, min.y);
            bounds.Br.max = bounds.Br.min + extents;

            bounds.Tr     = new NodeBounds();
            bounds.Tr.min = new float2(min.x + extents.x, min.y + extents.y);
            bounds.Tr.max = max;

            return(bounds);
        }
示例#2
0
        private bool BuildNode(int nodeId)
        {
            Node node = m_Nodes[nodeId];

            if (IsLeaf(node))
            {
                node.IsLeaf     = true;
                m_Nodes[nodeId] = node;
                return(false);
            }

            FourNodeBounds fourBounds = node.Bounds.Subdivide();

            if (node.NumValidChildren() != 4)
            {
                int4 data = new int4();
                data.x    = AddNode(fourBounds.Bl);
                data.y    = AddNode(fourBounds.Tl);
                data.z    = AddNode(fourBounds.Br);
                data.w    = AddNode(fourBounds.Tr);
                node.Data = data;
            }
            else
            {
                SetBounds(node.Data.x, fourBounds.Bl);
                SetBounds(node.Data.y, fourBounds.Tl);
                SetBounds(node.Data.z, fourBounds.Br);
                SetBounds(node.Data.w, fourBounds.Tr);
            }

            m_Nodes[nodeId] = node;

            for (int i = 0; i < 4; i++)
            {
                BuildNode(node.Data[i]);
            }

            return(true);
        }