From c463bce75418a145d319f214571e30df311ff8df Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Nov 2023 12:14:59 +0000 Subject: Calculate and expose the extents of the terrain mesh --- game/terrain2.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'game/terrain2.cpp') diff --git a/game/terrain2.cpp b/game/terrain2.cpp index 105eb33..0e8b78e 100644 --- a/game/terrain2.cpp +++ b/game/terrain2.cpp @@ -24,10 +24,15 @@ TerrainMesh::loadFromAsciiGrid(const std::filesystem::path & input) std::vector vertices; vertices.reserve(ncols * nrows); TerrainMesh mesh; + mesh.lowerExtent = {xllcorner, yllcorner, std::numeric_limits::max()}; + mesh.upperExtent + = {xllcorner + (cellsize * ncols), yllcorner + (cellsize * nrows), std::numeric_limits::min()}; for (size_t row = 0; row < nrows; ++row) { for (size_t col = 0; col < ncols; ++col) { float height = 0; f >> height; + mesh.upperExtent.z = std::max(mesh.upperExtent.z, height); + mesh.lowerExtent.z = std::min(mesh.lowerExtent.z, height); vertices.push_back(mesh.add_vertex({xllcorner + (col * cellsize), yllcorner + (row * cellsize), height})); } } -- cgit v1.2.3