Problem with collision

Hello,
I am spawning a couple of 1x1m boxes from the top, when they reach ground and are not moving anymore, I check each block's collision and try to determine witch one are in contact with other block. To do this I iterate through all of the world's contacts and check the world manifold normal:

Code:
   for(b2ContactEdge* e = b->GetContactList(); e; e=e->next)
   {
      b2WorldManifold worldManifold;
      e->contact->GetWorldManifold(&worldManifold);
      
      //bottom (0, 1)
      if(worldManifold.normal.x > -0.05f && worldManifold.normal.x <  0.05f &&
         worldManifold.normal.y >  0.95f && worldManifold.normal.y <  1.05f )
      {
         hasBottomContact = true;
      }
         
      //right (1, 0)
      else if(worldManifold.normal.x >  0.95f && worldManifold.normal.x < 1.05f &&
         worldManifold.normal.y > -0.05f && worldManifold.normal.y < 0.05f )
      {
         hasRightContact = true;
      }
         
      //left (-1, 0)
      else if(worldManifold.normal.x >  -1.05f && worldManifold.normal.x < -0.95f &&
         worldManifold.normal.y > -0.05f && worldManifold.normal.y < 0.05f )
      {
         hasLeftContact = true;
      }
   }


Basically I want to detect when a block is on the floor and has one block on each of his side touching it. The problem is that some block, even when they seems to meet all condition visually (I have put them all line up in a row and they can't move left or right when I apply a force on them), won't have those three collisions. They each seems to have the bottom collision (0,1), but most of them either don't have the left or right collision. I see a lot of them having the left or right collision twice though.

Is this normal? Or perhaps I'm just doing it wrong...
You need a frame of reference to understand which way the normal is pointing relative to the body you are concerned with. From the manual, section 9.1:

A contact normal is a unit vector that points from one shape to another. By convention, the normal points from fixtureA to fixtureB.

Since you don't have any indication from the contact alone which fixture belongs to "my" body or the "other" body, you need to figure that out on your own, and possibly reverse the direction of the supplied contact normal before you test against it. Generally it would work something like this:

Code:
if( contact->GetFixtureA()->GetBody() == myBody )
{
     worldManifold.normal = -worldManifold.normal;
}

// test to see which way your contact normal is pointing


you might look at this thread also for an explanation of why you need to do that: http://box2d.org/forum/viewtopic.php?f=3&t=4871

[edited to hopefully provide a clearer explanation]
Ha, that would explain a few things...
Thanks you for the help, I'll try that when I found the time.

Original thread: https://box2d.org/forum/viewtopic.php?t=4957