Tuesday, December 24, 2013

box2d small problem

b2BodyDef groundBodyDef; / / object definitions
groundBodyDef.position.Set (screenSize.width/2/PTM_RATIO, screenSize.height/2/PTM_RATIO); / / bottom-left corner
/ / 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;
/ / Bottom
groundBox.SetAsBox (screenSize.width/2/PTM_RATIO, 0, b2Vec2 (0, -screenSize.height/2/PTM_RATIO), 0);
groundBody-> CreateFixture (& groundBox, 0);

/ / Top
groundBox.SetAsBox (screenSize.width/2/PTM_RATIO, 0, b2Vec2 (0, screenSize.height/2/PTM_RATIO), 0);
groundBody-> CreateFixture (& groundBox, 0);

/ / Left
groundBox.SetAsBox (0, screenSize.height/2/PTM_RATIO, b2Vec2 (-screenSize.width/2/PTM_RATIO, 0), 0);
groundBody-> CreateFixture (& groundBox, 0);

/ / Right
groundBox.SetAsBox (0, screenSize.height/2/PTM_RATIO, b2Vec2 (screenSize.width/2/PTM_RATIO, 0), 0);

groundBody-> CreateFixture (& groundBox, 0);


Create a code defined in the test ground objects with a sentence groundBodyDef.position.Set (screenSize.width/2/PTM_RATIO, screenSize.height/2/PTM_RATIO); / / bottom-left corner, why there is such a coordinate position the? Finally, create a ground box and how the process of?
Find explain, thank you

No comments:

Post a Comment