diff --git a/src/studio/src/simulator.cpp b/src/studio/src/simulator.cpp index c3e3de8d2812a3e804c396db8fc825d38f8f7fcc..4e4e6f541103c7c8492af3f66ab14de7c186fe8a 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; } }