summaryrefslogtreecommitdiff
path: root/game/network/link.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-03-13 18:57:07 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-03-13 18:59:43 +0000
commit81e2f0082ee2c5b3584135467c94111565a776b1 (patch)
tree00c23d71090ac55c5d8218f5e86212992f2e1453 /game/network/link.cpp
parentMore complete tests for route finding (diff)
downloadilt-81e2f0082ee2c5b3584135467c94111565a776b1.tar.bz2
ilt-81e2f0082ee2c5b3584135467c94111565a776b1.tar.xz
ilt-81e2f0082ee2c5b3584135467c94111565a776b1.zip
Add generic middle classes LinkStraight and LinkCurve
Diffstat (limited to 'game/network/link.cpp')
-rw-r--r--game/network/link.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/game/network/link.cpp b/game/network/link.cpp
index ad09341..e45126f 100644
--- a/game/network/link.cpp
+++ b/game/network/link.cpp
@@ -1,9 +1,13 @@
#include "link.h"
#include <compare>
+#include <location.hpp>
+#include <maths.h>
#include <tuple>
Link::Link(End a, End b, float l) : ends {{std::move(a), std::move(b)}}, length {l} { }
+LinkCurve::LinkCurve(glm::vec3 c, float r, Arc a) : centreBase {c}, radius {r}, arc {std::move(a)} { }
+
bool
operator<(const glm::vec3 & a, const glm::vec3 & b)
{
@@ -16,3 +20,27 @@ operator<(const Node & a, const Node & b)
{
return a.pos < b.pos;
}
+
+Location
+LinkStraight::positionAt(float 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 auto dir {glm::normalize(diff)};
+ return Location {es.first->pos + vehiclePositionOffset() + dir * dist, {-vector_pitch(dir), vector_yaw(dir), 0}};
+}
+
+Location
+LinkCurve::positionAt(float dist, unsigned char start) const
+{
+ static constexpr std::array<float, 2> dirOffset {half_pi, -half_pi};
+ const auto frac {dist / length};
+ const auto es {std::make_pair(ends[start].node.get(), ends[1 - start].node.get())};
+ const auto as {std::make_pair(arc[start], arc[1 - start])};
+ const auto ang {as.first + ((as.second - as.first) * frac)};
+ const auto relPos {!sincosf(ang) * radius};
+ const auto relClimb {vehiclePositionOffset()
+ + glm::vec3 {0, -centreBase.y + es.first->pos.y + ((es.second->pos.y - es.first->pos.y) * frac), 0}};
+ const auto pitch {vector_pitch({0, (es.first->pos.y - es.second->pos.y) / length, 0})};
+ return Location {relPos + relClimb + centreBase, {pitch, normalize(ang + dirOffset[start]), 0}};
+}