private void TriangulateWithRiverBeginOrEnd(HexDirection direction, HexCell cell, Vector3 centre, EdgeVertices e) { var m = new EdgeVertices( Vector3.Lerp(centre, e.v1, 0.5f), Vector3.Lerp(centre, e.v5, 0.5f)); m.v3.y = e.v3.y; TriangulateEdgeStrip(m, weights1, cell.Index, e, weights1, cell.Index); TriangulateEdgeFan(centre, m, cell.Index); var reversed = cell.HasIncomingRiver; var indices = new Vector3(cell.Index, cell.Index, cell.Index); TriangulateRiverQuad(m.v2, m.v4, e.v2, e.v4, cell.RiverSurfaceY, 0.6f, reversed, indices); centre.y = m.v2.y = m.v4.y = cell.RiverSurfaceY; Rivers.AddTriangle(centre, m.v2, m.v4); if (reversed) { Rivers.AddTriangleUV(new Vector2(0.5f, 0.4f), new Vector2(1f, 0.2f), new Vector2(0f, 0.2f)); } else { Rivers.AddTriangleUV(new Vector2(0.5f, 0.4f), new Vector2(0f, 0.6f), new Vector2(1f, 0.6f)); } Rivers.AddTriangleCellData(indices, weights1); }
void TriangulateWithRiverBeginOrEnd(HexDirection direction, HexCell cell) { var center = cell.Center; var closerEdge = cell.Edges[(int)direction]; if (cell.HasRiverThroughEdge(direction.Next())) { if (cell.HasRiverThroughEdge(direction.Previous())) { center += HexMetrics.GetSolidEdgeMiddle(direction) * (HexMetrics.InnerToOuter * 0.5f); } else if (cell.HasRiverThroughEdge(direction.Previous2())) { center += HexMetrics.GetLeftSolidCorner(direction) * 0.25f; } } else if (cell.HasRiverThroughEdge(direction.Previous()) && cell.HasRiverThroughEdge(direction.Next2())) { center += HexMetrics.GetRightSolidCorner(direction) * 0.25f; } var m = new EdgeVertices(Vector3.Lerp(center, closerEdge.V1, 0.5f), Vector3.Lerp(center, closerEdge.V5, 0.5f)); m.V3.y = closerEdge.V3.y; // reassign middle verticle height as it is ommited in the calculation above TriangulateEdgeStrip(m, cell.Color, closerEdge, cell.Color); TriangulateEdgeFan(center, m, cell.Color); // river segments are added only if the current segment is not under water if (!cell.IsUnderwater) { bool reversed = cell.HasIncomingRiver; // outer circle of the hex TriangulateRiverQuadUnperturbed(m.V2, m.V4, closerEdge.V2, closerEdge.V4, cell.RiverSurfaceY, 0.6f, reversed); // end (or start) triangle center.y = m.V2.y = m.V4.y = cell.RiverSurfaceY; Rivers.AddTriangleUnperturbed(center, m.V2, m.V4); if (reversed) { Rivers.AddTriangleUV(new Vector2(0.5f, 0.4f), new Vector2(1f, 0.2f), new Vector2(0f, 0.2f)); } else { Rivers.AddTriangleUV(new Vector2(0.5f, 0.4f), new Vector2(0f, 0.6f), new Vector2(1f, 0.6f)); } } }
/// <summary> /// Creates the triangles for a side of the hexagon, with river starting or ending this side. /// </summary> void TriangulateWithRiverBeginOrEnd(HexDirection direction, HexCell cell, Vector3 center, EdgeVertices e) { // Edge 1/2 the way from edge and cell center EdgeVertices m = new EdgeVertices( Vector3.Lerp(center, e.v1, 0.5f), Vector3.Lerp(center, e.v5, 0.5f) ); m.v3.y = e.v3.y; // middle at river bed height, but not the center of the cell TriangulateEdgeStrip(m, weights1, cell.Index, e, weights1, cell.Index); TriangulateEdgeFan(center, m, cell.Index); if (!cell.IsUnderwater) // No river water surface underwater, riverbed itself is allowed // River water surface { bool reversed = cell.HasIncomingRiver; Vector3 indices; indices.x = indices.y = indices.z = cell.Index; TriangulateRiverQuad(m.v2, m.v4, e.v2, e.v4, cell.RiverSurfaceY, 0.6f, reversed, indices); // Add first/last water surface triangle for river begin/end center.y = m.v2.y = m.v4.y = cell.RiverSurfaceY; Rivers.AddTriangle(center, m.v2, m.v4); if (reversed) { Rivers.AddTriangleUV(new Vector2(0.5f, 0.4f), new Vector2(1f, 0.2f), new Vector2(0f, 0.2f)); } else { Rivers.AddTriangleUV(new Vector2(0.5f, 0.4f), new Vector2(0f, 0.6f), new Vector2(1f, 0.6f)); } Rivers.AddTriangleCellData(indices, weights1); } }