Made surface not crash, made surface release only on motor

This commit is contained in:
Vulpovile
2021-03-15 10:32:47 -07:00
parent bfcb3f83ab
commit 79ce0b491f

View File

@@ -37,26 +37,30 @@ void SurfaceTool::onButton1MouseDown(Mouse mouse)
{ {
AudioPlayer::playSound(dingSound); AudioPlayer::playSound(dingSound);
PartInstance * target = mouse.getTarget(); PartInstance * target = mouse.getTarget();
G3D::Ray ray = mouse.getLastRay(); if(target != NULL)
std::vector<G3D::Box> surfacesHit = getSurfaces(target);
int closest;
float nearValue = G3D::inf();
for(size_t i = 0; i < surfacesHit.size(); i++)
{ {
float newTime = ray.intersectionTime(surfacesHit[i]); G3D::Ray ray = mouse.getLastRay();
if(nearValue > newTime) std::vector<G3D::Box> surfacesHit = getSurfaces(target);
int closest;
float nearValue = G3D::inf();
for(size_t i = 0; i < surfacesHit.size(); i++)
{ {
nearValue = newTime; float newTime = ray.intersectionTime(surfacesHit[i]);
closest = (int)i; if(nearValue > newTime)
{
nearValue = newTime;
closest = (int)i;
}
}
if(G3D::isFinite(nearValue))
{
target->setSurface(closest, Enum::SurfaceType::Value(surface));
} }
} }
if(G3D::isFinite(nearValue)) if(surface == Enum::SurfaceType::Motor)
{ {
g_usableApp->changeTool(NULL);
printf("\n%d\n", closest);
target->setSurface(closest, Enum::SurfaceType::Value(surface));
} }
g_usableApp->changeTool(NULL);
} }
void SurfaceTool::onButton1MouseUp(Mouse mouse) void SurfaceTool::onButton1MouseUp(Mouse mouse)
{ {