Repository navigation
[rmodels] Fix GetRayCollisionSphere() hitting spheres behind the ray - #6231
Conversation
|
I discovered something while testing my PR a bit: if the ray's line completely misses the sphere, the This is not an issue for my PR, as it still sets the However, my question to @raysan5, should I add a fix for this? The fix is simple: I could return early if Looking at |
|
@Ne0nWinds good catch, thanks for the review Definitely returning a zeeroed struct will be desirable but please, avoid an early return if possible. |
GetRayCollisionSphere() hitting spheres behind the ray
|
Okay, pushed up a new commit. I restructured the conditionals so that it always returns a zeroed struct when the ray misses the sphere The diff looks more confusing, but I kept all the arithmetic the same. Only the error handling is different. |
|
@Ne0nWinds thanks! |
GetRayCollisionSphere()would sethittotrue, even if the sphere is behind the ray.Simple test case that would fail:
hitwas set based on the discriminant (d >= 0.0f), which only tells us whether the line the ray sits on intersects the sphere. It doesn't determine if it's in front of or behind the ray.The fix is to check if the signed distance from the ray origin is greater than or equal to zero. This checks that the collision point with the sphere is in front of ray and not behind it.