From 9dc8895fc0d7c0a5c065fc124c5dc39ecb4b7939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0toura=C4=8D?= <525032@mail.muni.cz> Date: Fri, 2 Jun 2023 15:33:54 +0200 Subject: [PATCH] ray picking fixed(?), gets bad with cam rotation --- src/studio/src/simulator.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/studio/src/simulator.cpp b/src/studio/src/simulator.cpp index c3e3de8..4e4e6f5 100644 --- a/src/studio/src/simulator.cpp +++ b/src/studio/src/simulator.cpp @@ -388,17 +388,20 @@ node_ptr Simulator::find_intersection(glm::vec3 rayPosition, glm::vec3 rayDirect if (!obj || !obj->is_selectable()) continue; - auto t = intersect(rayPosition, rayDirection, obj->getAABB().getLH()); - if (t.second > t.first || t.second < 0) + auto LH = obj->getAABB().getLH(); + LH.first = node->getFrame()->getTranslationMat() * node->getFrame()->getScaleMat() * glm::vec4(LH.first, 1); + LH.second = node->getFrame()->getTranslationMat() * node->getFrame()->getScaleMat() * glm::vec4(LH.second, 1); + auto [ t0, t1 ] = intersect(rayPosition, rayDirection, LH); + if ( t1 < t0 || t1 < 0) continue; - if (t.first < 0 && t.second < nearest_t) + if (t0 < 0 && t1 < nearest_t) { - nearest_t = t.second; + nearest_t = t1; nearest_node = node; } - else if (t.first < nearest_t) + else if (t0 < nearest_t) { - nearest_t = t.first; + nearest_t = t0; nearest_node = node; } } -- GitLab