Sunday, April 29, 2007

An Example of SAT

SAT has 3 main advantages and is the reason why I have choosen to use it. The 3main advanages are;

  • Allows to perform good looking physics simply and accurately, like bouncing, friction, deals with slopes in an automated fashion.

  • The collision detection is more accurate for high-speed sprites. In a sprite-based system, the objects can potentially jump past each other in a time frame if they move too fast.

  • It is based on vector math, so it can be extended to 3D; therefore, SAT itsn't limited to just strictly 2D like sprite collision



    The method of SAT is the heart of "What If Mode" for "What If Mode" (which will call the game something, but for now please excuse me if I over use it) is all about physics in the sense that it does matter what gravity is, or what the friction of the ground is, or the elasticity force between 2 particles, or it depends on the angle between 2 vectors, for whatever purpose of you being able to advance, or not advance to the next level. SAT can take into consideration all of these physics variables and supply a very accurate collision detection with these in effect since it uses vectors. Before I discuss SAT in depth I would like to give you a couple of examples of SAT and show you how it works.

    The basic idea of SAT is very simple, and easy to implement into any game. I'll show you SAT through an example of 2 boxes tested for collision.
    collision of 2 boxes

    The algorith tries to determine if it is possible to fit a plane between the 2 boxes if so then they're seperated. To determine if they're seperated it is as easy as projecting their intervals onto the normal plane and compare if they overlap or not. It's true that there are an infinite number of planes that can be drawn between 2 objects in 2D space, but think about how many we need to check? We only need to check for 4 planes. Out of the 4 planes you just have to check when atleast one is seperated, and once that has been checked you return a no collision flag else they're interested. So instead of checking for intersection at 4 corners, and 4 faces, and then if this, and if that you just have to check when they're seperated, and when all 4 come back false else they've collided.

    I will continue this section of my blog and come back later this weekend with an example of polygons, and a number of objects on the screen at once, and show you how easy it is to check for SAT. Until then...

    No comments: