diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-01-08 13:39:36 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-01-08 19:30:12 +0000 |
commit | c508f08ce4841eabbcaf5df7c31ff4331aa9750c (patch) | |
tree | ecf1bd2212309fd79f92f11547dcbebda2eef3e6 /game/geoData.cpp | |
parent | Have CLOG write to cerr, clog doesn't sync with Boost test output (diff) | |
download | ilt-c508f08ce4841eabbcaf5df7c31ff4331aa9750c.tar.bz2 ilt-c508f08ce4841eabbcaf5df7c31ff4331aa9750c.tar.xz ilt-c508f08ce4841eabbcaf5df7c31ff4331aa9750c.zip |
Tweak ray tracer calls to account for scale
Diffstat (limited to 'game/geoData.cpp')
-rw-r--r-- | game/geoData.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp index 4537026..32ec55e 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -95,30 +95,28 @@ GeoData::positionAt(const glm::vec2 wcoord) const return wcoord || heightMid; } -GeoData::RayTracer::RayTracer(glm::vec2 p0, glm::vec2 p1, float scale) : p {glm::floor(p0)}, d {glm::abs(p1 - p0)} +GeoData::RayTracer::RayTracer(glm::vec2 p0, glm::vec2 p1) : p {glm::floor(p0)}, d {glm::abs(p1)} { using Limits = std::numeric_limits<typename glm::vec2::value_type>; static_assert(Limits::has_infinity); - static constexpr const glm::vec2 inf {Limits::infinity(), -Limits::infinity()}; - auto byAxis = [this, p0, p1, scale](auto axis) { + auto byAxis = [this, p0, p1](auto axis) { if (d[axis] == 0) { inc[axis] = 0; - return inf[axis]; + return Limits::infinity(); } - else if (p1[axis] > p0[axis]) { - inc[axis] = scale; - return (std::floor(p0[axis]) + 1 - p0[axis]) * d[1 - axis]; + else if (p1[axis] > 0) { + inc[axis] = 1; + return (std::floor(p0[axis]) + 1.F - p0[axis]) * d[1 - axis]; } else { - inc[axis] = -scale; + inc[axis] = -1; return (p0[axis] - std::floor(p0[axis])) * d[1 - axis]; } }; error = byAxis(0); error -= byAxis(1); - inc.z = scale; } glm::vec2 @@ -129,7 +127,7 @@ GeoData::RayTracer::next() static constexpr const glm::vec2 m {1, -1}; const int axis = (error > 0) ? 1 : 0; p[axis] += inc[axis]; - error += d[1 - axis] * m[axis] * inc.z; + error += d[1 - axis] * m[axis]; return cur; } |