Box2D

  A Quick Introduction





Box2D Entities




  • Body 
  • Fixture
  • Shape
  • Joint
  • Contact
  • World

Body


  • A point (no size or shape). 
  • Got Position & Velocity.
  • All bodies in Box2D are rigid.
  • Can "carry" fixtures.
  • 3 types of bodies: 
    • Static 
    • Dynamic 
    • kinematic

[ Static ] Body


  • Has infinite mass
  • No Velocity, (position is set by user)
  • Does not collide with other static bodies.
  • Used as walls, platforms etc... 

[ Dynamic ] Body



  • Fully simulated - i,e can be moved by force.
  • Can collide with all 3 types
  • Has a mass (finite)

[ kinematic ] Body


  • Hybrid of static & dynamic
  • Can have velocity
  • No response to forces
  • Collide only with dynamic bodies only
  • Used for things like moving platforms etc...


    Fixture

    =

    shape + (density, friction, etc...)


    Fixture Properties


    • Density  -> used to compute the mass of the parent body
    • Friction  -> used to compute friction on contact...
    • Restitution  -> used to make stuff bounce!

    Shapes



    •  Simple classes to describe collision geometry
    • Box2D supports ellipses and convex polygons 
    • Also "Edge Shape" & "Chain Shape"                                          



      Force & Impulse


      • b2Body.ApplyImpulse() - Bam! all at once
      • b2Body.ApplyForce() - slow
      • b2Body.SetLinearVelocity() -  ignore simulation 


      • b2Body.SetLinearDamping() - affects all forces 
      • b2Body.SetGravityScale() - affects gravity

      Collisions!



      • Are managed with contacts

      Joints


      • Distance Joint - keeps constant distance
      • Revolute Joint - Rotate around a point
      • Prismatic Joint - keeps rotation aligned
      • Pulley Joint - 1 up and 1  down
      • And a few more...

      Using Box2D with QT



      Demo

       

      Questions?

      Box2D Quick Intro

      By Vitali Perchonok