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...

    Friday, April 27, 2007

    Seperating Axis Theorem "The Theory"

    After much thought and much research on how a collision engine would work in "What If Mode" I finally pulled out my Calculus 3 book, Math & Physics in Game Programming, and many articles on Gamedev.net, and Gamesutra.com I have come across the solution. It is called the "Seperating Axis Theorem" the theorem states that for any objects lying ing a plane one can put a line between 2 convex shapes if and only if "iff" they're not intersecting. This seperating axis theorem can be applied for fast collision between 2 polygons where each face's normal is used as a seperating axis. For increased efficiency, parallel axes may be calculated as a single axis. -Wiki

    How can this be applied to "What If Mode" Let's say that in our level the objects are constantly being formed, mis-shaped, and there constanly being changed this is called polymorphism in our game which isn't suppose to be confused with polymorphism in OOP. If we had polymorphic objects in a game not only would there have to be a fast collision detection, but the physics that simulated the collision of the polymorphic objects would have to concur with each other, and the collision detection must have some overlying rule that all objects obeyed. If this didn't happen then you would constantly have many algorithms asking which object is hitting which, and then have some type of sorting, or machine state based coding that asked after the algorithms told you which objects were about to collide or check for let's check for their collision. This could be many lines of code just to achieve a very simple concept.

    Seperating Axis Theorem solves this problem by means of creating these axis on all the objects faces and check for intersection from there axis.

    I'm going to create a demo of this seperating axis theorem simulation throw polygon shapes that form into other polygon shapes at random, and then work from their by means of applying actual images, and game objects. I shall continue this update through this blog, and will show all of my progressions and failing points while creating this demo.

    Thursday, April 26, 2007

    An Example of What If Mode

    I wanted to provide a small example of "What If Mode", so people don't try and misconstrue it with other game mods, engines, ideas, etc...
    Let's imagine that in a "mario like" game that there is a switch in a high place that normally using newtonian physics you couldn't reach, but there are 2 random objects in the level that might help you out. There is a gravity gun, and a bouncy ball, but furthermore we don't know what the ellastic forces, normal forces, friction, or the gravity are in that level.

    First let's start with the gravity gun. Could we use the gravity gun to either shoot the ball up and kill the switch, or use the gravity gun to shoot other objects in the game that would make the switch turn off? If we took this approach then what has to be the forces of the enviroment for us to accomplish this simple task? What does gravity have to be? What does the elastic forces have to be? Do we have friction in the level? Is it a concern at all? We simply have to experiment.

    However, there is a bouncy ball in the level as well. What can we do to the bouncy ball other than the idea of using the gravity gun Could we kick it? Could we bounce on top of the ball? Could we throw the gravity gun on top of the ball if gravity was light enough and kill the switch?

    Now let's talk about the forces of the level. The forces of the level either increases, or decreases the options we have to complete a simple task in each level. But what if they're never what we expect them to be? What if for a second gravity is as we know it the constant of 9.815, and friction is close to .250 in a specific level, but then all of a sudden they switch, or they're 1/3, 1/16, their size, or they're 3x, or 16x their constants? What if these constants in the level were to alternate momentarily, or continuously, or until you completed the game, or seemed that there were no constants at all.

    Having these random variables that make up the physics of the world makes the game more interesting, fun, and challenging all at the same time. The game is never the same, so you could just play level 1 over and over and over again without having to advance to level 2.

    Or could you? This is what I'm going to find out.

    The Beginning of What If Mode

    Hello, this is the beginning of the project "What If Mode". Rather if it has been done, or not it is purely for the benefit of my gamedev team to see if we can come up with creative ideas, and turn them into video games. Before I explain to you what the Project of "What If Mode" some history must be known about "What If Mode".

    It started as a special mode by my team leader who we call Jesus (we all have nicknames) that in our 3D game that we are continuously designing while in school, and won't start development until after school as a special mode that ask the simple question "What if this happens?" The idea, and possibilities of the game taking off in weird, quarky, funny directions are endless in "What If Mode". As we were discussing it; me, being the only programmer I just joked around asking the team "Do you know what a programmers headache is? It's when Jesus starts talking about his ideas for video games, because a programmer just has a baffled, some-what ridiculous look on their face asking; 'Are you insane'? "

    Well, after much pondering about if What If Mode was possible I just simply told myself I would never know unless I tried it. Now, I'm not going to create a "What If Mode" mod for game like HL 2, in Source Engine, or Unreal 03 when it comes out using Script I'm simply going to make a 2D "What If Mode" game "mario style" just to see what it would take to make something that can be so random and so interactive with how you play the game, and is never the same after ran once.

    So here I go wish me luck.

    Thanks,

    c.s. Finch