diff options
Diffstat (limited to 'game')
-rw-r--r-- | game/geoData.cpp | 23 | ||||
-rw-r--r-- | game/geoData.h | 2 |
2 files changed, 16 insertions, 9 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp index d66f1ed..c4a75f9 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -68,21 +68,26 @@ GeoData::loadFromImages(const std::filesystem::path & fileName, float scale_) }); } -glm::vec3 -GeoData::positionAt(const glm::vec2 wcoord) const +GeoData::Quad +GeoData::quad(glm::vec2 coord) const { - const auto coord {wcoord / scale}; const std::array<glm::vec2, 4> gridCorner { {{std::floor(coord.x), std::floor(coord.y)}, {std::floor(coord.x), std::ceil(coord.y)}, {std::ceil(coord.x), std::floor(coord.y)}, {std::ceil(coord.x), std::ceil(coord.y)}}}; - const auto point {transform_array(gridCorner, [this](const auto c) { - return nodes[at(c)].height; - })}; + return transform_array(gridCorner, [this](const auto c) { + return c || nodes[at(c)].height; + }); +} - const glm::vec2 frac = coord - gridCorner.front(); - const auto heightFloor = point[0] + ((point[2] - point[0]) * frac.x), - heightCeil = point[1] + ((point[3] - point[1]) * frac.x), +glm::vec3 +GeoData::positionAt(const glm::vec2 wcoord) const +{ + const auto coord {wcoord / scale}; + const auto point {quad(coord)}; + const glm::vec2 frac = coord - !point.front(); + const auto heightFloor = point[0].z + ((point[2].z - point[0].z) * frac.x), + heightCeil = point[1].z + ((point[3].z - point[1].z) * frac.x), heightMid = heightFloor + ((heightCeil - heightFloor) * frac.y); return wcoord || heightMid; diff --git a/game/geoData.h b/game/geoData.h index e5057c3..ffb7d64 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -11,6 +11,7 @@ public: struct Node { float height {-1.5F}; }; + using Quad = std::array<glm::vec3, 4>; using Limits = std::pair<glm::ivec2, glm::ivec2>; @@ -24,6 +25,7 @@ public: [[nodiscard]] unsigned int at(glm::ivec2) const; [[nodiscard]] unsigned int at(int x, int y) const; + [[nodiscard]] Quad quad(glm::vec2) const; [[nodiscard]] Limits getLimit() const; [[nodiscard]] glm::uvec2 getSize() const; |