diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-01-05 12:25:16 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-01-05 12:25:16 +0000 |
commit | b5899aae753287805967ec5241bc0063f5c95a4d (patch) | |
tree | 80738c35effb9aa2003bdeb37e04dbeb669be90c | |
parent | Return surface face list from setHeights (diff) | |
download | ilt-b5899aae753287805967ec5241bc0063f5c95a4d.tar.bz2 ilt-b5899aae753287805967ec5241bc0063f5c95a4d.tar.xz ilt-b5899aae753287805967ec5241bc0063f5c95a4d.zip |
Include arc angle in curved terrain walk
-rw-r--r-- | game/geoData.cpp | 11 | ||||
-rw-r--r-- | game/geoData.h | 9 |
2 files changed, 12 insertions, 8 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp index 03bf85f..1a4cd3b 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -285,7 +285,7 @@ GeoData::walkUntil(const PointFace & from, const GlobalPosition2D to, Tester<Wal } void -GeoData::walk(const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Consumer<WalkStep> op) const +GeoData::walk(const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Consumer<WalkStepCurve> op) const { walkUntil(from, to, centre, [&op](const auto & fh) { op(fh); @@ -294,11 +294,9 @@ GeoData::walk(const PointFace & from, GlobalPosition2D to, GlobalPosition2D cent } void -GeoData::walkUntil(const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Tester<WalkStep> op) const +GeoData::walkUntil(const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Tester<WalkStepCurve> op) const { - WalkStep step { - .current = from.face(this), - }; + WalkStepCurve step {WalkStep {.current = from.face(this)}}; if (!step.current.is_valid()) { const auto entryEdge = findEntry(from.point, to); if (!entryEdge.is_valid()) { @@ -307,6 +305,7 @@ GeoData::walkUntil(const PointFace & from, GlobalPosition2D to, GlobalPosition2D step.current = opposite_face_handle(entryEdge); } ArcSegment arc {centre, from.point, to}; + step.angle = arc.first; while (step.current.is_valid() && !op(step)) { step.previous = step.current; for (const auto next : fh_range(step.current)) { @@ -317,7 +316,7 @@ GeoData::walkUntil(const PointFace & from, GlobalPosition2D to, GlobalPosition2D if (const auto intersect = arc.crossesLineAt(e1, e2)) { step.exitHalfedge = next; arc.ep0 = step.exitPosition = intersect.value().first; - arc.first = std::nextafter(intersect.value().second, INFINITY); + arc.first = std::nextafter(step.angle = intersect.value().second, INFINITY); break; } } diff --git a/game/geoData.h b/game/geoData.h index 2bdc60d..7e4c28f 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -70,13 +70,18 @@ public: GlobalPosition2D exitPosition {}; }; + struct WalkStepCurve : public WalkStep { + Angle angle {}; + }; + template<typename T> using Consumer = const std::function<void(const T &)> &; template<typename T> using Tester = const std::function<bool(const T &)> &; void walk(const PointFace & from, GlobalPosition2D to, Consumer<WalkStep> op) const; void walkUntil(const PointFace & from, GlobalPosition2D to, Tester<WalkStep> op) const; - void walk(const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Consumer<WalkStep> op) const; - void walkUntil(const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Tester<WalkStep> op) const; + void walk(const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Consumer<WalkStepCurve> op) const; + void walkUntil( + const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Tester<WalkStepCurve> op) const; void boundaryWalk(Consumer<HalfedgeHandle>) const; void boundaryWalk(Consumer<HalfedgeHandle>, HalfedgeHandle start) const; |