idmillington / cyclone-physics

The Physics engine that accompanies the book "Game Physics Engine Design"
MIT License
946 stars 265 forks source link

The box-sphere collision test algorithm produces zero normal when a sphere's center is inside a box #34

Open YukinoHayakawa opened 9 years ago

YukinoHayakawa commented 9 years ago

According to the code above https://github.com/idmillington/cyclone-physics/blob/master/src/collide_fine.cpp#L623 the closestPt will be equal to relCentre if the center of the sphere is inside the box, which leads to a normal with zero length. Then you make a coordinate system with the zero normal and get a degenerated matrix with NaNs. The NaNs spread into every single part of the simulation and mess it up entirely.