diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-10-28 01:08:28 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-10-28 02:10:47 +0100 |
commit | 3bb238d41ca4f3e4a40f4ee3700b27ca7bf03b56 (patch) | |
tree | 532083d6076a8b1e72824fc9789769c5f60fc7b0 /game/network/network.cpp | |
parent | Implement extending a network into open space (diff) | |
download | ilt-3bb238d41ca4f3e4a40f4ee3700b27ca7bf03b56.tar.bz2 ilt-3bb238d41ca4f3e4a40f4ee3700b27ca7bf03b56.tar.xz ilt-3bb238d41ca4f3e4a40f4ee3700b27ca7bf03b56.zip |
Implement extending a network to join link ends
Diffstat (limited to 'game/network/network.cpp')
-rw-r--r-- | game/network/network.cpp | 28 |
1 files changed, 28 insertions, 0 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}}; + } +} |