From 37b135e59ba22cf9ace1141b9dd21d0819fe3d1d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 25 Oct 2022 18:49:19 +0100 Subject: Implement extending a network into open space --- game/network/network.cpp | 16 ++++++++++++++++ game/network/network.h | 4 ++++ game/network/network.impl.h | 10 ++++++---- game/network/rail.h | 2 ++ 4 files changed, 28 insertions(+), 4 deletions(-) (limited to 'game/network') diff --git a/game/network/network.cpp b/game/network/network.cpp index ad501b5..7724c20 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -93,3 +93,19 @@ Network::routeFromTo(const Link::End & end, const Node::Ptr & dest) const { return RouteWalker().findRouteTo(end, dest); } + +GenCurveDef +Network::genCurveDef(const glm::vec3 & start, const glm::vec3 & end, float startDir) +{ + const auto diff {end - start}; + const auto vy {vector_yaw(diff)}; + const auto dir = pi + startDir; + const auto flatStart {!start}, flatEnd {!end}; + const auto n2ed {(vy * 2) - dir - pi}; + const auto centre {find_arc_centre(flatStart, dir, flatEnd, n2ed)}; + + if (centre.second) { // right hand arc + return {end, start, centre.first}; + } + return {start, end, centre.first}; +} diff --git a/game/network/network.h b/game/network/network.h index f1ac23f..f37f335 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -15,6 +15,9 @@ class Texture; class Shader; class Ray; +template using GenDef = std::tuple...>; +using GenCurveDef = GenDef<3, 3, 2>; + class Network { public: using LinkEnd = std::pair; @@ -44,6 +47,7 @@ public: protected: static void joinLinks(const Link::Ptr & l, const Link::Ptr & ol); + static GenCurveDef genCurveDef(const glm::vec3 & start, const glm::vec3 & end, float startDir); using Nodes = std::set>; Nodes nodes; diff --git a/game/network/network.impl.h b/game/network/network.impl.h index cee8155..859d1ac 100644 --- a/game/network/network.impl.h +++ b/game/network/network.impl.h @@ -68,9 +68,10 @@ NetworkOf::candidateJoins(glm::vec3 n1, glm::vec3 n2) template Link::CCollection -NetworkOf::candidateExtend(glm::vec3 n1, glm::vec3 n2) +NetworkOf::candidateExtend(glm::vec3 start, glm::vec3 end) { - return {candidateLink(n1, n2)}; + const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(candidateNodeAt(start).first)); + return {candidateLink(cstart, cend, centre)}; } template @@ -89,7 +90,8 @@ NetworkOf::addJoins(glm::vec3 n1, glm::vec3 n2) template Link::CCollection -NetworkOf::addExtend(glm::vec3 n1, glm::vec3 n2) +NetworkOf::addExtend(glm::vec3 start, glm::vec3 end) { - return {addLink(n1, n2)}; + const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(nodeAt(start))); + return {addLink(cstart, cend, centre)}; } diff --git a/game/network/rail.h b/game/network/rail.h index b1a036e..6850463 100644 --- a/game/network/rail.h +++ b/game/network/rail.h @@ -17,12 +17,14 @@ struct Arc; // A piece of rail track class RailLinkStraight; +class RailLinkCurve; class RailLink : public virtual Link, public Renderable { public: RailLink() = default; inline ~RailLink() override = 0; using StraightLink = RailLinkStraight; + using CurveLink = RailLinkCurve; void render(const Shader &) const override; NO_COPY(RailLink); -- cgit v1.2.3