예제 #1
0
    void TriangulateCornerTerracesCliff(Vector3 first, Color firstColor, HexCell firstCell, Vector3 second, Color secondColor, HexCell secondCell, Vector3 third, Color thirdColor, HexCell thirdCell)
    {
        int second_first = Mathf.Abs(secondCell.Elevation - firstCell.Elevation);
        int third_first  = Mathf.Abs(thirdCell.Elevation - firstCell.Elevation);

        if (firstCell.Elevation != secondCell.Elevation && secondCell.Elevation != thirdCell.Elevation && thirdCell.Elevation != firstCell.Elevation)
        {
            if (HexCellConf.GetEdgeType(firstCell.Elevation, secondCell.Elevation) == HexEdgeType.Slope || HexCellConf.GetEdgeType(firstCell.Elevation, thirdCell.Elevation) == HexEdgeType.Slope)
            {
                if (second_first > third_first)
                {
                    float   b             = (1f - 1f / second_first);
                    Vector3 boundary      = Vector3.Lerp(first, second, b);
                    Color   boundaryColor = Color.Lerp(firstColor, secondColor, b);

                    Vector3 lastPos   = first;
                    Color   lastColor = firstColor;
                    for (int i = 1; i <= HexCellConf.terraceSteps; i++)
                    {
                        Vector3 v3 = HexCellConf.TerraceLerp(first, third, i, HexCellConf.terracesPerSlope);
                        Color   c3 = HexCellConf.TerraceLerpColor(firstColor, thirdColor, i, HexCellConf.terracesPerSlope);

                        AddTriangle(lastPos, boundary, v3);
                        AddTriangleColor(lastColor, boundaryColor, c3);

                        lastPos   = v3;
                        lastColor = c3;
                    }

                    lastPos   = third;
                    lastColor = thirdColor;
                    for (int i = 1; i <= HexCellConf.terraceSteps; i++)
                    {
                        Vector3 v3 = HexCellConf.TerraceLerp(third, second, i, HexCellConf.terracesPerSlope);
                        Color   c3 = HexCellConf.TerraceLerpColor(thirdColor, secondColor, i, HexCellConf.terracesPerSlope);

                        AddTriangle(boundary, v3, lastPos);
                        AddTriangleColor(boundaryColor, c3, lastColor);

                        lastPos   = v3;
                        lastColor = c3;
                    }
                }
                else
                {
                    float   b             = (1f - 1f / third_first);
                    Vector3 boundary      = Vector3.Lerp(first, third, b);
                    Color   boundaryColor = Color.Lerp(firstColor, thirdColor, b);

                    Vector3 lastPos   = first;
                    Color   lastColor = firstColor;
                    for (int i = 1; i <= HexCellConf.terraceSteps; i++)
                    {
                        Vector3 v3 = HexCellConf.TerraceLerp(first, second, i, HexCellConf.terracesPerSlope);
                        Color   c3 = HexCellConf.TerraceLerpColor(firstColor, secondColor, i, HexCellConf.terracesPerSlope);

                        AddTriangle(boundary, lastPos, v3);
                        AddTriangleColor(boundaryColor, lastColor, c3);

                        lastPos   = v3;
                        lastColor = c3;
                    }

                    lastPos   = second;
                    lastColor = secondColor;
                    for (int i = 1; i <= HexCellConf.terraceSteps; i++)
                    {
                        Vector3 v3 = HexCellConf.TerraceLerp(second, third, i, HexCellConf.terracesPerSlope);
                        Color   c3 = HexCellConf.TerraceLerpColor(secondColor, thirdColor, i, HexCellConf.terracesPerSlope);

                        AddTriangle(boundary, lastPos, v3);
                        AddTriangleColor(boundaryColor, lastColor, c3);

                        lastPos   = v3;
                        lastColor = c3;
                    }
                }
            }
            else
            {
                if (second_first > third_first)
                {
                    float   b             = (1f - 1f / second_first);
                    Vector3 boundary      = Vector3.Lerp(first, second, b);
                    Color   boundaryColor = Color.Lerp(firstColor, secondColor, b);

                    AddTriangle(first, boundary, third);
                    AddTriangleColor(firstColor, boundaryColor, thirdColor);

                    Vector3 lastPos   = third;
                    Color   lastColor = thirdColor;
                    for (int i = 1; i <= HexCellConf.terraceSteps; i++)
                    {
                        Vector3 v3 = HexCellConf.TerraceLerp(third, second, i, HexCellConf.terracesPerSlope);
                        Color   c3 = HexCellConf.TerraceLerpColor(thirdColor, secondColor, i, HexCellConf.terracesPerSlope);

                        AddTriangle(boundary, v3, lastPos);
                        AddTriangleColor(boundaryColor, c3, lastColor);

                        lastPos   = v3;
                        lastColor = c3;
                    }
                }
                else
                {
                    float   b             = (1f - 1f / third_first);
                    Vector3 boundary      = Vector3.Lerp(first, third, b);
                    Color   boundaryColor = Color.Lerp(firstColor, thirdColor, b);

                    AddTriangle(first, second, boundary);
                    AddTriangleColor(firstColor, secondColor, boundaryColor);

                    Vector3 lastPos   = second;
                    Color   lastColor = secondColor;
                    for (int i = 1; i <= HexCellConf.terraceSteps; i++)
                    {
                        Vector3 v3 = HexCellConf.TerraceLerp(second, third, i, HexCellConf.terracesPerSlope);
                        Color   c3 = HexCellConf.TerraceLerpColor(secondColor, thirdColor, i, HexCellConf.terracesPerSlope);

                        AddTriangle(boundary, lastPos, v3);
                        AddTriangleColor(boundaryColor, lastColor, c3);

                        lastPos   = v3;
                        lastColor = c3;
                    }
                }
            }
        }
        else
        {
            if ((secondCell.Elevation > thirdCell.Elevation && secondCell.Elevation > firstCell.Elevation) || (secondCell.Elevation < thirdCell.Elevation && secondCell.Elevation < firstCell.Elevation))
            {
                TriangulateEdgeTerracesTriangle(third, thirdColor, thirdCell, first, firstColor, firstCell, second, secondColor, secondCell);
            }
            else if ((thirdCell.Elevation > secondCell.Elevation && thirdCell.Elevation > firstCell.Elevation) || (thirdCell.Elevation < secondCell.Elevation && thirdCell.Elevation < firstCell.Elevation))
            {
                TriangulateEdgeTerracesTriangle(first, firstColor, firstCell, second, secondColor, secondCell, third, thirdColor, thirdCell);
            }
            else
            {
                TriangulateEdgeTerracesTriangle(second, secondColor, secondCell, third, thirdColor, thirdCell, first, firstColor, firstCell);
            }
        }
    }
예제 #2
0
 public HexEdgeType GetEdgeType(HexDirection direction)
 {
     return(HexCellConf.GetEdgeType(elevation, neighbors[(int)direction].elevation));
 }