summaryrefslogtreecommitdiff
path: root/game/geoData.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-02-12 20:40:20 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-02-12 20:40:20 +0000
commite0c5affab138cdc35074d66d641dae2dba1ab3f1 (patch)
tree7ed4f2042f01bcef981b75618fe3d4f86650b511 /game/geoData.cpp
parentAdd materializeRange override for naked iterator pair (diff)
downloadilt-e0c5affab138cdc35074d66d641dae2dba1ab3f1.tar.bz2
ilt-e0c5affab138cdc35074d66d641dae2dba1ab3f1.tar.xz
ilt-e0c5affab138cdc35074d66d641dae2dba1ab3f1.zip
Create flat GeoData as 10m squares instead of one big square
Diffstat (limited to 'game/geoData.cpp')
-rw-r--r--game/geoData.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp
index b30a35b..49cf892 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -62,6 +62,8 @@ GeoData::loadFromAsciiGrid(const std::filesystem::path & input)
return mesh;
};
+template<typename T> constexpr static T GRID_SIZE = 10'000;
+
GeoData
GeoData::createFlat(GlobalPosition2D lower, GlobalPosition2D upper, GlobalDistance h)
{
@@ -70,11 +72,29 @@ GeoData::createFlat(GlobalPosition2D lower, GlobalPosition2D upper, GlobalDistan
mesh.lowerExtent = {lower, h};
mesh.upperExtent = {upper, h};
- const auto ll = mesh.add_vertex({lower.x, lower.y, h}), lu = mesh.add_vertex({lower.x, upper.y, h}),
- ul = mesh.add_vertex({upper.x, lower.y, h}), uu = mesh.add_vertex({upper.x, upper.y, 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>) {
+ vertices.push_back(mesh.add_vertex({col, row, h}));
+ }
+ }
- mesh.add_face(ll, uu, lu);
- mesh.add_face(ll, ul, uu);
+ 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) {
+ mesh.add_face({
+ vertices[ncols * (row - 1) + (col - 1)],
+ vertices[ncols * (row - 0) + (col - 0)],
+ vertices[ncols * (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)],
+ });
+ }
+ }
mesh.update_vertex_normals_only();