Hi, I think the best would be to use a specialized physics library.
That said. If I think about this problem, I would suspect that it's not that hard:
The sphere has a midpoint and a radius. For every point in the mesh do the following:
- check if the point lies inside the sphere.
- if it does check if it is closer to the center than the previously found point(if any)
- if it does... store this point as the collision point
Of course, this routine will be fairly slow.
A few things to speed it up:
- for a first trivial reject, first see if the bounding sphere of the mesh collides
- don't calc the squareroots when checking distances... use the squared lengths instead.(much faster)
- Instead of comparing every point of the mesh, use a dimensional space division algorithm (quadtree / BSP)for the mesh to quickly rule out groups of points
Ah... and this routine only works if the sphere doesn't travel too fast (relative to the mesh). If it would travel very fast, and you sample it X times per second, chances are the sphere would have flown right through the mesh without every colliding. To overcome this, you must use 'swept volumes' which basically makes your sphere into a tube. Making the math exponentially complicated.