Knowledge about box2d

Source: Internet
Author: User
The cocos2d-x engine supports two physical engines, box2d and chipmunk, respectively. It is usually used as box2d. The concepts in box2d are as follows. World, body, bodydef, fixture, fixturedef, shape, and joint) and link definition (jointdef ). World: two steps are required to create a world: 1. Generate a Gravity Vector. 2. generate an object based on the gravity vector. For example: // generate a Gravity Vector b2vec2 gravity; gravity. set (0.0f,-10.0f); // generates the world object b2world * World = new b2world (gravity, true) based on the gravity vector ); Rigid Body and rigid body definition: a rigid body represents a particle, so it has only a position and no size. There are three types of rigid bodies: 1. Static rigid bodies ). No quality, no speed. Absolutely static. 2. prismatic body ). No quality, but speed. The engine calculates and updates its location based on the speed. 3. dynamic body ). Quality and speed. The most common rigid body. Similar to the world, a rigid body definition can be divided into two steps: 1. Create a rigid body definition. 2. Generate a rigid body according to the cylinder definition. Eg: // generate a rigid body definition b2bodydef groundbodydef; groundbodydef. position. Set (0, 0); // generate a rigid body b2body * groundbody = World-> createbody (& groundbodydef) based on the rigid body definition ); Shape: The shape is attached to the rigid body by association, and the rigid body has a visual shape. A rigid body can have multiple associations, so it can have multiple shapes. box2d is called a compound shapes to form more complex shapes. Eg: b2polygonshape dynamicbox; dynamicbox. setasbox (0.5f, 0.5f ); Association and association definition: Create Association: 1. Create Association definition. 2. Create associations using world-related methods. Eg: b2fixturedef fixturedef; fixturedef. shape = & dynamicbox; fixturedef. dynsity = 1.0f; fixturedef. friction = 3.0f; // generate the association b2fixture * fixture = body-> createfixtrue (& fixturedef) according to the association definition ); Link and link definition: A link is used to associate multiple rigid bodies so that they can interact with each other. There are many types of links. You must select the desired type. The same two steps: 1. Define. 2. Create according to the definition. Eg: b2linejointdef jointdef; b2vec2 axis (2.0f, 1.0f); axis. normalize (); jointdef. initialize (ground, body, b2vec2 (0.0f, 8.5f), axis); jointdef. motorspeed = 0.0f; jointdef. maxmotorforce = 100366f; jointdef. enablemotor = true; jointdef. lowertransltaion =-4.0f; jointdef. uppertranslation = 4.0f; jointdef. enablelimit = true; // generate the link b2joint * Joint = m_world-> createjoint (& jointdef) based on the link definition ); This blog is from
Ashuldo
, Reprinted please indicate the source:
Http://blog.csdn.net/fansongy/article/details/8846403

 

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.