diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-10-02 18:16:27 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-10-02 19:29:39 +0100 |
commit | d7587defa3cedd6e7ea6d0623aa8cd0f6b27819c (patch) | |
tree | 73b2dbaae87ebb5851ae09358f206d2f0f85a6f0 /game/network/network.cpp | |
parent | Latest clang-formatting (diff) | |
download | ilt-d7587defa3cedd6e7ea6d0623aa8cd0f6b27819c.tar.bz2 ilt-d7587defa3cedd6e7ea6d0623aa8cd0f6b27819c.tar.xz ilt-d7587defa3cedd6e7ea6d0623aa8cd0f6b27819c.zip |
Add support for searching a network for a ray intersection
Diffstat (limited to 'game/network/network.cpp')
-rw-r--r-- | game/network/network.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/game/network/network.cpp b/game/network/network.cpp index f59fe1e..775d420 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -5,7 +5,9 @@ #include <filesystem> #include <game/network/link.h> #include <gfx/models/texture.h> +#include <glm/gtx/intersect.hpp> #include <initializer_list> +#include <ray.hpp> #include <stdexcept> #include <utility> @@ -33,6 +35,21 @@ Network::findNodeAt(glm::vec3 pos) const return {}; } +Network::IntersectRayResult +Network::intersectRay(const Ray & ray) const +{ + // Click within 2m of a node + if (const auto node = std::find_if(nodes.begin(), nodes.end(), + [&ray](const NodePtr & node) { + glm::vec3 ipos, inorm; + return glm::intersectRaySphere(ray.start, ray.direction, node->pos, 2.F, ipos, inorm); + }); + node != nodes.end()) { + return *node; + } + return intersectRayLinks(ray); +} + void Network::joinLinks(const LinkPtr & l, const LinkPtr & ol) { |