Your raycast-vs-sphere code is broken

Check your codebase if you don’t believe me. I posted this months ago on GDA but never found the time to make a proper note. And you know what? I still don’t have the time. Check the GDA archives for more information.

In short: the code solving the quadratic equation suffers from limited FPU accuracy and returns “no intersection” while there definitely is one. “Best” fix is to move the ray origin closer to the target sphere. See this small repro case for details.

It’s not a theoretical problem only, it happened in Konoko Payne when sniping a far away enemy with a Mercury Bow.

So, there. Off my TODO list, stupid item!

One Response to “Your raycast-vs-sphere code is broken”



  1. Pablo de Heras Says:

    Hehe yes. We had the same problem in our ray tracer with more far away objects. Moving the starting point of the ray close to the object and also scaling the object or combination of objects down or up to one unit, helped a lot.

    Cheers,

    Pablo

shopfr.org cialis