summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-01-04 00:36:30 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-01-04 00:36:30 +0000
commitcf40f6d96f811dddcfe5b0c51c313e07848bff4c (patch)
treee6a49faa859579b6a119c29009ee90597c9c4382 /game
parentUse a test fixture suite over repeated fixture case (diff)
downloadilt-cf40f6d96f811dddcfe5b0c51c313e07848bff4c.tar.bz2
ilt-cf40f6d96f811dddcfe5b0c51c313e07848bff4c.tar.xz
ilt-cf40f6d96f811dddcfe5b0c51c313e07848bff4c.zip
Extracting finding a surround geo quad into separate function
Diffstat (limited to 'game')
-rw-r--r--game/geoData.cpp23
-rw-r--r--game/geoData.h2
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;