From 381caebb524a5bb8f091d1aa2ca02d384e010961 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 7 Jan 2024 17:13:38 +0000 Subject: Global positions in network data --- game/network/link.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'game/network/link.cpp') diff --git a/game/network/link.cpp b/game/network/link.cpp index e8eaea2..dc9aecc 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -1,5 +1,4 @@ #include "link.h" -#include #include #include #include @@ -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(es.first->pos.z - centreBase.z) + + (static_cast(es.second->pos.z - es.first->pos.z) * frac)}}; + const auto pitch {vector_pitch({0, 0, static_cast(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,13 @@ LinkCurve::intersectRay(const Ray & 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 {Position2D {arc_length(arc), e1p.z - e0p.z} / segs}; auto segCount = static_cast(std::lround(segs)) + 1; std::vector 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 (Position2D 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); } -- cgit v1.2.3 From 067ecf8d6dfc9ecf002d3cc92ce7d1574d095ddc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 7 Jan 2024 17:29:21 +0000 Subject: Remove PositionxD from Network --- game/network/link.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'game/network/link.cpp') diff --git a/game/network/link.cpp b/game/network/link.cpp index dc9aecc..932fc67 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -63,12 +63,13 @@ LinkCurve::intersectRay(const Ray & 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 {Position2D {arc_length(arc), e1p.z - e0p.z} / segs}; + const auto step {glm::vec<2, RelativeDistance> {arc_length(arc), e1p.z - e0p.z} / segs}; auto segCount = static_cast(std::lround(segs)) + 1; std::vector points; points.reserve(segCount); - for (Position2D swing = {arc.first, centreBase.z - e0p.z}; segCount; swing += step, --segCount) { + for (std::remove_const_t 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); -- cgit v1.2.3