diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-04-07 16:13:42 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-04-07 16:13:42 +0100 |
commit | 7d1351c2a25d71d312bf341ccab6fe6ca213023f (patch) | |
tree | b83f838d9d7e567b7d672e6e63ff716b4f74c754 /game | |
parent | Split water from terrain (diff) | |
download | ilt-7d1351c2a25d71d312bf341ccab6fe6ca213023f.tar.bz2 ilt-7d1351c2a25d71d312bf341ccab6fe6ca213023f.tar.xz ilt-7d1351c2a25d71d312bf341ccab6fe6ca213023f.zip |
Fix creating a flat terrain of exactly the requested size
Which must be a size of multiples of GRID_SIZE, 10m
Diffstat (limited to 'game')
-rw-r--r-- | game/geoData.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp index ed4303b..2313342 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -65,36 +65,36 @@ GeoData::loadFromAsciiGrid(const std::filesystem::path & input) return mesh; }; -template<typename T> constexpr static T GRID_SIZE = 10'000; +constexpr static GlobalDistance GRID_SIZE = 10'000; GeoData GeoData::createFlat(GlobalPosition2D lower, GlobalPosition2D upper, GlobalDistance h) { + assert((upper - lower) % GRID_SIZE == GlobalPosition2D {}); GeoData mesh; mesh.lowerExtent = {lower, h}; mesh.upperExtent = {upper, h}; std::vector<VertexHandle> vertices; - for (GlobalDistance row = lower.x; row < upper.x; row += GRID_SIZE<GlobalDistance>) { - for (GlobalDistance col = lower.y; col < upper.y; col += GRID_SIZE<GlobalDistance>) { + for (GlobalDistance row = lower.x; row <= upper.x; row += GRID_SIZE) { + for (GlobalDistance col = lower.y; col <= upper.y; col += GRID_SIZE) { vertices.push_back(mesh.add_vertex({col, row, h})); } } - const auto nrows = static_cast<size_t>(std::ceil(float(upper.x - lower.x) / GRID_SIZE<RelativeDistance>)); - const auto ncols = static_cast<size_t>(std::ceil(float(upper.y - lower.y) / GRID_SIZE<RelativeDistance>)); - for (size_t row = 1; row < nrows; ++row) { - for (size_t col = 1; col < ncols; ++col) { + const auto n = glm::vec<2, size_t> {((upper - lower) / GRID_SIZE) + 1}; + for (auto row = 1U; row < n.x; ++row) { + for (auto col = 1U; col < n.y; ++col) { mesh.add_face({ - vertices[ncols * (row - 1) + (col - 1)], - vertices[ncols * (row - 0) + (col - 0)], - vertices[ncols * (row - 0) + (col - 1)], + vertices[n.y * (row - 1) + (col - 1)], + vertices[n.y * (row - 0) + (col - 0)], + vertices[n.y * (row - 0) + (col - 1)], }); mesh.add_face({ - vertices[ncols * (row - 1) + (col - 1)], - vertices[ncols * (row - 1) + (col - 0)], - vertices[ncols * (row - 0) + (col - 0)], + vertices[n.y * (row - 1) + (col - 1)], + vertices[n.y * (row - 1) + (col - 0)], + vertices[n.y * (row - 0) + (col - 0)], }); } } |