Quick part selection fix
A Part in front of the camera can now be selected if other parts are behind it.
This commit is contained in:
12
main.cpp
12
main.cpp
@@ -17,7 +17,7 @@
|
||||
#include "TextButtonInstance.h"
|
||||
#include "ImageButtonInstance.h"
|
||||
#include "AudioPlayer.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#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<float>::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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user