From 2e66a686cd6cf589c583060921430a94b2849e83 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 21 Dec 2024 14:10:01 +0000 Subject: Expose network link interface to define a base area of the link --- game/network/link.cpp | 35 +++++++++++++++++++++++++++++++++++ game/network/link.h | 3 +++ 2 files changed, 38 insertions(+) (limited to 'game/network') diff --git a/game/network/link.cpp b/game/network/link.cpp index 79af92a..61e8771 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -38,6 +38,20 @@ LinkStraight::intersectRay(const Ray & ray) const std::array {GlobalPosition3D {ends.front().node->pos}, GlobalPosition3D {ends.back().node->pos}}, 1000); } +std::vector +LinkStraight::getBase(RelativeDistance width) const +{ + const auto start = ends.front().node->pos; + const auto end = ends.back().node->pos; + const auto direction = (vector_normal(normalize(::difference(start, end).xy())) * width / 2.F) || 0.F; + return { + start - direction, + start + direction, + end - direction, + end + direction, + }; +} + Location LinkCurve::positionAt(float dist, unsigned char start) const { @@ -73,3 +87,24 @@ LinkCurve::intersectRay(const Ray & ray) const } return ray.passesCloseToEdges(points, 1.F); } + +std::vector +LinkCurve::getBase(RelativeDistance width) const +{ + const auto start = ends.front().node->pos; + const auto end = ends.back().node->pos; + const auto segs = std::ceil(15.F * arc.length()); + const auto step {glm::vec<2, RelativeDistance> {arc.length(), end.z - start.z} / segs}; + + auto segCount = static_cast(segs) + 1; + std::vector out; + out.reserve(segCount); + for (RelativePosition2D swing = {arc.first, centreBase.z - start.z}; segCount != 0U; swing += step, --segCount) { + const auto direction = sincos(swing.x); + const auto linkCentre = centreBase + ((direction * radius) || swing.y); + const auto toEdge = (direction * width / 2.F) || 0.F; + out.emplace_back(linkCentre + toEdge); + out.emplace_back(linkCentre - toEdge); + } + return out; +} diff --git a/game/network/link.h b/game/network/link.h index 4cca52c..59bbb65 100644 --- a/game/network/link.h +++ b/game/network/link.h @@ -45,6 +45,7 @@ public: [[nodiscard]] virtual Location positionAt(RelativeDistance dist, unsigned char start) const = 0; [[nodiscard]] virtual bool intersectRay(const Ray &) const = 0; + [[nodiscard]] virtual std::vector getBase(RelativeDistance width) const = 0; std::array ends; float length; @@ -69,6 +70,7 @@ public: [[nodiscard]] Location positionAt(RelativeDistance dist, unsigned char start) const override; [[nodiscard]] bool intersectRay(const Ray &) const override; + [[nodiscard]] std::vector getBase(RelativeDistance width) const override; }; LinkStraight::~LinkStraight() = default; @@ -82,6 +84,7 @@ public: [[nodiscard]] Location positionAt(RelativeDistance dist, unsigned char start) const override; [[nodiscard]] bool intersectRay(const Ray &) const override; + [[nodiscard]] std::vector getBase(RelativeDistance width) const override; GlobalPosition3D centreBase; RelativeDistance radius; -- cgit v1.2.3