public void RecalculateTerrain(TriCell cell) { Vector3 nextCorner, prevCorner; EdgeVertices edge; for (TriDirection direction = TriDirection.VERT; direction <= TriDirection.RIGHT; direction++) { Vector3 center = cell.Position, v1, v2; v1 = center + (cell.inverted ? -1 : 1) * TriMetrics.GetFirstSolidCorner(direction); v2 = center + (cell.inverted ? -1 : 1) * TriMetrics.GetSecondSolidCorner(direction); edge = new EdgeVertices(v1, v2); nextCorner = (center + edge.v1) / 2f; prevCorner = (center + edge.v5) / 2f; terrainSelectionViewer.AddTriangle(nextCorner, edge.v1, edge.v2); terrainSelectionViewer.AddTriangle(prevCorner, edge.v4, edge.v5); terrainSelectionViewer.AddTriangle(center, edge.v2, edge.v4); terrainSelectionViewer.AddTriangle(center, edge.v4, prevCorner); terrainSelectionViewer.AddTriangle(center, nextCorner, edge.v2); terrainSelectionViewer.AddTriangleColor(Color.blue); terrainSelectionViewer.AddTriangleColor(Color.blue); terrainSelectionViewer.AddTriangleColor(Color.blue); terrainSelectionViewer.AddTriangleColor(Color.blue); terrainSelectionViewer.AddTriangleColor(Color.blue); } }
void TriangulateWithRiver(TriCell cell, TriDirection direction, Vector3 center, EdgeVertices edge, Color color) { Vector3 riverOffset = new Vector3(0, TriMetrics.streamBedElevationOffset - TriMetrics.waterElevationOffset, 0); Vector3 nextCorner, prevCorner; nextCorner = (center + edge.v1) / 2f; prevCorner = (center + edge.v5) / 2f; Vector3 underCenter = center, underNextCorner = nextCorner, underPrevCorner = prevCorner; underCenter.y += TriMetrics.streamBedElevationOffset; underNextCorner.y += TriMetrics.streamBedElevationOffset; underPrevCorner.y += TriMetrics.streamBedElevationOffset; EdgeVertices underEdge = edge; underEdge.v1.y += TriMetrics.streamBedElevationOffset; underEdge.v2.y += TriMetrics.streamBedElevationOffset; underEdge.v3.y += TriMetrics.streamBedElevationOffset; underEdge.v4.y += TriMetrics.streamBedElevationOffset; underEdge.v5.y += TriMetrics.streamBedElevationOffset; terrain.AddTriangle(nextCorner, edge.v1, edge.v2); terrain.AddTriangle(prevCorner, edge.v4, edge.v5); terrain.AddTriangle(underCenter, underEdge.v2, underEdge.v4); terrain.AddTriangleColor(color); terrain.AddTriangleColor(color); terrain.AddTriangleColor(color); if (!cell.IsUnderwater) { rivers.AddTriangle(underCenter - riverOffset, underEdge.v2 - riverOffset, underEdge.v4 - riverOffset); rivers.AddTriangleColor(Color.blue); } if (cell.HasRiverThroughEdge(direction.Next())) { terrain.AddTriangle(underEdge.v4, underPrevCorner, underCenter); terrain.AddTriangleColor(color); if (!cell.IsUnderwater) { rivers.AddTriangle(underEdge.v4 - riverOffset, underPrevCorner - riverOffset, underCenter - riverOffset); rivers.AddTriangleColor(Color.blue); } terrain.AddQuad(underPrevCorner, prevCorner, underEdge.v4, edge.v4); terrain.AddQuadColor(color, color); } else { terrain.AddTriangle(center, edge.v4, prevCorner); terrain.AddQuad(underCenter, center, underEdge.v4, edge.v4); terrain.AddTriangleColor(color); terrain.AddQuadColor(color, color); } if (cell.HasRiverThroughEdge(direction.Previous())) { terrain.AddTriangle(underEdge.v2, underCenter, underNextCorner); terrain.AddTriangleColor(color); if (!cell.IsUnderwater) { rivers.AddTriangle(underEdge.v2 - riverOffset, underCenter - riverOffset, underNextCorner - riverOffset); rivers.AddTriangleColor(Color.blue); } terrain.AddQuad(underEdge.v2, edge.v2, underNextCorner, nextCorner); terrain.AddQuadColor(color, color); } else { terrain.AddTriangle(center, nextCorner, edge.v2); terrain.AddQuad(underEdge.v2, edge.v2, underCenter, center); terrain.AddTriangleColor(color); terrain.AddQuadColor(color, color); } }