Beispiel #1
0
    public bool Split()
    {
        float            hsplitRoll      = URandom.value;
        BSPGeneratorData bspData         = context.BSPData;
        bool             horizontalSplit = hsplitRoll < bspData.HorizontalSplitChance;
        float            hRatio          = area.Width / (float)area.Height;
        float            vRatio          = 1 / hRatio;

        if (hRatio >= 1.0f + bspData.VerticalSplitRatio)
        {
            horizontalSplit = false;
        }
        else if (vRatio > 1.0f + bspData.HorizontalSplitRatio)
        {
            horizontalSplit = true;
        }

        int maxSize = 0;
        int minSize = 0;

        if (horizontalSplit)
        {
            maxSize = area.Height - bspData.MinAreaSize.x;
            minSize = bspData.MinAreaSize.x;
        }
        else
        {
            maxSize = area.Width - bspData.MinAreaSize.y;
            minSize = bspData.MinAreaSize.x;
        }

        if (maxSize <= minSize)
        {
            return(false);
        }

        int splitValue = URandom.Range(minSize, maxSize + 1);

        left         = new BSPNode();
        left.context = context;

        right         = new BSPNode();
        right.context = context;

        if (horizontalSplit)
        {
            left.area  = new BSPRect(area.Row, area.Col, splitValue, area.Width);
            right.area = new BSPRect(area.Row + splitValue, area.Col, area.Height - splitValue, area.Width);
        }
        else
        {
            left.area  = new BSPRect(area.Row, area.Col, area.Height, splitValue);
            right.area = new BSPRect(area.Row, area.Col + splitValue, area.Height, area.Width - splitValue);
        }

        left.Split();
        right.Split();
        return(true);
    }
Beispiel #2
0
    public static void Split_CreatesTwoChildNodes()
    {
        var node = new BSPNode();

        node.Split();

        Assert.NotNull(node.leftChild_);
        Assert.NotNull(node.rightChild_);
    }
Beispiel #3
0
    private void splitBSPNode(BSPNode node)
    {
        bool split = node.width > maxNodeSize || node.height > maxNodeSize || Random.value > 0.25f;

        if (split && node.Split())
        {
            splitBSPNode(node.leftChild);
            splitBSPNode(node.rightChild);
        }
        else
        {
            nodes.Add(node);
        }
    }
Beispiel #4
0
    public static void Split_ChildNode_AlwaysHasSibling()
    {
        var node = new BSPNode();

        node.Split();
    }