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); } }
public void RecalculateTerrain(TriCell cell, bool buildable) { Vector3 nextCorner, prevCorner; EdgeVertices edge; for (TriDirection direction = TriDirection.VERT; direction <= TriDirection.RIGHT; direction++) { Vector3 center = cell.Position, v1, v2; //entityMenu.transform.localPosition = center + new Vector3(0, 20, 0); 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; AddTriangle(nextCorner, edge.v1, edge.v2); AddTriangle(prevCorner, edge.v4, edge.v5); AddTriangle(center, edge.v2, edge.v4); AddTriangle(center, edge.v4, prevCorner); AddTriangle(center, nextCorner, edge.v2); Color c = buildable ? Color.blue : Color.red; AddTriangleColor(c); AddTriangleColor(c); AddTriangleColor(c); AddTriangleColor(c); AddTriangleColor(c); } }
void Triangulate(TriDirection direction, TriCell cell) { int inverter = 0; if (cell.inverted) { inverter = -1; } else { inverter = 1; } Vector3 center = cell.Position, v1, v2; v1 = center + inverter * TriMetrics.GetFirstSolidCorner(direction); v2 = center + inverter * TriMetrics.GetSecondSolidCorner(direction); EdgeVertices e = new EdgeVertices(v1, v2); if (cell.IsUnderwater) { TriangulateWater(center, e); } if (cell.HasRiverThroughEdge(direction)) { TriangulateWithRiver(cell, direction, center, e, cell.Color); } else { TriangulateEdgeFan(center, e, cell.Color); } if (cell.inverted) { if (direction != TriDirection.LEFT) { TriangulateConnection(direction, cell, e, inverter); } } else { if (direction == TriDirection.LEFT) { TriangulateConnection(direction, cell, e, inverter); } } }