Basic box2d knowledge

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.