Hello forum!
Please pardon my spelling, i am not native to English, and with all the spell checking tools some mistakes may get through.
I recently started developing games for i Phone and i am using AirplaySDK. While looking for an engine i stumbled upon box 2d.
After a quick look at the TestBed and at the hello world i dived right in and done my first exercise which proved to be more than i could chew! I have a ground box and 2 dynamic boxes. They do not collide with each other but they collide with the ground. Am i missing something ?
Here is my code (mostly Hello World copy paste):

boxes fall down but they come to occupy the same space. they do not come to rest one upon each other as I hoped they would.
Please, please, please point to me what am i missing!?
<edit*> I noticed that i have 0.5f density...The density was 1.0f but had no different effect. I am actually looking for something like : "AllowCollisionOfDinamycBodyes(true);"
Please pardon my spelling, i am not native to English, and with all the spell checking tools some mistakes may get through.
I recently started developing games for i Phone and i am using AirplaySDK. While looking for an engine i stumbled upon box 2d.
After a quick look at the TestBed and at the hello world i dived right in and done my first exercise which proved to be more than i could chew! I have a ground box and 2 dynamic boxes. They do not collide with each other but they collide with the ground. Am i missing something ?
Here is my code (mostly Hello World copy paste):
Code:
b2Vec2 gravity(0.0f, 10.0f);
//// Do we want to let bodies sleep?
bool doSleep = true;
//// Construct a world object, which will hold and simulate the rigid bodies.
b2World *world = new b2World(gravity, doSleep);
//// Define the ground body.
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0.0f, 48.0f);
//// Call the body factory which allocates memory for the ground body
//// from a pool and creates the ground box shape (also from a pool).
//// The body is also added to the world.
b2Body* groundBody = world->CreateBody(&groundBodyDef);
//// Define the ground box shape.
b2PolygonShape groundBox;
//// The extents are the half-widths of the box.
groundBox.SetAsBox(24.0f, 1.0f);
//// Add the ground fixture to the ground body.
groundBody->CreateFixture(&groundBox, 0.0f);
//// Define the dynamic body. We set its position and call the body factory.
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(16.0f, 24.0f);
b2Body* body = world->CreateBody(&bodyDef);
b2BodyDef secondBodyDef;
secondBodyDef.type = b2_dynamicBody;
secondBodyDef.position.Set(16.0f, 14.0f);
b2Body* secondBody = world->CreateBody(&secondBodyDef);
//// Define another box shape for our dynamic body.
b2PolygonShape dynamicBox,secondBox;
dynamicBox.SetAsBox(3.0f, 3.0f);
secondBox.SetAsBox(3.0f, 3.0f);
//// Define the dynamic body fixture.
b2FixtureDef fixtureDef,secondFixtureDef;
fixtureDef.shape = &dynamicBox;
secondFixtureDef.shape = &secondBox;
//// Set the box density to be non-zero, so it will be dynamic.
fixtureDef.density = 0.5f;
secondFixtureDef.density = 0.5f;
//// Override the default friction.
fixtureDef.friction = 0.3f;
secondFixtureDef.friction = 0.3f;
//// Add the shape to the body.
body->CreateFixture(&fixtureDef);
secondBody->CreateFixture(&secondFixtureDef);
//// Prepare for simulation. Typically we use a time step of 1/60 of a
//// second (60Hz) and 10 iterations. This provides a high quality simulation
//// in most game scenarios.
float32 timeStep = 1.0f / 60.0f;
int32 velocityIterations = -6;
int32 positionIterations = -2;
while (1)
{
[...]
b2Vec2 position = body->GetPosition();
float32 angle = body->GetAngle();
//mc[0]->m_x = (int)(10*position.x);
//mc[0]->m_y = (int)(10*position.y);
Iw2DFillRect(CIwSVec2((int)(10*position.x),(int)(10*position.y)),CIwSVec2(60,60));
Iw2DFillRect(CIwSVec2((int)(10*(secondBody->GetPosition()).x),(int)(10*(secondBody->GetPosition()).y)),CIwSVec2(60,60));
[...]
}
//// Do we want to let bodies sleep?
bool doSleep = true;
//// Construct a world object, which will hold and simulate the rigid bodies.
b2World *world = new b2World(gravity, doSleep);
//// Define the ground body.
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0.0f, 48.0f);
//// Call the body factory which allocates memory for the ground body
//// from a pool and creates the ground box shape (also from a pool).
//// The body is also added to the world.
b2Body* groundBody = world->CreateBody(&groundBodyDef);
//// Define the ground box shape.
b2PolygonShape groundBox;
//// The extents are the half-widths of the box.
groundBox.SetAsBox(24.0f, 1.0f);
//// Add the ground fixture to the ground body.
groundBody->CreateFixture(&groundBox, 0.0f);
//// Define the dynamic body. We set its position and call the body factory.
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(16.0f, 24.0f);
b2Body* body = world->CreateBody(&bodyDef);
b2BodyDef secondBodyDef;
secondBodyDef.type = b2_dynamicBody;
secondBodyDef.position.Set(16.0f, 14.0f);
b2Body* secondBody = world->CreateBody(&secondBodyDef);
//// Define another box shape for our dynamic body.
b2PolygonShape dynamicBox,secondBox;
dynamicBox.SetAsBox(3.0f, 3.0f);
secondBox.SetAsBox(3.0f, 3.0f);
//// Define the dynamic body fixture.
b2FixtureDef fixtureDef,secondFixtureDef;
fixtureDef.shape = &dynamicBox;
secondFixtureDef.shape = &secondBox;
//// Set the box density to be non-zero, so it will be dynamic.
fixtureDef.density = 0.5f;
secondFixtureDef.density = 0.5f;
//// Override the default friction.
fixtureDef.friction = 0.3f;
secondFixtureDef.friction = 0.3f;
//// Add the shape to the body.
body->CreateFixture(&fixtureDef);
secondBody->CreateFixture(&secondFixtureDef);
//// Prepare for simulation. Typically we use a time step of 1/60 of a
//// second (60Hz) and 10 iterations. This provides a high quality simulation
//// in most game scenarios.
float32 timeStep = 1.0f / 60.0f;
int32 velocityIterations = -6;
int32 positionIterations = -2;
while (1)
{
[...]
b2Vec2 position = body->GetPosition();
float32 angle = body->GetAngle();
//mc[0]->m_x = (int)(10*position.x);
//mc[0]->m_y = (int)(10*position.y);
Iw2DFillRect(CIwSVec2((int)(10*position.x),(int)(10*position.y)),CIwSVec2(60,60));
Iw2DFillRect(CIwSVec2((int)(10*(secondBody->GetPosition()).x),(int)(10*(secondBody->GetPosition()).y)),CIwSVec2(60,60));
[...]
}

boxes fall down but they come to occupy the same space. they do not come to rest one upon each other as I hoped they would.
Please, please, please point to me what am i missing!?
<edit*> I noticed that i have 0.5f density...The density was 1.0f but had no different effect. I am actually looking for something like : "AllowCollisionOfDinamycBodyes(true);"