When writing games, collision detection is important, especially one that is fast and robust. True, you can get away with having a simple rectangular collision detection where your checking if two squares overlay, but that becomes less reliable when objects in your application/game are moving fast and many
I good collision detection system is SAT or Separating axis theorem. It says that if two convex shapes' (shapes that do not invaginate) projections along their respective normals does not overlap then the shapes do not overlay. More clearly, if there is any project that separates the two shapes, then there is a collision.
That is it. However, this requires further explanation. A convex shape is like a rectangle, an octagon, or any shape that does not fold into itself. When using SAT, we use its normals, denoted by brown lines, to project two convex shapes while comparing to see if the two's intervals overlap.
If an overlap exist, then a collision is occurring.
Here we see that two shapes normals have been used to project the intervals of the respective shape. By intervals I mean that the vertexes used to define the individual convex shape has all been projected along the normals (a total of four) using dot product between the normal and vertices so as to find a range or the intervals of the shape. This interval finding is done for each normal. Then, the range of the two shapes are compared to see if the overlap, more on this later. Take note of the image of the right, note that we have an overlap at the top and at the bottom. This is because the projected intervals of the two overlap. However, this is not a collision; to be a true collision, all four projects of any shape must not be separate. So if we have any separation, therefore any project not overlapping, then there is no collision.
Comments
Post a Comment