private void TriangulateOpenWater(HexDirection direction, HexObject cell, HexObject neighbour, Vector3 center) { Vector3 c1 = center + HexMetrics.GetFirstWaterCorner(direction); Vector3 c2 = center + HexMetrics.GetSecondWaterCorner(direction); water.AddTriangle(center, c1, c2); if (direction <= HexDirection.SE && neighbour != null) { Vector3 bridge = HexMetrics.GetWaterBridge(direction); Vector3 e1 = c1 + bridge; Vector3 e2 = c2 + bridge; water.AddQuad(c1, c2, e1, e2); if (direction <= HexDirection.E) { HexObject nextNeighbour = cell.GetNeighbour(direction.Next()); if (nextNeighbour == null || !nextNeighbour.IsUnderwater) { return; } water.AddTriangle(c2, e2, c2 + HexMetrics.GetWaterBridge(direction.Next())); } } }
private void TriangulateWater(HexDirection direction, HexObject cell, Vector3 center) { center.y = cell.WaterSurfaceY; HexObject neighbour = cell.GetNeighbour(direction); if (neighbour != null && !neighbour.IsUnderwater) { TriangulateWaterShore(direction, cell, neighbour, center); } else { TriangulateOpenWater(direction, cell, neighbour, center); } }
private void TriangulateWaterShore(HexDirection direction, HexObject cell, HexObject neighbour, Vector3 center1) { EdgeVertices e1 = new EdgeVertices(center1 + HexMetrics.GetFirstWaterCorner(direction), center1 + HexMetrics.GetSecondWaterCorner(direction)); water.AddTriangle(center1, e1.v1, e1.v2); water.AddTriangle(center1, e1.v2, e1.v3); water.AddTriangle(center1, e1.v3, e1.v4); water.AddTriangle(center1, e1.v4, e1.v5); Vector3 center2 = neighbour.Position; center2.y = center1.y; EdgeVertices e2 = new EdgeVertices(center2 + HexMetrics.GetSecondSolidCorner(direction.Opposite()), center2 + HexMetrics.GetFirstSolidCorner(direction.Opposite())); if (cell.HasRiverThroughEdge(direction)) { TriangulateEstuary(e1, e2, cell.IncomingRiver == direction); } else { waterShore.AddQuad(e1.v1, e1.v2, e2.v1, e2.v2); waterShore.AddQuad(e1.v2, e1.v3, e2.v2, e2.v3); waterShore.AddQuad(e1.v3, e1.v4, e2.v3, e2.v4); waterShore.AddQuad(e1.v4, e1.v5, e2.v4, e2.v5); waterShore.AddQuadUV(0f, 0f, 0f, 1f); waterShore.AddQuadUV(0f, 0f, 0f, 1f); waterShore.AddQuadUV(0f, 0f, 0f, 1f); waterShore.AddQuadUV(0f, 0f, 0f, 1f); } HexObject nextNeighbor = cell.GetNeighbour(direction.Next()); if (nextNeighbor != null) { Vector3 v3 = nextNeighbor.Position + (nextNeighbor.IsUnderwater ? HexMetrics.GetFirstWaterCorner(direction.Previous()) : HexMetrics.GetFirstSolidCorner(direction.Previous())); v3.y = center1.y; waterShore.AddTriangle( e1.v5, e2.v5, v3 ); waterShore.AddTriangleUV( new Vector2(0f, 0f), new Vector2(0f, 1f), new Vector2(0f, nextNeighbor.IsUnderwater ? 0f : 1f) ); } }
private void UpdateHex(HexObject hex) { if (hex) { if (isDragging) { HexObject otherCell = hex.GetNeighbour(dragDirection.Opposite()); if (otherCell) { if (currentActionMode == ActionMode.BuildRoad) { otherCell.AddRoad(dragDirection); // TODO: Add a cost to this for gameplay } } } } }
private void TriangulateConnection(HexDirection direction, HexObject cell, EdgeVertices e1) { HexObject neighbour = cell.GetNeighbour(direction); if (neighbour == null) { return; } Vector3 bridge = HexMetrics.GetBridge(direction); bridge.y = neighbour.Position.y - cell.Position.y; EdgeVertices e2 = new EdgeVertices(e1.v1 + bridge, e1.v5 + bridge); if (cell.HasRiverThroughEdge(direction)) { if (!cell.IsUnderwater) { e2.v3.y = neighbour.StreamBedY; if (!neighbour.IsUnderwater) { TriangulateRiverQuad(e1.v2, e1.v4, e2.v2, e2.v4, cell.RiverSurfaceY, neighbour.RiverSurfaceY, 0.8f, cell.HasIncomingRiver && cell.IncomingRiver == direction); } else if (cell.Elevation > neighbour.WaterLevel) { TriangulateWaterfallInWater(e1.v2, e1.v4, e2.v2, e2.v4, cell.RiverSurfaceY, neighbour.RiverSurfaceY, neighbour.WaterSurfaceY); } } else if (!neighbour.IsUnderwater && neighbour.Elevation > cell.WaterLevel) { TriangulateWaterfallInWater(e2.v4, e2.v2, e1.v4, e1.v2, neighbour.RiverSurfaceY, cell.RiverSurfaceY, cell.WaterSurfaceY); } } if (cell.GetEdgeType(direction) == HexEdgeType.Slope) { TriangulateEdgeTerraces(e1, cell, e2, neighbour, cell.HasRoadThroughEdge(direction)); } else { TriangulateEdgeStrip(e1, cell.Color, e2, neighbour.Color, cell.HasRoadThroughEdge(direction)); } HexObject next = cell.GetNeighbour(direction.Next()); if (direction <= HexDirection.E && next != null) { Vector3 v5 = e1.v5 + HexMetrics.GetBridge(direction.Next()); v5.y = next.Position.y; if (cell.Elevation <= neighbour.Elevation) { if (cell.Elevation <= next.Elevation) { TriangulateCorner(e1.v5, cell, e2.v5, neighbour, v5, next); } else { TriangulateCorner(v5, next, e1.v5, cell, e2.v5, neighbour); } } else if (neighbour.Elevation <= next.Elevation) { TriangulateCorner(e2.v5, neighbour, v5, next, e1.v5, cell); } else { TriangulateCorner(v5, next, e1.v5, cell, e2.v5, neighbour); } } }