From d7a6935c6096ef1eb3b3d723dc8e78bf6336faf6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 9 Mar 2021 23:51:30 +0000 Subject: Please joining links midpoint height better --- game/network/rail.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'game') diff --git a/game/network/rail.cpp b/game/network/rail.cpp index c124a41..91be466 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -65,24 +65,30 @@ RailLinks::addLinksBetween(glm::vec3 start, glm::vec3 end) throw std::runtime_error("Node exists but couldn't find it"); }; float dir = pi + findDir(*node1ins.first); - const glm::vec2 flatStart {start.x, start.z}, flatEnd {end.x, end.z}; + const glm::vec2 flatStart {!start}, flatEnd {!end}; if (!node2ins.second) { + auto midheight = [&](auto mid) { + const auto sm = glm::distance(flatStart, mid), em = glm::distance(flatEnd, mid); + return start.y + ((end.y - start.y) * (sm / (sm + em))); + }; float dir2 = pi + findDir(*node2ins.first); if (const auto radii = find_arcs_radius(flatStart, dir, flatEnd, dir2); radii.first < radii.second) { const auto radius {radii.first}; - const auto c1 = start + !sincosf(dir + half_pi) * radius; - const auto c2 = end + !sincosf(dir2 + half_pi) * radius; + const auto c1 = flatStart + sincosf(dir + half_pi) * radius; + const auto c2 = flatEnd + sincosf(dir2 + half_pi) * radius; const auto mid = (c1 + c2) / 2.F; - addLink(start, mid, !c1); - return addLink(end, mid, !c2); + const auto midh = mid ^ midheight(mid); + addLink(start, midh, c1); + return addLink(end, midh, c2); } else { const auto radius {radii.second}; - const auto c1 = start + !sincosf(dir - half_pi) * radius; - const auto c2 = end + !sincosf(dir2 - half_pi) * radius; + const auto c1 = flatStart + sincosf(dir - half_pi) * radius; + const auto c2 = flatEnd + sincosf(dir2 - half_pi) * radius; const auto mid = (c1 + c2) / 2.F; - addLink(mid, start, !(c1)); - return addLink(mid, end, !c2); + const auto midh = mid ^ midheight(mid); + addLink(midh, start, c1); + return addLink(midh, end, c2); } } const auto diff {end - start}; -- cgit v1.2.3