summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
Diffstat (limited to 'game')
-rw-r--r--game/geoData.cpp43
-rw-r--r--game/geoData.h4
2 files changed, 28 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
diff --git a/game/geoData.h b/game/geoData.h
index 2a1c8bd..b16aed7 100644
--- a/game/geoData.h
+++ b/game/geoData.h
@@ -44,6 +44,10 @@ public:
glm::vec2 next();
private:
+ RayTracer(glm::vec2 p0, glm::vec2 p1, glm::vec2 d);
+ RayTracer(glm::vec2 p0, glm::vec2 d, std::pair<float, float>, std::pair<float, float>);
+ static std::pair<float, float> byAxis(glm::vec2 p0, glm::vec2 p1, glm::vec2 d, glm::length_t);
+
glm::vec2 p;
const glm::vec2 d;
float error;