Determine the point of collision between the mesh and the sphere?

I am writing physics simulations using Ogre and MOC .

I have a sphere that I shoot from the camera position and it is moved in the direction facing the camera using a vector camera.

I would like to know how I can detect the point of collision between my sphere and another mesh.

How can I check the collision point between two meshes using MOC or OGRE?

Update: It should be mentioned earlier. I cannot use a third party physics library as I need to develop it myself (uni project).

+2


source to share


2 answers


I think it is best to use a dedicated physics library.

It said. If I think about this problem, I would suspect that it is not that hard:

The sphere has a midpoint and radius. For each grid point, do the following:

  • check if the point is inside the sphere.
  • if it checks if it is closer to the center than the previously found point (if any)
  • if it ... stores that point as a collision point


Of course, this procedure will be quite slow. A few things to speed up this:

  • for the first trivial deviation, first see if the bounding sphere of the mesh collides
  • don't compute squareroots when checking distances ... use square lengths instead (much faster)
  • Instead of comparing each grid point, use a spatial partitioning algorithm (quadtree / BSP) on the grid to quickly eliminate groups of points

Ah ... and this procedure only works if the sphere is not moving too fast (relative to the mesh). If it traveled very quickly and you tried it X times per second, chances are the sphere would fly straight through the mesh without any collision. To overcome this you have to use "swept volume", which basically turns your sphere into a tube. Making the math harder.

+2


source


The accepted solution here flat doesn't work. This will only be a job if the mesh density is usually high enough that no two points on the mesh are separated from each other than the diameter of your collision sphere. Imagine a tiny sphere launched a short distance from a random vector in a huuuge cubic grid. The cubic mesh has only 8 vertices. What are the chances that the cube will actually fall into one of those 8 vertices?

This really needs to be done when colliding with polygons. You should be able to check the intersection of the polygon and the sphere (and also the cylinder if you want to avoid tunneling as mentioned above). There are many resources available online and in book form for this, but http://www.realtimerendering.com/intersections.html can be a useful starting point.



The optimization comments are good. Early capabilities are needed (perhaps a quick check against a bounding sphere or an axial bounding volume for a mesh). Even after you have determined that you are inside the bounded volume, it would probably be a good idea to remove the unlikely polygons from the list of potential candidates (too far, in the wrong direction, etc.).

+8


source







All Articles