From 94f0e426bc8f298aec90fd0d4fcf6f823f8c399c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 10 Jan 2022 02:07:53 +0000 Subject: Ray Trace cursor clicks to terrain surface --- ui/gameMainWindow.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'ui') diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index d53db4b..1724927 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -70,16 +70,11 @@ public: const auto & ref = *selected.base()->get(); clicked = typeid(ref).name(); } + else if (const auto pos = gameState->geoData->intersectRay(ray)) { + clicked = streamed_string(*pos); + } else { - try { - const auto dist = camera->pos.z / -ray.direction.z; - const auto pos = !camera->pos + (!ray.direction * dist); - - clicked = streamed_string(gameState->geoData->positionAt(pos)); - } - catch (std::range_error &) { - clicked.clear(); - } + clicked.clear(); } } } -- cgit v1.2.3