3-16 Slope-Cliff类型镜像组合

  在上一章中,我们完成了Slope-Cliff类型三角形连接区域的构建,在这一章中,我们将完成Slope-Cliff类型的镜像组合中,三角形连接区域的构建。如下图所示:

  这部分所使用到的代码,我们可以参考构建Slope-Cliff类型三角形连接区域所用到的代码。只不过构建三角形时,顺序有所不同。我们创建一个新的TriangulateCornerCliffTerraces方法,其内部代码与TriangulateCornerTerracesCliff相似,只是调整了参数顺序。代码如下:

HexMesh.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/// <summary>
/// 针对Slope-Cliff连接 镜像 类型 创建三角形连接区域
/// </summary>
/// <param name="begin">初始cell位置</param>
/// <param name="beginCell">初始cell实例</param>
/// <param name="left">左侧cell位置</param>
/// <param name="leftCell">左侧cell实例</param>
/// <param name="right">右侧cell位置</param>
/// <param name="rightCell">右侧cell实例</param>
private void TriangulateCornerCliffTerraces(
Vector3 begin, HexCell beginCell,
Vector3 left, HexCell leftCell,
Vector3 right, HexCell rightCell)
{
float b = 1f / (leftCell.Elevation - beginCell.Elevation);
Vector3 boundary = Vector3.Lerp(begin, left, b);
Color boundaryColor = Color.Lerp(beginCell.color, leftCell.color, b);

TriangulateBoundaryTriangle(right, rightCell, begin, beginCell, boundary, boundaryColor);

if (leftCell.GetEdgeType(rightCell) == HexEdgeType.Slope)
{
TriangulateBoundaryTriangle(left, leftCell, right, rightCell, boundary, boundaryColor);
}
else
{
AddTriangle(left, right, boundary);
AddTriangleColor(leftCell.color, rightCell.color, boundaryColor);
}
}

  完成镜像的方法后,我们只需要在``方法中判断并调用即可,代码如下:

HexMesh.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
private void TriangulateCorner(
Vector3 bottom, HexCell bottomCell,
Vector3 left, HexCell leftCell,
Vector3 right, HexCell rightCell)
{



if (rightEdgeType == HexEdgeType.Slope)
{
if (leftEdgeType == HexEdgeType.Flat)
{
TriangulateCornerTerraces(right, rightCell, bottom, bottomCell, left, leftCell);
return;
}

//Slope-Cliff连接 镜像 类型
//bottom最低,right比bottom高1,left比right高1及以上
TriangulateCornerCliffTerraces(bottom, bottomCell, left, leftCell, right, rightCell);
return;
}


}

  这样,我们就完成了Slope-Cliff类型及其镜像的三角形连接区域构建。在接下来的章节中,我们将完成最后一种连接类型,即最低的地图单元,和其他两个地图单元的高度差都大于1的情况。

Github代码