Fixed incorrect distances for AABB raycast results

This commit is contained in:
Diren D Bharwani 2023-03-04 17:32:05 +08:00
parent e293094b6d
commit 20fe6c4877
2 changed files with 8 additions and 1 deletions

View File

@ -155,6 +155,11 @@ namespace SHADE
SHRaycastResult result;
result.hit = Intersects(ray.position, ray.direction, result.distance);
// Negative distances are invalid, therefore false
if (result.distance < 0.0f)
result.hit = false;
if (result.hit)
{
result.position = ray.position + ray.direction * result.distance;

View File

@ -197,7 +197,9 @@ namespace SHADE
// Load start and end points into the container for debug drawing
#ifdef SHEDITOR
SHVec3 endPos = info.ray.position + info.ray.direction * SHRay::MAX_RAYCAST_DIST;
// Default end pos is how far the ray was casted.
const float DISTANCE = info.distance == std::numeric_limits<float>::infinity() ? SHRay::MAX_RAYCAST_DIST : info.distance;
SHVec3 endPos = info.ray.position + info.ray.direction * DISTANCE;
if (!results.empty())
endPos = results.back().position;