From f45e8afb3765abf7ee69a4e211db0792200bb7be Mon Sep 17 00:00:00 2001 From: MusicalProgrammer <38636805+MusicalProgrammer@users.noreply.github.com> Date: Sun, 29 Apr 2018 18:49:57 -0400 Subject: [PATCH] Quick part selection fix A Part in front of the camera can now be selected if other parts are behind it. --- main.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index c9fa0d1..39b806b 100644 --- a/main.cpp +++ b/main.cpp @@ -17,7 +17,7 @@ #include "TextButtonInstance.h" #include "ImageButtonInstance.h" #include "AudioPlayer.h" - +#include #if G3D_VER < 61000 #error Requires G3D 6.10 @@ -1105,15 +1105,21 @@ void Demo::onUserInput(UserInput* ui) { { selectedInstance = NULL; testRay = app->debugCamera.worldRay(mousex, mousey, app->renderDevice->getViewport()); + float nearest=std::numeric_limits::infinity(); + Vector3 camPos = app->debugCamera.getCoordinateFrame().translation; for(size_t i = 0; i < instances.size(); i++) { if(instances.at(i)->className == "Part" && instances.at(i)->parent == dataModel) { PhysicalInstance* test = (PhysicalInstance*)instances.at(i); - if (testRay.intersectionTime(test->getBox()) != inf()) { - selectedInstance = test; + float distanceFromPart = (camPos-test->getPosition()).magnitude(); + if (nearest>distanceFromPart) + { + nearest=distanceFromPart; + selectedInstance = test; + } } } }