diff options
Diffstat (limited to 'game/network')
-rw-r--r-- | game/network/network.cpp | 16 | ||||
-rw-r--r-- | game/network/network.h | 4 | ||||
-rw-r--r-- | game/network/network.impl.h | 10 | ||||
-rw-r--r-- | game/network/rail.h | 2 |
4 files changed, 28 insertions, 4 deletions
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<size_t... n> using GenDef = std::tuple<glm::vec<n, float>...>; +using GenCurveDef = GenDef<3, 3, 2>; + class Network { public: using LinkEnd = std::pair<Link::Ptr, unsigned char>; @@ -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<Node::Ptr, PtrMemberSorter<Node::Ptr, &Node::pos>>; 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<T>::candidateJoins(glm::vec3 n1, glm::vec3 n2) template<typename T> Link::CCollection -NetworkOf<T>::candidateExtend(glm::vec3 n1, glm::vec3 n2) +NetworkOf<T>::candidateExtend(glm::vec3 start, glm::vec3 end) { - return {candidateLink<typename T::StraightLink>(n1, n2)}; + const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(candidateNodeAt(start).first)); + return {candidateLink<typename T::CurveLink>(cstart, cend, centre)}; } template<typename T> @@ -89,7 +90,8 @@ NetworkOf<T>::addJoins(glm::vec3 n1, glm::vec3 n2) template<typename T> Link::CCollection -NetworkOf<T>::addExtend(glm::vec3 n1, glm::vec3 n2) +NetworkOf<T>::addExtend(glm::vec3 start, glm::vec3 end) { - return {addLink<typename T::StraightLink>(n1, n2)}; + const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(nodeAt(start))); + return {addLink<typename T::CurveLink>(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); |