private void TriangulateCorner( Vector3 bottom, VoronoiCell bottomCell, Vector3 left, VoronoiCell leftCell, Vector3 right, VoronoiCell rightCell) { VoronoiEdgeType leftEdgeType = bottomCell.GetEdgeType(leftCell); VoronoiEdgeType rightEdgeType = bottomCell.GetEdgeType(rightCell); if (leftEdgeType == VoronoiEdgeType.Slope) { if (rightEdgeType == VoronoiEdgeType.Slope) { TriangulateCornerTerraces(bottom, bottomCell, left, leftCell, right, rightCell); } else if (rightEdgeType == VoronoiEdgeType.Flat) { TriangulateCornerTerraces(left, leftCell, right, rightCell, bottom, bottomCell); } else { TriangulateCornerTerracesCliff(bottom, bottomCell, left, leftCell, right, rightCell); } } else if (rightEdgeType == VoronoiEdgeType.Slope) { if (leftEdgeType == VoronoiEdgeType.Flat) { TriangulateCornerTerraces(right, rightCell, bottom, bottomCell, left, leftCell); } else { TriangulateCornerCliffTerraces(bottom, bottomCell, left, leftCell, right, rightCell); } } else if (leftCell.GetEdgeType(rightCell) == VoronoiEdgeType.Slope) { if (leftCell.Elevation < rightCell.Elevation) { TriangulateCornerCliffTerraces(right, rightCell, bottom, bottomCell, left, leftCell); } else { TriangulateCornerTerracesCliff(left, leftCell, right, rightCell, bottom, bottomCell); } } else { Terrain.AddTriangle(bottom, left, right); Terrain.AddTriangleColor(bottomCell.Color, leftCell.Color, rightCell.Color); } }
private void TriangulateConnection(VoronoiCell cell, VoronoiDirection direction, EdgeVertices e1) { VoronoiCell neighbor = cell.GetNeighbor(direction); Vector3 bridge = VoronoiMetrics.GetBridge(cell, direction); EdgeVertices e2 = new EdgeVertices( e1.V1 + bridge, e1.V5 + bridge ); if (cell.HasRiverThroughEdge(direction)) { e2.V3 = Vector3.ClampMagnitude(e2.V3, neighbor.StreamBedElevation); TriangulateRiverQuad(e1.V2, e1.V4, e2.V2, e2.V4, cell.RiverSurfaceElevation, neighbor.RiverSurfaceElevation, 0.8f, cell.HasIncomingRiver && cell.IncomingRiver == direction ); } if (cell.GetEdgeType(direction) == VoronoiEdgeType.Slope) { TriangulateEdgeTerraces(e1, cell, e2, neighbor, cell.HasRoadThroughEdge(direction)); } else { TriangulateEdgeStrip(e1, cell.Color, e2, neighbor.Color, cell.HasRoadThroughEdge(direction)); } VoronoiCell nextNeighbor = cell.GetNeighbor(direction.Next(cell)); if (cell.CornerConnections.Contains(direction)) { Vector3 v5 = e1.V5 + VoronoiMetrics.GetBridge(cell, direction.Next(cell)); if (cell.Elevation <= neighbor.Elevation) { if (cell.Elevation <= nextNeighbor.Elevation) { TriangulateCorner(e1.V5, cell, e2.V5, neighbor, v5, nextNeighbor); } else { TriangulateCorner(v5, nextNeighbor, e1.V5, cell, e2.V5, neighbor); } } else if (neighbor.Elevation <= nextNeighbor.Elevation) { TriangulateCorner(e2.V5, neighbor, v5, nextNeighbor, e1.V5, cell); } else { TriangulateCorner(v5, nextNeighbor, e1.V5, cell, e2.V5, neighbor); } } }
private void TriangulateCornerCliffTerraces( Vector3 begin, VoronoiCell beginCell, Vector3 left, VoronoiCell leftCell, Vector3 right, VoronoiCell rightCell) { float b = 1f / (leftCell.Elevation - beginCell.Elevation); b = b < 0 ? -b : b; Vector3 boundary = Vector3.Lerp(VoronoiMetrics.Perturb(begin), VoronoiMetrics.Perturb(left), b); Color boundaryColor = Color.Lerp(beginCell.Color, leftCell.Color, b); TriangulateBoundaryTriangle(right, rightCell, begin, beginCell, boundary, boundaryColor); if (leftCell.GetEdgeType(rightCell) == VoronoiEdgeType.Slope) { TriangulateBoundaryTriangle(left, leftCell, right, rightCell, boundary, boundaryColor); } else { Terrain.AddTriangleUnperturbed(VoronoiMetrics.Perturb(left), VoronoiMetrics.Perturb(right), boundary); Terrain.AddTriangleColor(leftCell.Color, rightCell.Color, boundaryColor); } }