I was doing some more reading and I had a side thought about the last suggested block placement logic. The way it is currently set up the loop exits upon first collision, meaning that if the block were to intersect on the x axis while it was being placed, it would simply be projected away from the object it was colliding with and then the loop would exit leaving it possibly suspended in mid air, if the block was now no longer colliding with an object.
OOps, not what we want to happen. This is an easy fix though, we just have to
continue to move the object through the main do loop until both an x and y collision has happened, so that the Object is at rest. So, this will change the logic structure too..
int collide=0 //Change collide to an integer value
do
{
if(collide==0)
{
Move block along negative x and y axises by -0.005
}
else
{
Move block along negative y axis 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.
collide +=1; //ADD ONE TO COLLIDE
if(collide==2)
{
break; //(SIMPLE IF ENCLOSER OF BREAK STATEMENT)
}
}
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 +=2
break;
}
}
while(there's still blocks to check)
}
}while( collide<2)>
This seems to fix our problem, but upon closer inspection we run across one more.
Using the current structure of logic the blocks at some point will begin to leave spaces due to the inability of the blocks to know about spaces between each other. This problem occurs no matter what point of origin is used for placing the blocks into the Block Placement area. This is due to the different sizes of the blocks and the random nature of their creation.
So.. Now what??
Well one solution is that through the use of reference counting, the blocks keeping track of the order in which they are created, that they should be able to share information with a management system. It will be the job of this management system to keep track of available space that needs to be filled as the blocks are generated.
For example :
The first row of blocks can be generated by keeping track of the translations of the blocks before them without running into the space problem. By simply knowing the boundaries of the block before it and knowing it's own boundaries the right origin for placing the block can be determined. Once the first row is filled, if we continued to rely on this system alone, the same problem would occur so an added element is needed.
Because of the nature of the growing complexity of placing these blocks, this is where a quad tree does indeed come in handy. By Subdividing the space we can know which blocks the next block placed in the new row can come into contact with, without having to cycle through all of the blocks.
It will be up to blocks to keep track of what sectors or branches of the subdivided space they are in so that when an initial collision occurs on the new row, by comparing sizes of the blocks, and knowing the dimensions of the each sizes bounding blocks, we can determine where the new block will fit without wasting space.
This sounds well and dandy in theory, and I'm glad that I took the time really analyze the problem before attempting to really code the solution again, even though this analysis took me a couple of hours, it probably ended up saving me a couple of days time. Following this model I will be structuring a new system for block placement. I will post screenshots of this implementation, even if it ends up that it doesn't work out. That will be available sometime later today.
Further analysis will be required as well if this implementation fails.