diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-07 18:02:56 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-07 18:02:56 +0000 |
commit | 509c955aac687a6e8daa80906d593cb24f83c64d (patch) | |
tree | 0b551c1a26a2c08973e9dcf298f9da286687fc20 /game/network/link.cpp | |
parent | Merge branch 'template-types' (diff) | |
parent | Simplify find_arcs_radius (diff) | |
download | ilt-509c955aac687a6e8daa80906d593cb24f83c64d.tar.bz2 ilt-509c955aac687a6e8daa80906d593cb24f83c64d.tar.xz ilt-509c955aac687a6e8daa80906d593cb24f83c64d.zip |
Merge branch 'global-network'
Diffstat (limited to 'game/network/link.cpp')
-rw-r--r-- | game/network/link.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/game/network/link.cpp b/game/network/link.cpp index e8eaea2..932fc67 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -1,5 +1,4 @@ #include "link.h" -#include <compare> #include <glm/gtx/transform.hpp> #include <location.h> #include <maths.h> @@ -8,10 +7,10 @@ Link::Link(End a, End b, float l) : ends {{std::move(a), std::move(b)}}, length {l} { } -LinkCurve::LinkCurve(Position3D c, float r, Arc a) : centreBase {c}, radius {r}, arc {std::move(a)} { } +LinkCurve::LinkCurve(GlobalPosition3D c, RelativeDistance r, Arc a) : centreBase {c}, radius {r}, arc {std::move(a)} { } bool -operator<(const Position3D & a, const Position3D & b) +operator<(const GlobalPosition3D & a, const GlobalPosition3D & b) { // NOLINTNEXTLINE(hicpp-use-nullptr,modernize-use-nullptr) return std::tie(a.x, a.y, a.z) < std::tie(b.x, b.y, b.z); @@ -24,12 +23,13 @@ operator<(const Node & a, const Node & b) } Location -LinkStraight::positionAt(float dist, unsigned char start) const +LinkStraight::positionAt(RelativeDistance dist, unsigned char start) const { const auto es {std::make_pair(ends[start].node.get(), ends[1 - start].node.get())}; - const auto diff {es.second->pos - es.first->pos}; + const RelativePosition3D diff {es.second->pos - es.first->pos}; const auto dir {glm::normalize(diff)}; - return Location {es.first->pos + vehiclePositionOffset() + dir * dist, {vector_pitch(dir), vector_yaw(dir), 0}}; + return Location {es.first->pos + GlobalPosition3D(vehiclePositionOffset() + dir * dist), + {vector_pitch(dir), vector_yaw(dir), 0}}; } bool @@ -49,9 +49,11 @@ LinkCurve::positionAt(float dist, unsigned char start) const const auto ang {as.first + ((as.second - as.first) * frac)}; const auto relPos {(sincosf(ang) || 0.F) * radius}; const auto relClimb {vehiclePositionOffset() - + Position3D {0, 0, es.first->pos.z - centreBase.z + ((es.second->pos.z - es.first->pos.z) * frac)}}; - const auto pitch {vector_pitch({0, 0, (es.second->pos.z - es.first->pos.z) / length})}; - return Location {relPos + relClimb + centreBase, {pitch, normalize(ang + dirOffset[start]), 0}}; + + RelativePosition3D {0, 0, + static_cast<RelativeDistance>(es.first->pos.z - centreBase.z) + + (static_cast<RelativeDistance>(es.second->pos.z - es.first->pos.z) * frac)}}; + const auto pitch {vector_pitch({0, 0, static_cast<RelativeDistance>(es.second->pos.z - es.first->pos.z) / length})}; + return Location {GlobalPosition3D(relPos + relClimb) + centreBase, {pitch, normalize(ang + dirOffset[start]), 0}}; } bool @@ -61,15 +63,14 @@ LinkCurve::intersectRay(const Ray<GlobalPosition3D> & ray) const const auto & e1p {ends[1].node->pos}; const auto slength = round_frac(length / 2.F, 5.F); const auto segs = std::round(15.F * slength / std::pow(radius, 0.7F)); - const auto step {Position3D {arc_length(arc), e1p.z - e0p.z, slength} / segs}; - const auto trans {glm::translate(centreBase)}; + const auto step {glm::vec<2, RelativeDistance> {arc_length(arc), e1p.z - e0p.z} / segs}; auto segCount = static_cast<std::size_t>(std::lround(segs)) + 1; std::vector<GlobalPosition3D> points; points.reserve(segCount); - for (Position3D swing = {arc.first, centreBase.z - e0p.z, 0.F}; segCount; swing += step, --segCount) { - const auto t {trans * glm::rotate(half_pi - swing.x, up) * glm::translate(Position3D {radius, 0.F, swing.y})}; - points.emplace_back(t * glm::vec4 {0, 0, 0, 1}); + for (std::remove_const_t<decltype(step)> swing = {arc.first, centreBase.z - e0p.z}; segCount; + swing += step, --segCount) { + points.emplace_back(centreBase + GlobalPosition3D((sincosf(swing.x) * radius) || swing.y)); } return ray.passesCloseToEdges(points, 1.F); } |