I. Concepts of box2d
1.1Rigid Body, particle, only the position has no size
- Static rigid body: the static rigid body has no quality and no speed. You can manually change its position.
- Motion rigid body: the motion rigid body has no quality, but can have a speed. You can update the position on your own.
- Dynamic rigid body: the dynamic rigid body has both quality and speed.
Create a Rigid Body
B2bodydef bodydef; // defines a rigid bodydef. type = b2_dynamicbody; // define the type of the Rigid Body b2_staticbody *, b2_kinematicbody, b2_dynamicbodybodydef.position.set (x/ptm_ratio, Y/ptm_ratio); // set the position of the rigid body, box2d uses meters as the unit, so the pixel is converted to meters, and 32 pixels are 1 meters b2body * groundbody = World-> createbody (& bodydef); // create a rigid body according to the definition of the Rigid Body
1.2Shape, added to the rigid body for collision, with friction and recovery and other material characteristics
B2polygonshape dynamicbox; // define a dynamicbox. setasbox (. 5f,. 5f) shape; // set the midpoint of the box to 1 m in length and width.
1.3An association is an attribute attached to a rigid body. A rigid body can have multiple associations.
B2fixturedef fixturedef; // defines an association fixturedef. shape = & dynamicbox; // The associated shape fixturedef. density = 1.0f; // density fixturedef. friction = 0.3f; // friction body-> createfixture (& fixturedef); // create a rigid body Association
1.4Link. You can contact multiple rigid bodies.
B2revolutejointdef rjd; // defines a link to rjd. initialize (m_attachment, m_platform, b2vec2 (0.0f, 5.0f); rjd. maxmotortorque = 50366f; rjd. enablemotor = true; World-> createjoint (& rjd );
1.5Constraints
1.6World
B2vec2 gravity; // defines the gravity. set (0.0f,-10.0f); // set the gravity direction to-10 world = new b2world (gravity); // create the world-> setallowsleeping (true ); // world-> setcontinuousphysics (true );
Link: http://blog.linguofeng.com/pages/language/c/box2d.html