Ejemplo n.º 1
0
    protected override void DoFracture()
    {
        var mainQuad = new D2D_Quad();

        mainQuad.BL = new D2D_Point(0, 0);
        mainQuad.BR = new D2D_Point(width - 1, 0);
        mainQuad.TL = new D2D_Point(0, height - 1);
        mainQuad.TR = new D2D_Point(width - 1, height - 1);

        quads.Clear();
        quads.Add(mainQuad);

        for (var i = 0; i < Count; i++)
        {
            SplitLargest();
        }

        for (var i = 0; i < quads.Count; i++)
        {
            var quad  = quads[i];
            var group = D2D_SplitBuilder.CreateGroup();

            group.AddTriangle(quad.BL, quad.BR, quad.TL);
            group.AddTriangle(quad.TR, quad.TL, quad.BR);
        }
    }
Ejemplo n.º 2
0
    protected override void DoFracture()
    {
        var mainQuad = new D2D_Quad();

        mainQuad.BL = new D2D_Point(0, 0);
        mainQuad.BR = new D2D_Point(width - 1, 0);
        mainQuad.TL = new D2D_Point(0, height - 1);
        mainQuad.TR = new D2D_Point(width - 1, height - 1);

        quads.Clear();
        quads.Add(mainQuad);

        for (var i = 0; i < Count; i++)
        {
            SplitLargest();
        }

        for (var i = 0; i < quads.Count; i++)
        {
            var quad  = quads[i];
            var group = D2D_SplitBuilder.CreateGroup();

            group.AddTriangle(quad.BL, quad.BR, quad.TL);
            group.AddTriangle(quad.TR, quad.TL, quad.BR);
        }
    }
    public void Split(ref D2D_Quad first, ref D2D_Quad second, float irregularity)
    {
        if (first == null)
        {
            first = new D2D_Quad();
        }
        if (second == null)
        {
            second = new D2D_Quad();
        }

        var b = D2D_Point.DistanceSq(BL, BR);
        var t = D2D_Point.DistanceSq(TL, TR);
        var l = D2D_Point.DistanceSq(BL, TL);
        var r = D2D_Point.DistanceSq(BR, TR);

        // Vertical split
        if (b > l || b > t || t > l || t > r)
        {
            var TS = TL + (TR - TL) * Random.Range(0.5f - irregularity, 0.5f + irregularity);
            var BS = BL + (BR - BL) * Random.Range(0.5f - irregularity, 0.5f + irregularity);

            first.BL = BL;
            first.BR = BS;
            first.TL = TL;
            first.TR = TS;
            first.CalculateSize();

            second.BL = BS;
            second.BR = BR;
            second.TL = TS;
            second.TR = TR;
            second.CalculateSize();
        }
        // Horizontal split
        else
        {
            var LS = BL + (TL - BL) * Random.Range(0.5f - irregularity, 0.5f + irregularity);
            var RS = BR + (TR - BR) * Random.Range(0.5f - irregularity, 0.5f + irregularity);

            first.BL = LS;
            first.BR = RS;
            first.TL = TL;
            first.TR = TR;
            first.CalculateSize();

            second.BL = BL;
            second.BR = BR;
            second.TL = LS;
            second.TR = RS;
            second.CalculateSize();
        }
    }