From 6a1df3dfbae98a05e74c646cc216fbc19ffdb6d6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 7 Jan 2024 13:04:31 +0000 Subject: Template Ray on position type --- game/network/link.cpp | 9 +++++---- game/network/link.h | 8 ++++---- game/network/network.cpp | 7 ++++--- game/network/network.h | 8 ++++---- game/network/network.impl.h | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) (limited to 'game/network') diff --git a/game/network/link.cpp b/game/network/link.cpp index 703a1ca..e8eaea2 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -33,9 +33,10 @@ LinkStraight::positionAt(float dist, unsigned char start) const } bool -LinkStraight::intersectRay(const Ray & ray) const +LinkStraight::intersectRay(const Ray & ray) const { - return ray.passesCloseToEdges(std::array {ends.front().node->pos, ends.back().node->pos}, 1.F); + return ray.passesCloseToEdges( + std::array {GlobalPosition3D {ends.front().node->pos}, GlobalPosition3D {ends.back().node->pos}}, 1000); } Location @@ -54,7 +55,7 @@ LinkCurve::positionAt(float dist, unsigned char start) const } bool -LinkCurve::intersectRay(const Ray & ray) const +LinkCurve::intersectRay(const Ray & ray) const { const auto & e0p {ends[0].node->pos}; const auto & e1p {ends[1].node->pos}; @@ -64,7 +65,7 @@ LinkCurve::intersectRay(const Ray & ray) const const auto trans {glm::translate(centreBase)}; auto segCount = static_cast(std::lround(segs)) + 1; - std::vector points; + 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})}; diff --git a/game/network/link.h b/game/network/link.h index 78d3e91..95c141e 100644 --- a/game/network/link.h +++ b/game/network/link.h @@ -10,7 +10,7 @@ #include #include -class Ray; +template class Ray; // Generic network node // something that can be travelled to @@ -45,7 +45,7 @@ public: NO_MOVE(Link); [[nodiscard]] virtual Location positionAt(float dist, unsigned char start) const = 0; - [[nodiscard]] virtual bool intersectRay(const Ray &) const = 0; + [[nodiscard]] virtual bool intersectRay(const Ray &) const = 0; std::array ends; float length; @@ -69,7 +69,7 @@ public: NO_MOVE(LinkStraight); [[nodiscard]] Location positionAt(float dist, unsigned char start) const override; - [[nodiscard]] bool intersectRay(const Ray &) const override; + [[nodiscard]] bool intersectRay(const Ray &) const override; }; LinkStraight::~LinkStraight() = default; @@ -82,7 +82,7 @@ public: NO_MOVE(LinkCurve); [[nodiscard]] Location positionAt(float dist, unsigned char start) const override; - [[nodiscard]] bool intersectRay(const Ray &) const override; + [[nodiscard]] bool intersectRay(const Ray &) const override; Position3D centreBase; float radius; diff --git a/game/network/network.cpp b/game/network/network.cpp index 1ff5b26..d52e804 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -49,13 +49,14 @@ Network::candidateNodeAt(Position3D pos) const } Node::Ptr -Network::intersectRayNodes(const Ray & ray) const +Network::intersectRayNodes(const Ray & ray) const { // Click within 2m of a node if (const auto node = std::find_if(nodes.begin(), nodes.end(), [&ray](const Node::Ptr & node) { - Position3D ipos, inorm; - return glm::intersectRaySphere(ray.start, ray.direction, node->pos, 2.F, ipos, inorm); + GlobalPosition3D ipos; + Normal3D inorm; + return ray.intersectSphere(node->pos, 2000, ipos, inorm); }); node != nodes.end()) { return *node; diff --git a/game/network/network.h b/game/network/network.h index 8af06a9..9ce6e81 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -14,7 +14,7 @@ class Texture; class SceneShader; -class Ray; +template class Ray; template using GenDef = std::tuple...>; using GenCurveDef = GenDef<3, 3, 2>; @@ -32,8 +32,8 @@ public: using NodeInsertion = std::pair; [[nodiscard]] NodeInsertion newNodeAt(Position3D); [[nodiscard]] NodeInsertion candidateNodeAt(Position3D) const; - [[nodiscard]] virtual Link::Ptr intersectRayLinks(const Ray &) const = 0; - [[nodiscard]] virtual Node::Ptr intersectRayNodes(const Ray &) const; + [[nodiscard]] virtual Link::Ptr intersectRayLinks(const Ray &) const = 0; + [[nodiscard]] virtual Node::Ptr intersectRayNodes(const Ray &) const; [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, Position3D) const; [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, const Node::Ptr &) const; @@ -66,7 +66,7 @@ protected: void joinLinks(const Link::Ptr &) const; protected: - [[nodiscard]] Link::Ptr intersectRayLinks(const Ray &) const override; + [[nodiscard]] Link::Ptr intersectRayLinks(const Ray &) const override; public: template diff --git a/game/network/network.impl.h b/game/network/network.impl.h index 8e9e85c..4acbb6d 100644 --- a/game/network/network.impl.h +++ b/game/network/network.impl.h @@ -24,7 +24,7 @@ NetworkOf::joinLinks(const Link::Ptr & l) const template Link::Ptr -NetworkOf::intersectRayLinks(const Ray & ray) const +NetworkOf::intersectRayLinks(const Ray & ray) const { // Click link if (const auto link = std::find_if(links.objects.begin(), links.objects.end(), -- cgit v1.2.3