Friday, November 28, 2014

INFR3110 Blog 4


Physics in a game serves many purposes, but its primary goal is to create realism. The addition of physics brings along many emerging dynamics; from complex real-world interactions such as gravity, springs, water, clothing movement, to explosions, there is much that a physics engine can do to enhance the overall experience of your game. One vital topic of physics is collision detection.

In order to represent objects in our game world, we typically need a collidable entity – or bounding box, shape to represent it in a “physics world”. The collidable entity is not visible to the player, but is attached and used to represent objects in our game world. Implementation wise, as the entities in our physics world is updated, based of elements such as gravity, and force, the game world will use the updated collidable entity to transform our game world objects. An example of this would be having say a basketball in our game world, and creating than attaching a collidable entity from the physics world. The collidable entity will likely be a sphere shape and will be given physics properties such as bounciness, mass and drag. When our physics world updates, the collidable entity will frame by frame fall to the ground and bounce.  To apply this to our game world, we simple use the updated attributes from the collidable entity and apply them to our game world’s basketball mesh.

Above, we see that we used a sphere primitive to represent our basketball in the physics world, however for more complex shapes there are many other options. The player object, depending on game complexity will likely be represented with a capsule in our physics world.  Another primitive for our collidable entities is the box.

When it comes to actually detecting collision between objects, some of the methods are :

Axis-aligned bounding box (AABB) is one of the simplest implementations of collision detection; it involves creating bounding boxes from the same coordinate system.  Collision is detected if any points are inside another. Essentially for the 2 objects a collision is checked for, it is the equivalent to drawing a box, with the axis x, y, z to be parallel to one another. The major problem with this method is if one of the objects is rotated, in which case the bounding box becomes very inaccurate, with the potential for having a lot of empty space. This was the case for my previous GDW game, where fences had bounding boxes that were too big, when rotated or checked against the character at a non-parallel angle.

The other method that remedies the above problem is to create an Oriented bounding box(OBB), essentially the boxes will no longer have parallel axis, but will be rotated by its local transformation. To detect the actual collision, there are methods such as using Seperating Axis Theorem(SAT).

The basic idea behind the SAT algorithm is to create a projection of each edge, perpendicular to itself (normal). A vector is formed and if, there is no overlap between the projection formed and the project of the other bounding box, this edge will have no collision. If there exists a projection where there is no overlap, than the 2 bounding boxes is determined to be not colliding.

Detection of other primitives is more straightforward. For instance, collision between spheres can be determined by comparing their respective radii to get the distance from one another.

Gregory, J. (2009). Collision and Rigid Body Dynamics. Game engine architecture. Wellesley, Mass.: A K Peters

Friday, November 7, 2014

INFR3110 Blog 3


Barely in the groove of using 2loc, after many attempts, hurdles, scrapping together pieces of information here and there, and even abandoning some projects, I’ve managed to complete a few medium homework questions. 2loc has been a challenging beast to say the least and it is the primary adversary when it comes to completing these assignments. Constantly scratching my head and questioning everything, I’ve bided for time in hopes of learning new details from either the lecture or the tutorials.

One of the more challenging of the completed - Shadow mapping is simple in theory, but the implementation in 2loc involves what I believe to be the combined use of many unknown 2loc features lurking in the depths. The main points to take away in the implementation is the use of ShaderOperators to update the passed in light viewprojection matrix. As I did not properly understand ECS, I had been scratching my head as to why the light camera’s passed back view projection matrix was wrong – I expected it to be computed and then returned but was forgetting that the system was the one to do that, and has yet to perform the task.The other important part is passing in specific uniforms not exposed or directly controlled by the programmer. Rather, these functions were hidden away and must be enabled. Even then, finding the exact name of the uniform was difficult. It would seem that this has been alleviated in the latest distribution, where these functions are exposed in full and would even warn you if they are enabled and not used in the shader; a bit late for me, as much time was lost in finding and learning these features. From then on it was smooth sailing - calculating the position to shadow coord by using the lights’ view projection and the model matrix, than deserializing it to sample from the shadowmap. Following the standard algorithm already taught to us and a bit of tweaking to get rid of shadow acne and voila, shadow mapping.

Shadowmapping in 2loc

The other bit I worked on was Pacman. The most challenging element of this was in figuring out what method to implement the collision. I was tempted to use box2D, but realistically it requires the arduous process of creating static bodies for all the walls. Looking towards the future, I decided on a supposedly easy approach of collision masks. The only problem encountered was the different coordinate systems between sampling the texture with the build in readpixels function. The simplest remedy being to rotate the png itself.

As for the rest of this term and the hard homework questions waiting, the roadmap I had in mind is to take Pacman all the way; a total of 35xp is tantalizing. The obligation of doing the AI centric homework question compels me as I am taking “Artificial intelligence for gaming” this semester. Salvaging my A* algorithm from the previous year, I will be able to implement the AI for the ghosts to a much more accurate degree. If you’ve read up on the AI of the ghosts, it would seem they are a lot more complicated than meets the eye…