summaryrefslogtreecommitdiff
path: root/game/network
diff options
context:
space:
mode:
Diffstat (limited to 'game/network')
-rw-r--r--game/network/network.cpp28
-rw-r--r--game/network/network.h2
-rw-r--r--game/network/network.impl.h21
3 files changed, 47 insertions, 4 deletions
diff --git a/game/network/network.cpp b/game/network/network.cpp
index 7724c20..dd61f9b 100644
--- a/game/network/network.cpp
+++ b/game/network/network.cpp
@@ -109,3 +109,31 @@ Network::genCurveDef(const glm::vec3 & start, const glm::vec3 & end, float start
}
return {start, end, centre.first};
}
+
+std::pair<GenCurveDef, GenCurveDef>
+Network::genCurveDef(const glm::vec3 & start, const glm::vec3 & end, float startDir, float endDir)
+{
+ startDir += pi;
+ endDir += pi;
+ const glm::vec2 flatStart {!start}, flatEnd {!end};
+ auto midheight = [&](auto mid) {
+ const auto sm = glm::distance(flatStart, mid), em = glm::distance(flatEnd, mid);
+ return start.z + ((end.z - start.z) * (sm / (sm + em)));
+ };
+ if (const auto radii = find_arcs_radius(flatStart, startDir, flatEnd, endDir); radii.first < radii.second) {
+ const auto radius {radii.first};
+ const auto c1 = flatStart + sincosf(startDir + half_pi) * radius;
+ const auto c2 = flatEnd + sincosf(endDir + half_pi) * radius;
+ const auto mid = (c1 + c2) / 2.F;
+ const auto midh = mid ^ midheight(mid);
+ return {{start, midh, c1}, {end, midh, c2}};
+ }
+ else {
+ const auto radius {radii.second};
+ const auto c1 = flatStart + sincosf(startDir - half_pi) * radius;
+ const auto c2 = flatEnd + sincosf(endDir - half_pi) * radius;
+ const auto mid = (c1 + c2) / 2.F;
+ const auto midh = mid ^ midheight(mid);
+ return {{midh, start, c1}, {midh, end, c2}};
+ }
+}
diff --git a/game/network/network.h b/game/network/network.h
index f37f335..4a2f56a 100644
--- a/game/network/network.h
+++ b/game/network/network.h
@@ -48,6 +48,8 @@ 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);
+ static std::pair<GenCurveDef, GenCurveDef> genCurveDef(
+ const glm::vec3 & start, const glm::vec3 & end, float startDir, float endDir);
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 859d1ac..5b1649d 100644
--- a/game/network/network.impl.h
+++ b/game/network/network.impl.h
@@ -61,9 +61,16 @@ NetworkOf<T>::candidateStraight(glm::vec3 n1, glm::vec3 n2)
template<typename T>
Link::CCollection
-NetworkOf<T>::candidateJoins(glm::vec3 n1, glm::vec3 n2)
+NetworkOf<T>::candidateJoins(glm::vec3 start, glm::vec3 end)
{
- return {candidateLink<typename T::StraightLink>(n1, n2)};
+ if (glm::distance(start, end) < 2.F) {
+ return {};
+ }
+ const auto defs = genCurveDef(
+ start, end, findNodeDirection(candidateNodeAt(start).first), findNodeDirection(candidateNodeAt(end).first));
+ const auto & [c1s, c1e, c1c] = defs.first;
+ const auto & [c2s, c2e, c2c] = defs.second;
+ return {candidateLink<typename T::CurveLink>(c1s, c1e, c1c), candidateLink<typename T::CurveLink>(c2s, c2e, c2c)};
}
template<typename T>
@@ -83,9 +90,15 @@ NetworkOf<T>::addStraight(glm::vec3 n1, glm::vec3 n2)
template<typename T>
Link::CCollection
-NetworkOf<T>::addJoins(glm::vec3 n1, glm::vec3 n2)
+NetworkOf<T>::addJoins(glm::vec3 start, glm::vec3 end)
{
- return {addLink<typename T::StraightLink>(n1, n2)};
+ if (glm::distance(start, end) < 2.F) {
+ return {};
+ }
+ const auto defs = genCurveDef(start, end, findNodeDirection(nodeAt(start)), findNodeDirection(nodeAt(end)));
+ const auto & [c1s, c1e, c1c] = defs.first;
+ const auto & [c2s, c2e, c2c] = defs.second;
+ return {addLink<typename T::CurveLink>(c1s, c1e, c1c), addLink<typename T::CurveLink>(c2s, c2e, c2c)};
}
template<typename T>