Check for NaN

Seems some setups are sensitive to this and others are not.
pull/173/head
Javidx9 4 years ago committed by GitHub
parent 199941385f
commit 43c1ddc6b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      Extensions/olcPGEX_RayCastWorld.h

@ -3,7 +3,7 @@
+-------------------------------------------------------------+
| OneLoneCoder Pixel Game Engine Extension |
| Ray Cast World v1.0 |
| Ray Cast World v1.01 |
+-------------------------------------------------------------+
NOTE: UNDER ACTIVE DEVELOPMENT - THERE ARE BUGS/GLITCHES
@ -310,10 +310,6 @@ void olc::rcw::Engine::Update(float fElapsedTime)
olc::vi2d vAreaTL = { std::min(vCurrentCell.x, vTargetCell.x) - 1, std::min(vCurrentCell.y, vTargetCell.y) - 1 };
olc::vi2d vAreaBR = { std::max(vCurrentCell.x, vTargetCell.x) + 1, std::max(vCurrentCell.y, vTargetCell.y) + 1 };
bool bRecheck = false;
do
{
bRecheck = false;
// Iterate through each cell in test area
olc::vi2d vCell;
@ -338,11 +334,12 @@ void olc::rcw::Engine::Update(float fElapsedTime)
// But modified to work :P
olc::vf2d vRayToNearest = vNearestPoint - vPotentialPosition;
float fOverlap = object->fRadius - vRayToNearest.mag();
if(std::isnan(fOverlap)) fOverlap = 0;// Thanks Dandistine!
// If overlap is positive, then a collision has occurred, so we displace backwards by the
// overlap amount. The potential position is then tested against other tiles in the area
// therefore "statically" resolving the collision
if (fOverlap > 0)
if ( fOverlap > 0)
{
// Statically resolve the collision
vPotentialPosition = vPotentialPosition - vRayToNearest.norm() * fOverlap;
@ -358,14 +355,10 @@ void olc::rcw::Engine::Update(float fElapsedTime)
HandleObjectVsScenery(object, vCell.x, vCell.y, side, vNearestPoint.x - float(vCell.x), vNearestPoint.y - float(vCell.y));
}
bRecheck = true;
}
}
}
}
}
while (bRecheck);
}
// Set the objects new position to the allowed potential position

Loading…
Cancel
Save