notgiven688 / jitterphysics

A cross-platform, realtime physics engine for all .NET apps.
MIT License
386 stars 87 forks source link

Fix Raycast reporting false positives and wrong distances #32

Open forestrf opened 5 years ago

forestrf commented 5 years ago

Fix Raycast reporting false positives for rays that cross a bounding box but not the shape that is inside it, thanks to analyzing BEPU Physics raycasting source code.

The code used from BEPU is here: https://github.com/bepu/bepuphysics1/blob/e0438719412e2eab8683d5ca65c1b0bb0e9b177a/BEPUphysics/CollisionTests/CollisionAlgorithms/GJK/GJKToolbox.cs#L347

This should or may fix this issue:

19

This PR was originally https://github.com/mattleibow/jitterphysics/pull/29 but after removing the repository I encountered this bug https://github.com/isaacs/github/issues/168 so I closed the previous PR to be able to update it. Here are the changes:

After reviewing https://github.com/bulletphysics/bullet3/blob/cdd56e46411527772711da5357c856a90ad9ea67/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp I was able to fix the raycast reporting wrong distances randomly by using lambda as fraction directly instead of calculating it.