Wednesday, January 09, 2008

Mid-week update

I'm trying to get into a habit of continuously blogging with good content. Hopefully I make that become a reality. It has been a somewhat progressive week.
With the addition to the implementation of the bounding boxes for objects in the game engine, I also managed to add some simple AABB type collision to the system.
I'm still struggling with how I'm going to actually handle the collisions for the initial block placement in the game barricade however. So, because of this, tonight, I'm taking some time dedicated solely to research in that area.

Yesterday, I experimented with writing some simple functionality that took a block and moved it from the center of the world origin down the negative y axis and the negative x axis until it either came into contact with the block placement volume or another block. Once a collision happened, a test would take place to make sure that the block was not outside of the block placement area, if it was, we iterated small movements until it no longer was testing both the X and Y half-vectors of the bounding volumes. ( I realized that this wasn't the best approach as it eats up some time, but seeing as how there are only a maximum of 60 blocks currently being created, I figured it was at least worth experimenting with.) If it was intersecting with another block we did the same thing. Now feasibly this should work, except that you either A) have to at least divide areas into sub regions and check every block in that region, or B) check every single block in that has already been generated and placed. Seeing as how the game works with such a small number of objects, for simple block placement it didn't seem to make much sense to write a system to check for subdivision organization. My opinion on this may eventually change as I do some additional research this evening.

My problem with the sample implementation yesterday simply was a lack of accurate checking on the x axis for all boxes. I was simply trying to write something fast and was some what disoriented as I've been sick for the last week or so, again.. damn winter, At any rate, I only checked for a collision on the previously generated and placed block instead of with all
blocks. Essentially what I was supposed to have written was two separate main bodies of code for collision, one that checked for block 2 block collision and one that checked for block
to placement bounds collision. Inside each one I was supposed to have checks to see what the shortest path of projection for the objects to no longer be intersecting was and then move the objects appropriately to their resting places. But as I said I didn't check for every block on the x axis, and I didn't get the new translation position from projection, instead, I did small moving increments, which looking back caused extra checks to be made afterwards.

Writing this out has really allowed me to see where I went wrong with things yesterday. I had the right idea, but my actual implementation was wrong. My new structure should look something like the following.


bool collide=false
do
{
Move block along negative x and y axises by -0.005

if( collision with block placement area)
{
determine the projection by seeing which axis is the shortest distant to
non collision
move block to new position.
break;
}

else
{
do
{
subtract a number from the current block to work down the list of previously
generated blocks

if(the current block to check is out of bounds)
{
subtract one from the current row of blocks to check and make the last
block in the row the first to check
}

if(the row is out of bounds)
{
no collision happened, so break this loop
}
if(collision with current block to check)
{
determine the projection by seeing which axis is the shortest distant to
non collision
move block to new position.
collide = true
break;
}

}
while(there's still blocks to check)
}



}while( collide == false)



That should be all the code I need for proper placement of the blocks, at least that's what I'm thinking right now. Yesterdays implementation was something like 273 lines of code,
so, if this works, it should speed the block placement up drastically. I'm still going to do some additional reading before trying to implement this in the actual game and make sure that there isn't a better approach to take that I haven't thought of yet. Hopefully, my next entry will include some screen shots of some neatly placed blocks.

No comments: