Stack physics acting up

Here's my code that generates the scene:

Code: Select all

void physExample( )
{
   physWorld( windowWidth, windowHeight, -9.8f, true );
   
   physBox( windowWidth / 2, -5.0f, windowWidth + 20.0f, 5.0f, 0.0f, 0.0f, 0.0f, false );
   physBox( windowWidth / 2, windowHeight + 5.0f, windowWidth + 20.0f, 5.0f, 0.0f, 0.0f, 0.0f, false );
   physBox( -5.0f, windowHeight / 2, 5.0f, windowHeight, 0.0f, 0.0f, 0.0f, false );
   physBox( windowWidth + 5.0f, windowHeight / 2, 5.0f, windowHeight, 0.0f, 0.0f, 0.0f, false );

   physBox( 500.0f, 100.0f, 50.0f, 50.0f, 1.0f, 1.0f, 0.0f, true );
   physBox( 500.0f, 200.0f, 50.0f, 50.0f, 1.0f, 1.0f, 0.0f, true );
   physBox( 500.0f, 300.0f, 50.0f, 50.0f, 1.0f, 1.0f, 0.0f, true );
   physBox( 500.0f, 400.0f, 50.0f, 50.0f, 1.0f, 1.0f, 0.0f, true );
   physBox( 500.0f, 500.0f, 50.0f, 50.0f, 1.0f, 1.0f, 0.0f, true );
   physBox( 500.0f, 600.0f, 50.0f, 50.0f, 1.0f, 1.0f, 0.0f, true );
}


with the function physBox being:

Code: Select all

b2Body* physBox( float x, float y, float w, float h, float density, float friction, float restitution, bool moveable )
{
   b2BodyDef bodyDef;
   bodyDef.position.Set( x, y );
   b2Body* body = world->CreateBody( &bodyDef );

   b2PolygonDef shapeDef;
   shapeDef.SetAsBox( w / 2, h / 2 );
   shapeDef.density = density;
   shapeDef.friction = friction;
   shapeDef.restitution = restitution;

   body->CreateShape( &shapeDef );
   if ( moveable )
      body->SetMassFromShapes( );

   return body;
}


After creating the scene, all that happens is simulating the world 60 times per second. However, instead of a straight stack of boxes, this is the result:
http://www.vimeo.com/5139677

How is that possible? What am I doing wrong?
Box2D uses meters so your boxes are 50m x 50m. Box2D is not tuned for stacking objects this large.

Also stacking is tuned around using the default friction (0.3).

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