diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-01-13 19:38:11 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-01-13 19:43:19 +0000 |
commit | b3d75fe53ec3f7766e4ee6e35bfccd99c1ef9eed (patch) | |
tree | 73153d2d7facf8072481a43df9168fa9b8fdfb76 /game/geoData.cpp | |
parent | Fix up includes (diff) | |
download | ilt-b3d75fe53ec3f7766e4ee6e35bfccd99c1ef9eed.tar.bz2 ilt-b3d75fe53ec3f7766e4ee6e35bfccd99c1ef9eed.tar.xz ilt-b3d75fe53ec3f7766e4ee6e35bfccd99c1ef9eed.zip |
Progressive constructors for RayTracer
Diffstat (limited to 'game/geoData.cpp')
-rw-r--r-- | game/geoData.cpp | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp index 2028937..25c7131 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -99,28 +99,33 @@ GeoData::positionAt(const glm::vec2 wcoord) const return wcoord || heightMid; } -GeoData::RayTracer::RayTracer(glm::vec2 p0, glm::vec2 p1) : p {glm::floor(p0)}, d {glm::abs(p1)} +GeoData::RayTracer::RayTracer(glm::vec2 p0, glm::vec2 p1) : RayTracer {p0, p1, glm::abs(p1)} { } +GeoData::RayTracer::RayTracer(glm::vec2 p0, glm::vec2 p1, glm::vec2 d) : + RayTracer {p0, d, byAxis(p0, p1, d, 0), byAxis(p0, p1, d, 1)} { - using Limits = std::numeric_limits<typename glm::vec2::value_type>; - static_assert(Limits::has_infinity); +} - auto byAxis = [this, p0, p1](auto axis) { - if (d[axis] == 0) { - inc[axis] = 0; - return Limits::infinity(); - } - else if (p1[axis] > 0) { - inc[axis] = 1; - return (std::floor(p0[axis]) + 1.F - p0[axis]) * d[1 - axis]; - } - else { - inc[axis] = -1; - return (p0[axis] - std::floor(p0[axis])) * d[1 - axis]; - } - }; +GeoData::RayTracer::RayTracer( + glm::vec2 p0, glm::vec2 d_, std::pair<float, float> xdata, std::pair<float, float> ydata) : + p {glm::floor(p0)}, + d {d_}, error {xdata.second - ydata.second}, inc {xdata.first, ydata.first} +{ +} - error = byAxis(0); - error -= byAxis(1); +std::pair<float, float> +GeoData::RayTracer::byAxis(glm::vec2 p0, glm::vec2 p1, glm::vec2 d, glm::length_t axis) +{ + using Limits = std::numeric_limits<typename glm::vec2::value_type>; + static_assert(Limits::has_infinity); + if (d[axis] == 0) { + return {0, Limits::infinity()}; + } + else if (p1[axis] > 0) { + return {1, (std::floor(p0[axis]) + 1.F - p0[axis]) * d[1 - axis]}; + } + else { + return {-1, (p0[axis] - std::floor(p0[axis])) * d[1 - axis]}; + } } glm::vec2 |