Game Development Reference
In-Depth Information
Meeting the world
Most of the time, the physics simulation will mean the creation of a b2World object.
Note, however, that you can get interesting results managing more than one world object
in the same game, for multiple views for instance. But that's for another topic.
In our simplified basic project, the world is created like this:
b2Vec2 gravity;
gravity.Set(0.0f, -10.0f);
world = new b2World(gravity);
// Do we want to let bodies sleep?
world->SetAllowSleeping(true);
world->SetContinuousPhysics(true);
_debugDraw = new (std::nothrow) GLESDebugDraw( PTM_RATIO );
world->SetDebugDraw(_debugDraw);
uint32 flags = 0;
flags += b2Draw::e_shapeBit;
// flags += b2Draw::e_jointBit;
// flags += b2Draw::e_aabbBit;
// flags += b2Draw::e_pairBit;
// flags += b2Draw::e_centerOfMassBit;
_debugDraw->SetFlags(flags);
Box2D has its own vector structure, b2Vec2 , and we use it here to create the world's grav-
ity. The b2World object receives that as its parameter. A simulation does not always re-
quire gravity, of course; in that case, the argument will be a (0, 0) vector.
SetAllowSleeping means if objects are not moving and therefore not generating de-
rived data, skip checking for derived data from those objects.
SetContinuousPhysics means we have some fast objects in our hands, which we'll
later point out to the simulation, so it can pay extra attention for collisions.
Search WWH ::




Custom Search