Creating Body and add it in World (BOX2D)


So we have covered the tutorial in last page about physics world and how we can create it, now its time for adding something in the world and play with it
// creating BodyDefinition

Here we create Dynamic Bodies.

b2BodyDef myBodyDef;
myBodyDef.type = b2_dynamicBody;
// create Shape Definition

b2PolygonShape polygonShape;
polygonShape.SetAsBox(1, 1); //a 2×2 rectangle

//fixture definition
b2FixtureDef myFixtureDef;
myFixtureDef.shape = &polygonShape;
myFixtureDef.density = 1;

//create dynamic bodies
m_world->CreateBody(&myBodyDef)->CreateFixture(&myFixtureDef); /// Body created and added into world



Leave a Reply

Your email address will not be published. Required fields are marked *