Пример #1
0
    pulley(float x,float y, float l_density, float r_density, b2World *m_world)
    {
        b2Vec2 shift = b2Vec2(x,y);
        b2BodyDef *bd = new b2BodyDef;
        bd->type = b2_dynamicBody;
        bd->position.Set(-10+x,15+y);
        bd->fixedRotation = true;

        //The open box
        b2FixtureDef *fd1 = new b2FixtureDef;
        fd1->density = l_density;///default 10.0f
        fd1->friction = 0.5;
        fd1->restitution = 0.f;
        fd1->shape = new b2PolygonShape;
        b2PolygonShape bs1;
        bs1.SetAsBox(2,0.2, b2Vec2(0.f,-1.9f)+shift, 0);
        fd1->shape = &bs1;
        b2FixtureDef *fd2 = new b2FixtureDef;
        fd2->density = l_density;///default 10.0f
        fd2->friction = 0.5;
        fd2->restitution = 0.f;
        fd2->shape = new b2PolygonShape;
        b2PolygonShape bs2;
        bs2.SetAsBox(0.2,2, b2Vec2(2.0f,0.f)+shift, 0);
        fd2->shape = &bs2;
        b2FixtureDef *fd3 = new b2FixtureDef;
        fd3->density = l_density;///default 10.0f
        fd3->friction = 0.5;
        fd3->restitution = 0.f;
        fd3->shape = new b2PolygonShape;
        b2PolygonShape bs3;
        bs3.SetAsBox(0.2,2, b2Vec2(-2.0f,0.f)+shift, 0);
        fd3->shape = &bs3;

        b2Body* box1 = m_world->CreateBody(bd);
        box1->CreateFixture(fd1);
        box1->CreateFixture(fd2);
        box1->CreateFixture(fd3);

        //The bar
        bd->position.Set(25+x,15+y);
        fd1->density = r_density;///default 34.0f
        b2Body* box2 = m_world->CreateBody(bd);
        box2->CreateFixture(fd1);

        // The pulley joint
        b2PulleyJointDef* myjoint = new b2PulleyJointDef();
        b2Vec2 worldAnchorOnBody1(-10, 15); // Anchor point on body 1 in world axis
        b2Vec2 worldAnchorOnBody2(25, 15); // Anchor point on body 2 in world axis
        b2Vec2 worldAnchorGround1(-10+x, 20+y); // Anchor point for ground 1 in world axis
        b2Vec2 worldAnchorGround2(25+x, 20+y); // Anchor point for ground 2 in world axis
        float32 ratio = 1.0f; // Define ratio
        myjoint->Initialize(box1, box2, worldAnchorGround1+shift, worldAnchorGround2+shift, box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
        m_world->CreateJoint(myjoint);
    }
Пример #2
0
pulley_j(b2Body* box1,b2Body* box2,float b1x,float b1y,float b2x,float b2y,float g1x,float g1y,float g2x,float g2y,b2World* m_world){

      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody1(b1x, b1y); // Anchor point on body 1 in world axis
      b2Vec2 worldAnchorOnBody2(b2x, b2y); // Anchor point on body 2 in world axis
      b2Vec2 worldAnchorGround1(g1x, g1y); // Anchor point for ground 1 in world axis
      b2Vec2 worldAnchorGround2(g2x, g2y); // Anchor point for ground 2 in world axis
      float32 ratio = 1.0f; // Define ratio
      myjoint->Initialize(box1, box2, worldAnchorGround1, worldAnchorGround2, box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);

}
Пример #3
0
  dominos_t::dominos_t()
  {
    //Ground
    /*! \var b1 
     * \brief pointer to the body ground 
     */ 
    b2Body* b1;  
    {
      
      b2EdgeShape shape; 
      shape.Set(b2Vec2(-90.0f, 0.0f), b2Vec2(90.0f, 0.0f));
      b2BodyDef bd; 
      b1 = m_world->CreateBody(&bd); 
      b1->CreateFixture(&shape, 0.0f);
    }
          
    //Top horizontal shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(6.0f, 0.25f);
	
      b2BodyDef bd;
      bd.position.Set(-31.0f, 30.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }

    //Dominos
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.0f);
	
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
		
      for (int i = 0; i < 8; ++i)
	{
	  b2BodyDef bd;
	  bd.type = b2_dynamicBody;
	  bd.position.Set(-35.5f + 1.0f * i, 31.25f);
	  b2Body* body = m_world->CreateBody(&bd);
	  body->CreateFixture(&fd);
	}
    }
    //Added sphere
    {
      b2Body* sbody;
      b2CircleShape circle;
      circle.m_radius = 1.0;
	
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 5.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(-26.5f, 31.25f);
      sbody = m_world->CreateBody(&ballbd);
      sbody->CreateFixture(&ballfd);
    }
      
    //Another horizontal shelf
    /*
    {
      b2PolygonShape shape;
      shape.SetAsBox(7.0f, 0.25f, b2Vec2(-20.f,20.f), 0.0f);
	
      b2BodyDef bd;
      bd.position.Set(1.0f, 6.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
	*/

    //The pendulum that knocks the dominos off
    {
      b2Body* b2;
      {
	b2PolygonShape shape;
	shape.SetAsBox(0.0f, 0.f);
	  
	b2BodyDef bd;
	bd.position.Set(-36.5f, 42.0f);
	b2 = m_world->CreateBody(&bd);
	b2->CreateFixture(&shape, 0.0f);
      }
	
      b2Body* b4;
      {
	b2PolygonShape shape;
	shape.SetAsBox(0.25f, 0.25f);
	  
	b2BodyDef bd;
	bd.type = b2_dynamicBody;
	bd.position.Set(-40.0f, 33.0f);
	b4 = m_world->CreateBody(&bd);
	b4->CreateFixture(&shape, 2.0f);
      }
	
      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-37.0f, 40.0f);
      jd.Initialize(b2, b4, anchor);
      m_world->CreateJoint(&jd);
    }
      
    //The train of small spheres
    /*
    {
      b2Body* spherebody;
	
      b2CircleShape circle;
      circle.m_radius = 0.5;
	
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 1.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
	
      for (int i = 0; i < 10; ++i)
	{
	  b2BodyDef ballbd;
	  ballbd.type = b2_dynamicBody;
	  ballbd.position.Set(-22.2f + i*1.0, 26.6f);
	  spherebody = m_world->CreateBody(&ballbd);
	  spherebody->CreateFixture(&ballfd);
	}
    }
    */

    //The pulley system
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-10,15);
      bd->fixedRotation = true;
      
      //The open box
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.0;
      fd1->restitution = 0.f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(2,0.2, b2Vec2(-12.f,2.1f), 0);
      fd1->shape = &bs1;
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.5;
      fd2->restitution = 0.f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.2,2, b2Vec2(-10.0f,4.f), 0);
      fd2->shape = &bs2;
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 10.0;
      fd3->friction = 0.5;
      fd3->restitution = 0.f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape bs3;
      bs3.SetAsBox(0.2,2, b2Vec2(-14.0f,4.f), 0);
      fd3->shape = &bs3;
       
      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);
      box1->CreateFixture(fd2);
      box1->CreateFixture(fd3);

      //The bar
      bd->position.Set(0,15);	
      fd1->density = 34.0f;	  
      b2Body* box2 = m_world->CreateBody(bd);
      box2->CreateFixture(fd1);

      // The pulley joint
      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody1(-22, 19); // Anchor point on body 1 in world axis
      b2Vec2 worldAnchorOnBody2(-12, 19); // Anchor point on body 2 in world axis
      b2Vec2 worldAnchorGround1(-22, 24); // Anchor point for ground 1 in world axis
      b2Vec2 worldAnchorGround2(-12, 24); // Anchor point for ground 2 in world axis
      float32 ratio = 1.0f; // Define ratio
      myjoint->Initialize(box1, box2, worldAnchorGround1, worldAnchorGround2, box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);
    }

    //The revolving horizontal platform
    {
      b2PolygonShape shape;
      shape.SetAsBox(2.2f, 0.2f);
	
      b2BodyDef bd;
      bd.position.Set(-8.8f, 20.0f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 1.f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      body->CreateFixture(fd);

      b2PolygonShape shape2;
      shape2.SetAsBox(0.2f, 2.0f);
      b2BodyDef bd2;
      bd2.position.Set(-8.8f, 20.0f);
      b2Body* body2 = m_world->CreateBody(&bd2);

      b2RevoluteJointDef jointDef;
      jointDef.bodyA = body;
      jointDef.bodyB = body2;
      jointDef.localAnchorA.Set(0,0);
      jointDef.localAnchorB.Set(0,0);
      jointDef.collideConnected = false;
      m_world->CreateJoint(&jointDef);
    }

    //The heavy sphere on the platform
    {
      b2Body* sbody;
      b2CircleShape circle;
      circle.m_radius = 1.0;
	
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 5.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(-8.8f, 22.0f);
      sbody = m_world->CreateBody(&ballbd);
      sbody->CreateFixture(&ballfd);
    }

    //Box
    /*{
      b2PolygonShape shape;
      shape.SetAsBox(1.8f, 0.10f);
	
      b2BodyDef bd;
      bd.position.Set(-6.0f, 16.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
    {

      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-10,15);
      bd->fixedRotation = true;


      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.0;
      fd1->restitution = 0.f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(2,0.2, b2Vec2(-6.f,22.0f), 0);
      fd1->shape = &bs1;
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.5;
      fd2->restitution = 0.f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.2,2, b2Vec2(-4.0f,23.9f), 0);
      fd2->shape = &bs2;
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 10.0;
      fd3->friction = 0.5;
      fd3->restitution = 0.f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape bs3;
      bs3.SetAsBox(0.2,2, b2Vec2(-8.0f,23.9f), 0);
      fd3->shape = &bs3;

      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);
      box1->CreateFixture(fd2);
      box1->CreateFixture(fd3);
  	}*/
  	//train of pendulums
  	{
      b2Body* b2;
      
	b2PolygonShape shape;
	shape.SetAsBox(2.0f, 0.0f);

	//b2BodyDef bd;
	//bd.position.Set(-36.5f, 38.0f);
	//b2 = m_world->CreateBody(&bd);
	//b2->CreateFixture(&shape, 0.0f);
      

      b2Body* b4;
      
    b2CircleShape circle;
    circle.m_radius = 0.5;
	//b2PolygonShape shape;
	//shape.SetAsBox(0.25f, 0.25f);

    b2FixtureDef ballfd;
    ballfd.shape = &circle;
    ballfd.density = 5.0f;
    ballfd.friction = 0.0f;
    ballfd.restitution = 0.0f;
    for (int i = 0; i < 7; ++i)
	{
	  b2BodyDef bd;
	  bd.position.Set(-7.0f + i*1.0, 28.0f);
	  b2 = m_world->CreateBody(&bd);
	  b2->CreateFixture(&shape, 0.0f);
	  b2BodyDef ballbd;
	  ballbd.type = b2_dynamicBody;
	  ballbd.position.Set(-7.0f + i*1.0, 22.0f);
	  b4 = m_world->CreateBody(&ballbd);
	  b4->CreateFixture(&ballfd);
	  b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-7.0f + i*1.0, 28.0f);
      jd.Initialize(b2, b4, anchor);
      m_world->CreateJoint(&jd);
	}
	}

	//Horizontal Platform before Boat
	{
      b2PolygonShape shape;
      shape.SetAsBox(3.0f, 0.25f);
	
      b2BodyDef bd;
      bd.position.Set(2.2f, 20.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }

    //The sphere on the platform which hits boat
    {
      b2Body* sbody;
      b2CircleShape circle;
      circle.m_radius = 1.0;
	
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 5.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(1.0f, 21.0f);
      sbody = m_world->CreateBody(&ballbd);
      sbody->CreateFixture(&ballfd);
    }

//horizontal lines
	{
      b2PolygonShape shape;
      shape.SetAsBox(6.0f, 0.001f);
	
      b2BodyDef bd;
      bd.position.Set(5.0f, 15.0f);
      bd.angle = -75;
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }


	{
      b2PolygonShape shape;
      shape.SetAsBox(6.0f, 0.001f);
	  b2BodyDef bd;
      bd.position.Set(0.0f, 10.0f);
      bd.angle = 75;
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    } 

	{
      b2PolygonShape shape;
      shape.SetAsBox(0.001f, 1.5f);
	
      b2BodyDef bd;
      bd.position.Set(-5.0f, 13.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }  



    //The see-saw system at the bottom
    {
      //The triangle wedge
      b2Body* sbody;
      b2PolygonShape poly;
      b2Vec2 vertices[3];
      vertices[0].Set(-1,0);
      vertices[1].Set(1,0);
      vertices[2].Set(0,1.5);
      poly.Set(vertices, 3);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(30.0f, 0.0f);
      sbody = m_world->CreateBody(&wedgebd);
      sbody->CreateFixture(&wedgefd);

      //The plank on top of the wedge
      b2PolygonShape shape;
      shape.SetAsBox(15.0f, 0.2f);
      b2BodyDef bd2;
      bd2.position.Set(17.0f, 1.5f);
      bd2.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd2);
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 1.f;
      fd2->shape = new b2PolygonShape;
      fd2->shape = &shape;
      body->CreateFixture(fd2);

      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(30.0f, 1.5f);
      jd.Initialize(sbody, body, anchor);
      m_world->CreateJoint(&jd);

      //The light box on the right side of the see-saw
      b2PolygonShape shape2;
      shape2.SetAsBox(2.0f, 2.0f);
      b2BodyDef bd3;
      bd3.position.Set(40.0f, 2.0f);
      bd3.type = b2_dynamicBody;
      b2Body* body3 = m_world->CreateBody(&bd3);
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 0.01f;
      fd3->shape = new b2PolygonShape;
      fd3->shape = &shape2;
      body3->CreateFixture(fd3);
    }
  }
/*
 * Base code for CS 251 Software Systems Lab
 * Department of Computer Science and Engineering, IIT Bombay
 *
 */


#include "cs251_base.hpp"
#include "render.hpp"

#ifdef __APPLE__
  #include <GLUT/glut.h>
#else
  #include "GL/freeglut.h"
#endif

#include <cstring>
using namespace std;

#include "dominos.hpp"

namespace cs251
{  /**  
   *  A constructor function for the dominos_t class.
   *  Sets up the Box2D simulation.
   *  Creates 18 simulation objects
   *      -# Ground Object
   *      -# Horizontal Shelves
   *      -# Redirecting Curvy Ramp
   *      -# Top Pendulum that knocks 5 Dominos
   *      -# Sphere on Top Platform(Kick Off)   
   *      -# Series of 5 Dominos on Top Platform
   *      -# See Saw System
   *      -# The Pushing Box(Nothing much? Not Really!)
   *      -# Chain of Pendulums that move the Saw
   *      -# Saw System
   *      -# The Three Plank System
   *      -# Pulley System with on Open Box and two Loading Slabs
   *      -# Revolvable Horizontal Platform
   *      -# A Heavy Sphere
   *      -# See Saw Series System
   *      -# The Containers 
   *      -# Small Car
   *      -# The 2 Rotating Fans
   *      
   *      
   *  The chain of events as seen in when the code is run are as follows,
   *  The pendulum bob hits one of the dominos in series.
   *  The last one of the dominos hits the heavy balls.
   *  The heavy ball bounces over the see saw and make the light box go up, while it falls down into the left container
   *  The light box pushes the chain of pendulums which then pushes the saw.
   *  The saw then cuts the rope.
   *  The ball pushes the dominos and all the dominos on the 3 planks fall down one by one in series.
   *  The last revolving domino taps the sphere on the horizontal plank below.
   *  The sphere falls into the open box of the pulley i.e. pulls up the loading bars.
   *  The 4 spheres in the loaded bars fall down into the other(right) container.
   *  The 1st sphere which had fallen into the adjacent see-saw's open box now is thrown up.
   *  The sphere is made to roll down to the right to push the car up the ramp.
   *  Finally the car touches the switch to make the fans rotate. :)
   *  Now we can have some cool air! :P
   */
  dominos_t::dominos_t()
  {
     //Ground
    // \var ground
    /*! 1) Ground Object.
     * -# Defines a b2Body object pointer to the ground object as the reference point/level for other objects in the simulation.
     * -# Points to an edge-shaped object in the Box2D simulation.
     * -# Creates a b2EdgeShape object 'shape', a b2BodyDef object 'bd', required to create the Ground object.
     */
     b2Body* ground;
    { b2EdgeShape shape;
      shape.Set(b2Vec2(-90.0f, 0.0f), b2Vec2(90.0f, 0.0f));
      b2BodyDef bd;
      ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
     } 
    
     //Top horizontal shelf
    // \var b1 (local)
    /*! 2) Horizontal Shelves.
     *  - 2.1) Top Horizontal shelf object.
     *   -# Creates a shelf modelled as a horizontal box.
     *   -# Uses b2PolygonShape 'shape' to define shape of the b2Body object 'b1' which represents the horizontal shelf.
     */
    
    {
      b2PolygonShape shape;
      shape.SetAsBox(3.1f, 0.25f);

      b2BodyDef bd;
      bd.position.Set(-31.0f, 38.0f);
       b2Body* b1 = m_world->CreateBody(&bd);
      b1->CreateFixture(&shape, 0.0f);
    }
    //horizontal shelf
    // \var b1 (local)
    /*! - 2.2) Another horizontal shelf object.
     *
     *    -# Creates a shelf modelled as a horizontal box.
     *    -# Uses b2PolygonShape 'shape' to define shape of the b2Body object 'b1' which represents the horizontal shelf.
     */
    {
      b2PolygonShape shape;
      shape.SetAsBox(13.f, 0.5f);

      b2BodyDef bd21;
      bd21.position.Set(-22.0f, 25.0f);
      b2Body* b1 = m_world->CreateBody(&bd21);
      b1->CreateFixture(&shape, 0.5f);

     // redirecting edges for the ball on the top
     /*! 
     *  3) Redirecting Curvy Ramp. 
     *  -# Creates a redirecting Curvy Ramp modelled as a set of edges in succession forming a curvy connected component.
     *  -# Uses b2EdgeShape to define 'shape(l/r)' of the b2Body object 'left/right' which represent the curvy slopes.
     *  -# Redifined shape(l/r) to reuse the variable for creating set of connected-edges.
     *  -# Redirecting Path : This element is right below the saw and has similar definition.
     */
   
      b2Body* left;
      b2Body* right;
      b2EdgeShape shapel, shaper;
        //shapel.Set(b2Vec2(-31.5f, 29.0f), b2Vec2(-33.0f, 32.0f));
      float x=-28.5, y=29.0, x2=-27.5;
      for(int i=0;i<3;i++)
      {
        shapel.Set(b2Vec2(x,y), b2Vec2(x-(3-i)*0.6, y+(1+i)*0.6));
        shaper.Set(b2Vec2(x2,y+4.f), b2Vec2(x2+(3-i)*0.6, y+4.f+(1+i)*0.6));
        x=x-(3-i)*0.6;
        x2=x2+(3-i)*0.6;
        y=y+(1+i)*0.6;
        b2BodyDef bd;
        left = m_world->CreateBody(&bd);
        right = m_world->CreateBody(&bd);
        left->CreateFixture(&shapel, 0.0f);
        right->CreateFixture(&shaper, 0.0f);
      }
    }

    //The pendulum that knocks the dominos off
    /*! 4) Top Pendulum that knocks the 5 Dominos.
     *  - 4.1) Pendulum-Stand-Base object.
     *   -# A b2Body pointer 'b2' to the pendulum-stand's base's object, in the simulation, modelled as a rectangular box.
     *   -# Defines b2PolygonShape 'shape' to define the box-shape of the base.
     *   -# 'b2' is defined as bodyA in the definition of revolute joint for pendulum.
     */
    {

      b2Body* b2;
      {
        b2PolygonShape shape;
        shape.SetAsBox(0.25f, 0.5f);

        b2BodyDef bd;
        bd.position.Set(-34.5f, 38.0f);
        b2 = m_world->CreateBody(&bd);
        b2->CreateFixture(&shape, 10.0f);
      }

    
    // \var b4(local) 
    /*! - 4.2) Pendulum Bob.
     *
     *   -# A b2Body pointer 'b4' to the bob object hanging from a point, to act as a supended pendulum bob in the simulation, modelled as a small dense square box.
     *   -# Defines b2PolygonShape shape to define the small-box-shape of the bob. 
     *   -# Creates a b2RevoluteJointDef object 'jd' to create a revolute joint between an anchor point and the bob(bodyB/'b4') 
     */
      b2Body* b4;
      {
        b2PolygonShape shape;
        shape.SetAsBox(0.25f, 0.25f);

        b2BodyDef bd;
        bd.type = b2_dynamicBody;
        bd.position.Set(-38.0f, 41.50f);
        b4 = m_world->CreateBody(&bd);
        b4->CreateFixture(&shape, 25.0f);
      }
      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-34.5f, 45.0f);
      jd.Initialize(b2, b4, anchor);

      m_world->CreateJoint(&jd);
    }

    //The sphere on the top platform
    // var: sbody (local)
    /*! 5) Sphere on Top Platform.
     *  -# Creates pointer 'sbody' to a heavy sphere objects created on the top horizontal plank/platform.
     *  -# Points to a (b2CircleShape)circle/sphere-shaped object in the Box2D simulation.
     *  -# Creates a b2CircleShape object 'circle', a b2BodyDef object 'ballbd', b2FixtureDef ballfd.
     */
    {
      b2Body* sbody;
      b2CircleShape circle;
      circle.m_radius = 1.0;

      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 15.0f;
      ballfd.friction = 1.0f;
      ballfd.restitution = 0.7f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(-28.f, 38.25f);
      sbody = m_world->CreateBody(&ballbd);
      sbody->CreateFixture(&ballfd);
      sbody->SetId(3);
    }

    //Dominos on the top
    //  var: body (local)
    /*! 6) Series of 5 Dominos on Top Horizontal Shelf(Start the game :P).
     *   -# Creates 5 dominos on the above created horizontal shelf, modelled as thin boxes.
     *   -# b2FixtureDef object 'fd' used to specifying physical properties(density, friction, shape) of the b2Body 'body' object(for each domino).
     *   -# b2bodyDef object 'bd' used as body-definition for each b2Body 'body' representing a domino in the simulation.
     */
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.0f);

      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;

      for (int i =0; i < 5; ++i)
      {
       b2BodyDef bd;
       bd.type = b2_dynamicBody;
       bd.position.Set(-33.5f + 1.0f * i, 40.f);
       b2Body* body = m_world->CreateBody(&bd);
       body->CreateFixture(&fd);
      }
    }

    //The see-saw system
    /*! 7) See Saw system.
     * - See saw is modelled as a plank joined with a triangular which acts as its fulcrum.
     * Uses b2PolygonShape to define shapes(rectangular/triangular) of the b2Body objects(plank/fulcrum).
     * Define a revolute joint between plank and th tip of wedge.
     */
    {
      //The triangle wedge
      // var: sbody (local)
     /*! - 7.1) See Saw system fulcrum.
      *
      *   -# Fulcrum is modelled as a triangle, simply a 3 vertex polygon.
      *   -# Uses b2PolygonShape to define 'poly' shape of the b2Body object 'sbody', wihich represents the fulcrum .
      *   -# 'wedgefd' is b2FixtureDef for 'sbody', defining its b2PolygonShape 'poly' and density, friction, resitution with (b2FixtureDef)wedgefd.
      */
      b2Body* sbody;
      b2PolygonShape poly;
      b2Vec2 vertices[3];
      vertices[0].Set(-1,0);
      vertices[1].Set(1,0);
      vertices[2].Set(0,1);
      poly.Set(vertices, 3);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(-20.0f, 25.5f);
      sbody = m_world->CreateBody(&wedgebd);
      sbody->CreateFixture(&wedgefd);
      //The plank on top of the wedge
       //  var: body (local)
      /*!  - 7.2) The Plank.
       *
       *     -# Creates a plank modelled as a flattened (horizontal) box.
       *     -# Defines b2PolygonShape 'shape' for the flattened shape and b2FixtureDef 'fd2' to define the physical properties (density,shape) of the b2Body object 'body', which represents the plank.
       *     -# Defines b2RevoluteJointDef to define a revolute joint between the plank, and the tip of the wedge(fulcrum), on which it rests, at its center. 
       */   
      b2PolygonShape shape;
      shape.SetAsBox(8.0f, 0.2f);
      b2BodyDef bd2;
      bd2.position.Set(-20.0f, 26.5f);
      bd2.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd2);
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 1.f;
      fd2->shape = new b2PolygonShape;
      fd2->shape = &shape;
      body->CreateFixture(fd2);

      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-20.0f, 26.5f);
      jd.Initialize(sbody, body, anchor);
      m_world->CreateJoint(&jd);
      //The box on the right side of the see-saw
      // var: b3 (local)
     /*! 
      * 8) The Pushing  Box.
      *  -# Creates a light box as a rectangular object in the simulation used to push the pendulum.
      *  -# Uses b2PolygonShape object 'shape2' to define shape of the b2Body object 'b3' which represents the light pushing box.
      *  -# 'fd3' is a b2FixtureDef onject defining the physical properities of 'b3'. Density of the box is 0.1(small)
      */
      b2PolygonShape shape2;
      shape2.SetAsBox(2.0f, 2.0f);
      b2BodyDef bd3;
      bd3.position.Set(-11.f, 28.5f);
      bd3.type = b2_dynamicBody;
      b2Body *b3 = m_world->CreateBody(&bd3);
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = .1f;
      fd3->shape = new b2PolygonShape;
      fd3->shape = &shape2;
      b3->CreateFixture(fd3);
    }

    //The chain of pendulums that push the saw
    {
      // var: b2 (local)
      /*! 
       * 9) Chain of Pendulums that move the Saw.
       * - 9.1) Pendulum-Hinge-Base object.
       *   -# A b2Body pointer 'b2' to the Pendulum-Hinge-Base object on which the pendulum hangs in the simulation, modelled as a wide rectangular box.
       *   -# Defined as bodyA in the definition of revolute joint for pendulum.
       *   -# Creates a b2PolygonShape object 'shape', a b2BodyDef object 'bd', required to create the Pendulum-Hinge-Base object.
       */
      b2Body* b2;
      {
            b2PolygonShape shape;
            shape.SetAsBox(6,0.5f);
            b2BodyDef bd;
            bd.position.Set(7,40);
            b2 = m_world->CreateBody(&bd);
            b2->CreateFixture(&shape, 0.01f);
      }
      // \var b4 
      /*! - 9.2) Pendulum Bob objects.
       *
       *   -# b2Body pointer 'b4' to the pendulum bob object hanging from a point to act, in the simulation, for each pendulem, one by one.
       *   -# Defines b2PolygonShape shape to define the small-box-shape of the bob. 
       *   -# Creates a b2RevoluteJointDef object 'jd' to create a revolute joint between an anchor point and the bob(bodyB/'b4') 
       */
      for(int i=0; i<4; i++)
      {
          b2Body* b4;
         {
            b2CircleShape shape;
            shape.m_radius=2.f;

            b2BodyDef bd;
            bd.position.Set(1.f+i*4, 34.0f);
            bd.type=b2_dynamicBody;
            b4= m_world->CreateBody(&bd);
            b4->CreateFixture(&shape,0.01f);
          }
          b2RevoluteJointDef jd;
          b2Vec2 anchor;
          anchor.Set(1.f+i*4,40);
          jd.Initialize(b2,b4,anchor);

          m_world->CreateJoint(&jd);
      }
    }
      //The saw system(top right)
      // var: sbody (local)
      /*! 10) Saw system.
       *    -# Saw, b2Body 'body', is modelled as a triangle(3 vertices to define 'shape') hung on a small b2Body 'b1'.
       *    -# Uses b2PolygonShape 'poly' to define shape of the b2Body object 'body'.
       *    -# 'fd' is b2FixtureDef for 'body' definig its shape('poly'), density, friction, resitution.
       *    -# Creates a b2MotorJointDef object 'mjd' to create a motor joint, basically to create the effect of a saw.
       */
    {
      b2BodyDef bd;
      bd.position.Set(16.5f,34.0f);
      b2Body* b1=m_world->CreateBody(&bd);
      b2PolygonShape shape;
      shape.SetAsBox(.01f,.01f);
      b2FixtureDef fd;
      fd.shape=&shape;
      fd.density=1.f;
      fd.restitution=0.f;        
      b1->CreateFixture(&fd);

      bd.type=b2_dynamicBody;
      bd.position.Set(15.f,34.0f);
      b2Body* body=m_world->CreateBody(&bd);
      b2Vec2 v[3];
      v[0].Set(0,0.5f);
      v[1].Set(0.,-1.3f);
      v[2].Set(5,.5f);  
      shape.Set(v,3);
      fd.shape=&shape;
      fd.density=.01f;
      fd.friction=1.f;
      body->CreateFixture(&fd); 
  
      b2MotorJointDef mjd;
      mjd.Initialize(b1,body);    
      mjd.maxForce=1.f;
      mjd.maxTorque=1000.f;
      m_world->CreateJoint(&mjd);
    } 
     
   
   // redirecting path
     /* 
     *    - 10.1) Redirecting Curvy Ramp2. 
     *        -# Creates a redirecting Curvy Ramp modelled as a set of edges in succession forming a curvy connected component.
     *        -# Uses b2EdgeShape to define 'shapel' of the b2Body object 'left' which represent the curvy slopes.
     *        -# Redifined 'shapel' to reuse the variable for creating set of connected-edges.
     */
   
      b2Body* left;
      b2EdgeShape shapel, shaper;
      float x=24, y=24;
      for(int i=0;i<3;i++)
      {
        shapel.Set(b2Vec2(x,y), b2Vec2(x-(3-i)*0.8, y+(1+i)*0.6));
        x=x-(3-i)*0.8;
        y=y+(1+i)*0.6;
        b2BodyDef bd;
        left = m_world->CreateBody(&bd);
        left->CreateFixture(&shapel, 0.0f);
      }
    
    

    //Top 3 horizontal planks
    // \var plankbase[3]
    /*! 
     * 11) The Three Plank System.
     */
    /*!  - 11.1) The 3 Base-Planks.
     *    -# Creates 3 b2Body object pointers plankbase[0,1,2] representing 3 shelves modelled as flattened horizontal boxes.
     *    -# Uses b2PolygonShape 'shape' to define shape of the b2Body objects 'plankbase[0,1,2]'.
     *    -# The 'shape' object is changed as plankbase[0](1st plank) is smaller than the rest and placed at a shifted location. Basically, we set 'shape' and bd.position for every plankbase[i] in the loop.
     */ 
    b2Body* plankbase[3];
    {
      b2PolygonShape shape;
      shape.SetAsBox(3.5f, 0.25f);

      b2BodyDef bd;
      bd.position.Set(-31.0f+60.1f, 20.0f+3.0f);
      
      for(int i=0;i<3;i++)
      { plankbase[i] = m_world->CreateBody(&bd);
        plankbase[i]->CreateFixture(&shape, 0.5f);
        bd.position.Set(-31.0f+58.0f, 17.0f+3.0f-3.0f*i);
        shape.SetAsBox(5.6f, 0.25f);
      }  
    }
  
   {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.0f);

      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.7f;
        
      b2Body* body;
      b2BodyDef bd;
      bd.type = b2_dynamicBody;
      
      b2RevoluteJointDef jointDef;
      int lower=4, higher=10;          //jugaad  
     // Dominos series on the three planks 
     // var: body (local)
     /*!  - 11.2) Series of Dominos on 3 Horizontal Shelves.
      *
      *    -# Creates 7,12,12 dominos on the above created 3 horizontal shelves(i:lower-higher in for loop decides location and number of the dominos).
      *    -# b2FixtureDef object 'fd' used to specifying physical properties(density, friction, shape) of the b2Body object 'body'.
      *    -# b2bodyDef object 'bd' used as body-definition for each b2Body 'body' representing a domino in the simulation.
      *    -# Creates b2RevoluteJointDef object 'jointDef' to create revolute joint for 3 dominos, hinged at their bases with the plank-base.
      *    -# Since, the location of these dominos and corresponding joints is asymmetric we broke up for the 3 cases(3 planks) using "switch-case". 
      */
        
      for(int k=0;k<3;k++) 
      { for (int i = lower; i <=higher; ++i)    
         { bd.position.Set(-35.5f+58.0f + 1.0f * i, 21.25f+3.0f-k*3.0f);
           body = m_world->CreateBody(&bd);
           body->CreateFixture(&fd);
         }
        // use the last created domino
        
         switch(k)
         { case 0 :   jointDef.localAnchorA.Set(3.5,0.25);
                      jointDef.localAnchorB.Set(0.1,-1.0);
                      lower=0; higher=10;
                      break;
           case 1 :   bd.position.Set(-36.5f+58.0f, 22.25f);
                      body = m_world->CreateBody(&bd);
                      body->CreateFixture(&fd);
                      lower=-1; higher=10;
                      jointDef.localAnchorA.Set(-5.6,0.25);
                      jointDef.localAnchorB.Set(-0.1,-1.0);
                      break;      
           case 2 :   jointDef.localAnchorA.Set(5.6,0.25);
                      jointDef.localAnchorB.Set(0.1,-1.0);
         }
         jointDef.bodyA = plankbase[k];
         jointDef.bodyB = body;
         jointDef.collideConnected = true;
       
         m_world->CreateJoint(&jointDef);
       }  
    }

    //The pulley system (bottom right corner)
    // 
    /*! 12) Pulley system with an Open Box and 2 Loading Slabs. 
     *  -# Consists of 2 bars/loading slabs(b2Body object pointers box1[0,1]), an open box(b2Body object pointer 'box2'), few balls(b2Body object pointer 'spherebody') and a pulley joint connecting the two in the simulation.
     *  -# The 2 bars/loading slabs('box1[0,1]') modelled as 2 rectangular boxes hinged from one end, with a wall on the other side modelled as another verticle box. Formed using b2PolygonShape object 'bs1'(redefined over and over) & correspondingb2FixtureDef object 'fd1' for 2 base bars and walls. Also, b2Body pointer 'body1' is defines as the anchor for erevolute joint. The density of lower slab is kept on higher side for simulation purposes.
     *  -# The open box('box2') is modelled as set of 3 connected slabs(1 horizontal and 2 verticle), formed by using b2PolygonShape object 'bs1'(redefined over and over) & correspondingb2FixtureDef object 'fd1' redefined for -left, right and base walls, kept horizontal with fixedRotation set to true. These are created using 'fd1' to specify shape, friction, restitution, density etc and b2PolygonShape object 'bs1' to specify shape(horizontal rectangular boxes and verticle edges).
     *  -# Pulley joint is created using b2PulleyJoitDef object pointer 'myjoint', used to define the pulley string across anchor points(worldAnchorGround(1/2)), connecting 2 bodies -'box1[0]' and 'box2'.
     *  -# Revolute joint is created for the 2 loading slabs using b2RevoluteJoint object rd, for both the bars. 'body1' is created as the dummy(no fixture) base body for the anchor. The anchor points etc are set before the for loop and in the for loop(at end) for the next iteration.
     */
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(30,11);
      bd->fixedRotation = true;
      //The open box
      
      b2Body* box2 = m_world->CreateBody(bd);
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 500.0;
      fd1->friction = 5;
      fd1->restitution = 0.3f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      
      b2EdgeShape shape;
      shape.Set(b2Vec2(1.5,-1.5), b2Vec2(1.5,1.5));
      fd1->shape = &shape;
      box2->CreateFixture(fd1);
 
      shape.Set(b2Vec2(-1.5,-1.5), b2Vec2(-1.5,1.5));
      fd1->shape = &shape;
      box2->CreateFixture(fd1);

      bs1.SetAsBox(1.5,0.1,b2Vec2(0,-1.5),0);
      fd1->shape = &bs1;
      box2->CreateFixture(fd1);
      
      //The first and second bar on left
      bd->fixedRotation = false;
      bd->position.Set(23,13.5f);
      fd1->shape = &bs1;
      fd1->density = 500.0;
      fd1->friction = 0.01f;

       b2BodyDef bd1;
       bd1.position.Set(18,13.5);
       

      //(revolute joint for both the bars)
      b2RevoluteJointDef rjd;
      b2Vec2 anchor;
      anchor.Set(18,13.5);
      
      b2Body *box1[2];
      for(int i=0;i<2;i++)
      { bs1.SetAsBox(0.2,0.4+i*0.8,b2Vec2(0,i*1.2),0);
        box1[i] = m_world->CreateBody(bd);
        box1[i]->CreateFixture(fd1);
        fd1->density=1.f;
        bs1.SetAsBox(3,0.2, b2Vec2(-3.f,0),0);
        box1[i]->CreateFixture(fd1);
      
        b2Body* body1 = m_world->CreateBody(&bd1);
       
        rjd.Initialize(box1[i], body1, anchor);
        m_world->CreateJoint(&rjd);
      
        //Setting up for next iteration
        anchor.Set(18,10.5);
        bd->position.Set(23,10.5);
        bd1.position.Set(18,10.5);
        fd1->friction=10.f;
      }

      //Revolute joint between the two left bars
      b2RevoluteJointDef rd;
      rd.Initialize(box1[1],box1[0],b2Vec2(23,13));
      m_world->CreateJoint(&rd);

      //The train of spheres
      for(int j=0;j<2;j++)
      {
        b2Body* spherebody;
        b2CircleShape circle;
        circle.m_radius=0.8;
        b2FixtureDef ballfd;
        ballfd.density = 50.0f;
        ballfd.friction = 10.f;
        ballfd.restitution = 0.f;
        ballfd.shape=&circle;
        for (int i = 0; i <2; ++i)
        {
          b2BodyDef ballbd;
          ballbd.type = b2_dynamicBody;
          ballbd.position.Set(18.f + i*2.0+2*j, 13.7f-j*3);
          spherebody = m_world->CreateBody(&ballbd);
          spherebody->CreateFixture(&ballfd);
        }
      }
      
      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody2(23, 11); // Anchor point on body 1 in world axis
      b2Vec2 worldAnchorOnBody1(30, 13); // Anchor point on body 2 in world axis
      b2Vec2 worldAnchorGround2(30, 15); // Anchor point for ground 1 in world axis
      b2Vec2 worldAnchorGround1(23, 15); // Anchor point for ground 2 in world axis
      float32 ratio = 1.0f; // Define ratio
      myjoint->Initialize(box1[0], box2, worldAnchorGround1, worldAnchorGround2, box1[0]->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);
    }
    
    //The Revolvable horizontal platform
    //   var: body (local)
    /*! 13) Revolvable Horizontal Platform.
     *  -# Creates a revolvable shelf modelled as a horizontal box with joint at center.
     *  -# Uses b2PolygonShape objects to define shape of the b2Body objects body, body2 which represent the revolvable horizontal shelf.
     *  -# Revolute joint is created using b2RevoluteJointDef object specifying localanchorA,B and bodyA,B.
     */
    {
      b2PolygonShape shape;
      shape.SetAsBox(1.f, 0.2f);

      b2BodyDef bd;
      bd.position.Set(32.f, 14.0f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 1.f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      fd->friction=0.f;
      body->CreateFixture(fd);
    
      bd.type=b2_staticBody;
      b2Body* b2=m_world->CreateBody(&bd);
    
      b2RevoluteJointDef rjd;
      rjd.bodyA=body;
      rjd.bodyB=b2;
      rjd.localAnchorA.Set(0,0);
      rjd.localAnchorB.Set(0,0);
      m_world->CreateJoint(&rjd);

    }
    //The heavy sphere on the platform
    // var: sbody (local)
    /*! 14) A Heavy Sphere.
     *  -# Creates b2Body pointer 'sbody' to a heavy sphere objects created on the above horizontal revolvable shelf.
     *  -# Points to a Circle/Sphere-shaped object in the Box2D simulation.
     *  -# Creates (1) b2CircleShape object 'circle' (2) b2BodyDef object 'ballbd', to set position and type(b2_dynamicBody) (3) b2FixtureDef 'ballfd', to specify physical properties - density(high-25), friction, shape('circle'), restitution(0.5-so that the ball doesn't bounce).
     */
    {
      b2Body* sbody;
      b2CircleShape circle;
      circle.m_radius = 1.0;
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 100.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = .5f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(32.0f, 15.0f);
      sbody = m_world->CreateBody(&ballbd);
      sbody->CreateFixture(&ballfd);
    }
    //The see-saw system
    /*! 15) See Saw Series system.
     *  - See saw is modelled as a plank joined with a triangule which acts as its fulcrum.
     *  - Uses b2PolygonShape to define shapes(rectangular/triangular) of the b2Body objects(plank/fulcrum).
     *  Define a revolute joint between plank and th tip of wedge.
     */
    {
      //The triangle wedges
      // var: sbody (local)
      /*!  - 15.1) See Saw system fulcrum.
       *
       *    -# Fulcrum is modelled as a triangle, simply a 3 vertex polygon.
       *    -# Uses b2PolygonShape to define 'poly' shape of the b2Body object 'sbody', wihich represents the fulcrum .
       *    -# 'wedgefd' is b2FixtureDef for 'sbody', defining its b2PolygonShape 'poly' and density, friction, resitution with (b2FixtureDef)wedgefd.
       */
      {b2Body* sbody;
       b2PolygonShape poly;
       b2Vec2 vertices[3];
       vertices[0].Set(-1,0);
       vertices[1].Set(1,0);
       vertices[2].Set(0,1.5);
       poly.Set(vertices, 3);
       b2FixtureDef wedgefd;
       wedgefd.shape = &poly;
       wedgefd.density = 10.0f;
       wedgefd.friction = 0.0f;
       wedgefd.restitution = 0.0f;
       b2BodyDef wedgebd;
       wedgebd.position.Set(8.0f, 0.0f);
       sbody = m_world->CreateBody(&wedgebd);
       sbody->CreateFixture(&wedgefd);
       //The plank on top of the wedge
       //  var: body (local)
       /*!  - 15.2) The Plank
        *    -# Creates a plank modelled as a flattened (horizontal) box.
        *    -# Defines b2PolygonShape 'shape' for the flattened shape and b2FixtureDef 'fd2' to define the physical properties (density,shape) of the b2Body object 'body', which represents the plank.
        *    -# Defines b2RevoluteJointDef to define a revolute joint between the plank, and the tip of the wedge(fulcrum), on which it rests, at its center. 
        */  
       b2PolygonShape shape;
       shape.SetAsBox(10.0f, 0.2f);
       b2BodyDef bd2;
       bd2.position.Set(8.0f, 1.5f);
       bd2.type = b2_dynamicBody;
       b2Body* body = m_world->CreateBody(&bd2);
       b2FixtureDef *fd2 = new b2FixtureDef;
       fd2->density = 1.f;
       fd2->shape = new b2PolygonShape;
       fd2->shape = &shape;
       //fd2->friction=0.0f;
       body->CreateFixture(fd2);

       b2RevoluteJointDef jd;
       b2Vec2 anchor;
       anchor.Set(8.0f, 1.5f);
       jd.Initialize(sbody, body, anchor);
       m_world->CreateJoint(&jd);
     } 
      //The triangle wedge
      // var: sbody (local)
      /*  15.1)fulcrum. (PART OF ABOVE ELEMENT)
       *    -# Fulcrum is modelled as a triangle.
       *    -# Uses b2PolygonShape to define 'poly' shape of the b2Body object 'sbody'(fulcrum).
       *    -# 'wedgefd' is b2FixtureDef for 'sbody' definig its shape('poly'), density, friction, resitution.
       */
      b2Body* sbody;
      b2PolygonShape poly;
      b2Vec2 vertices[3];
      vertices[0].Set(-1,0);
      vertices[1].Set(1,0);
      vertices[2].Set(0,2.);
      poly.Set(vertices, 3);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(-8.0f, 0.0f);
      sbody = m_world->CreateBody(&wedgebd);
      sbody->CreateFixture(&wedgefd);

      //The plank on top of the wedge(PART OF ABOVE ELEMENT)
      //  var: body (local)
      /* - 15.2) Plank.
       *   -# Creates a plank modelled as a horizontal box.
       *   -# Uses b2PolygonShape to define 'shape' and b2FixtureDef 'fd2' which defines the physical properties(density,shape) of the b2Body object 'body' which represents the plank.
       *   -# The Plank rests on the above created wedge(fulcrum) and its center is fixed on the tip of the wedge(fulcrum). 
       *   -# Also the planks friction is defined to be 0.05f.
       */
     {
      b2PolygonShape shape;
      shape.SetAsBox(8.0f, 0.2f);
      b2BodyDef bd2;
      bd2.position.Set(-8.0f, 2.f);
      bd2.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd2);
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 1.f;
      fd2->shape = new b2PolygonShape;
      fd2->shape = &shape;
      fd2->friction=0.5f;
      body->CreateFixture(fd2);

      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-8.0f, 2.f);
      jd.Initialize(sbody, body, anchor);
      m_world->CreateJoint(&jd);
     }  
      //The Containers
      /*!  16)The Containers
        *  -# The open box('box1') is formed by using 3 b2PolygonShape & b2FixtureDef-left, right and base walls.
        *  -# Defined a b2FixtureDef object 'fd1' to specify shape, friction, restitution, density etc.
        *  -# Defined a b2PolygonShape object 'bs1' to specify shape(horizontal and vertical rectangular boxes).
        */
      {
       b2BodyDef *bd = new b2BodyDef;
       bd->type = b2_dynamicBody;
       bd->position.Set(-1.5,5);
        //bd->fixedRotation = true;
     
       b2Body* box2 = m_world->CreateBody(bd);
       b2FixtureDef *fd1 = new b2FixtureDef;
       fd1->density = 10.0;
       fd1->friction = 0.5;
       fd1->restitution = 0.f;
       fd1->shape = new b2PolygonShape;
       b2PolygonShape bs1;
       for(int i=0;i<2;i++)
       {  bs1.SetAsBox(2,0.2, b2Vec2(0.f,-1.9f), 0);
          fd1->shape = &bs1;
          box2->CreateFixture(fd1);
      
          bs1.SetAsBox(0.2,2, b2Vec2(2.0f,0.f), 0);
          fd1->shape = &bs1;
          box2->CreateFixture(fd1);
      
          bs1.SetAsBox(0.2,2, b2Vec2(-2.0f,0.f), 0);
          fd1->shape = &bs1;
          box2->CreateFixture(fd1);

          fd1->density = 25.f;  // changin for next iteration
          fd1->friction = 5;
          bd->position.Set(15.f,5);
          box2 = m_world->CreateBody(bd);
        }  
      }
    }

    // Car
    /*! 17)Car 
     *   -# Defined b2Body object pointers (chasis-)m_car, (wheels-) m_wheel1, m_wheel2, which together form the car!
     *   -# Defined b2PolygonShape 'chassis' using array of 8 vertices, for the car's outer body. Defined  b2CircleShape circle for the wheels.
     *   -# Defined b2WheelJointDef jd for both the wheels created above. 
     *   -# 17.1) Curvy Ramp2: 
     *       Creates a redirecting Curvy Ramp modelled as a set of edges in succession forming a curvy connected component.
     *       Uses b2EdgeShape to define 'shapel' of the b2Body object 'left' which represent the curvy slopes.
     *       Redifined 'shapel' to reuse the variable for creating set of connected-edges.
     */
    {
      b2PolygonShape chassis;
      b2Vec2 vertices[8];
      vertices[0].Set(-2.5f, -0.7f);
      vertices[1].Set(2.5f, -0.7f);
      vertices[2].Set(2.5f, 0.0f);
      vertices[4].Set(2.0f, 1.9f);
      vertices[3].Set(0.f, 1.9f);
      vertices[5].Set(-2.5f, 0.2f);
      chassis.Set(vertices, 6);

      b2CircleShape circle;
      circle.m_radius = 1.f;

      b2BodyDef bd;
      bd.type = b2_dynamicBody;
      bd.position.Set(-22.f, 1.0f);
      b2Body* m_car = m_world->CreateBody(&bd);
      m_car->CreateFixture(&chassis, 0.001f);
      m_car->SetId(3);
      b2FixtureDef fd;
      fd.shape = &circle;
      fd.density = .001f;
      fd.friction = 0.9f;

      bd.position.Set(-23.f, 0.35f);
      b2Body*  m_wheel1 = m_world->CreateBody(&bd);
      m_wheel1->CreateFixture(&fd);
      m_wheel1->SetId(3);
      bd.position.Set(-21.f, 0.4f);
      b2Body*  m_wheel2 = m_world->CreateBody(&bd);
      fd.density=0.005f;
      m_wheel2->CreateFixture(&fd);
      m_wheel2->SetId(3);
      b2WheelJointDef jd;
      b2Vec2 axis(0.0f, 1.0f);

      jd.Initialize(m_car, m_wheel1, m_wheel1->GetPosition(), axis);
      jd.motorSpeed = 0.0f;
      jd.maxMotorTorque = 20.0f;
      jd.enableMotor = true;
      jd.frequencyHz = 4;
      jd.dampingRatio = 0.7f;
      m_world->CreateJoint(&jd);

      jd.Initialize(m_car, m_wheel2, m_wheel2->GetPosition(), axis);
      jd.motorSpeed = 0.0f;
      jd.maxMotorTorque = 10.0f;
      jd.enableMotor = false;
      jd.frequencyHz = 4;
      jd.dampingRatio = 0.7f;
      m_world->CreateJoint(&jd);
    }
     // Ramp
     /* 
      *  -# 17.1) Curvy Ramp2: 
      *       Creates a redirecting Curvy Ramp modelled as a set of edges in succession forming a curvy connected component.
      *       Uses b2EdgeShape to define 'shapel' of the b2Body object 'left' which represent the curvy slopes.
      *       Redifined 'shapel' to reuse the variable for creating set of connected-edges.
      */
     {
      b2Body* left;
      b2EdgeShape shapel, shaper;
      float x=-23, y=0;
      for(int i=0;i<3;i++)
      {
        shapel.Set(b2Vec2(x,y), b2Vec2(x-(4-i)*0.8, y+(1+i)*0.4));
        x=x-(4-i)*0.8;
        y=y+(1+i)*0.4;
        b2BodyDef bd;
        left = m_world->CreateBody(&bd);
        left->CreateFixture(&shapel, 0.0f);
      }
    
     }
    //Bottom button box
    // \var b1 (local)
    /*   Button Base.
     *   -# Creates a box modelled as a horizontal square polygon.
     *   -# Uses b2PolygonShape 'shape' to define shape of the b2Body object 'b1' which represents the box.
     */
    {  
    b2PolygonShape shape;
    shape.SetAsBox(2.f, 2.f);
    b2BodyDef bd;
    bd.position.Set(-42.8f, 2.0f);
    b2Body* b1 = m_world->CreateBody(&bd);
    b1->CreateFixture(&shape, 0.5f);
    }
}
Пример #5
0
  dominos_t::dominos_t()
  {
  #define DEGTORAD 0.0174532925199432957f
    //Ground
    /*! \var b1
     * \brief pointer to the body ground
     */
    b2Body* b1;
    {

      b2EdgeShape shape;
      shape.Set(b2Vec2(-90.0f, 0.0f), b2Vec2(90.0f, 0.0f));
      b2BodyDef bd;
      b1 = m_world->CreateBody(&bd);
      b1->CreateFixture(&shape, 0.0f);
    }

    //Top horizontal shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(6.0f, 0.25f);

      b2BodyDef bd;
      bd.position.Set(-26.0f, 30.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);

       b2PolygonShape shape1;
      shape1.SetAsBox(0.2f, 1.5f);
      b2FixtureDef fd;
      fd.shape = &shape1;
      fd.density = 3.0f;
      fd.friction = 0.5f;
       b2BodyDef bd1;
	  bd1.type = b2_dynamicBody;
	  bd1.position.Set(-21.0f, 31.75f);
	  b2Body* body = m_world->CreateBody(&bd1);
	  body->CreateFixture(&fd);

	   b2RevoluteJointDef revoluteJointDef;
  revoluteJointDef.bodyA = ground;
  revoluteJointDef.bodyB = body;
  revoluteJointDef.collideConnected = false;
  revoluteJointDef.localAnchorA.Set(5.0f,0.0f);//the top right corner of the box
  revoluteJointDef.localAnchorB.Set(0.0f,-1.5f);//center of the circle
  m_world->CreateJoint( &revoluteJointDef );

    }

    //Dominos
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.0f);

      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;

      for (int i = 0; i < 9; ++i)
	{
	  b2BodyDef bd;
	  bd.type = b2_dynamicBody;
	  bd.position.Set(-30.5f + 1.0f * i, 31.25f);
	  b2Body* body = m_world->CreateBody(&bd);
	  body->CreateFixture(&fd);
	}
    }

    //Another horizontal shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(7.0f, 0.25f, b2Vec2(-24.5f,20.f), 0.0f);

      b2BodyDef bd;
      bd.position.Set(1.0f, 6.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }


    //The pendulum that knocks the dominos off
    {
      b2Body* b2;
      {
	b2PolygonShape shape;
	shape.SetAsBox(0.25f, 1.f);

	b2BodyDef bd;
	bd.position.Set(-31.5f, 29.0f);
	b2 = m_world->CreateBody(&bd);
	b2->CreateFixture(&shape, 10.0f);
      }

      b2Body* b4;
      {
	b2PolygonShape shape;
	shape.SetAsBox(0.25f, 0.25f);

	b2BodyDef bd;
	bd.type = b2_dynamicBody;
	bd.position.Set(-35.0f, 33.0f);
	b4 = m_world->CreateBody(&bd);
	b4->CreateFixture(&shape, 2.0f);
      }

      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-32.0f, 40.0f);
      jd.Initialize(b2, b4, anchor);
      m_world->CreateJoint(&jd);
    }

    //The train of small spheres
    {
      b2Body* spherebody;
      b2Body* spherebody1;

      b2CircleShape circle;
      circle.m_radius = 0.5;

      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 3.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;

      for (int i = 0; i<33; ++i)
	{
	  b2BodyDef ballbd;
	  ballbd.type = b2_dynamicBody;
	  if(i<10){
	  ballbd.position.Set(-30.f + i*1.0, 26.6f);
	   spherebody = m_world->CreateBody(&ballbd);
	  spherebody->CreateFixture(&ballfd);
	  }
	  if(i==10){ballbd.position.Set(-6.8f, 9.3f);
      spherebody = m_world->CreateBody(&ballbd);
	  spherebody->CreateFixture(&ballfd);
	  spherebody->SetGravityScale(-0.7);}
	  if(i==11){ballbd.position.Set(-6.8f, 20.7f);
	  ballfd.density = 20.0f;
      spherebody = m_world->CreateBody(&ballbd);
	  spherebody->CreateFixture(&ballfd);}
	  if(i==12){ballbd.position.Set(-2.8f, 20.7f);
	  ballfd.density = 20.0f;
      spherebody = m_world->CreateBody(&ballbd);
	  spherebody->CreateFixture(&ballfd);}
	  //ball falling on spring
      if(i==13){ballbd.position.Set(12.2f, 21.5f);
	  ballfd.density = 25.0f;circle.m_radius = 1.0;
      spherebody = m_world->CreateBody(&ballbd);
	  spherebody->CreateFixture(&ballfd);}
	  //ball beside spring
	  if(i==14){ballbd.position.Set(22.0f, 13.0f);
	  ballfd.density = 25.0f;
	  ballfd.restitution = 0.5f;
      spherebody = m_world->CreateBody(&ballbd);
	  spherebody->CreateFixture(&ballfd);}
	  if(i>14){
	  ballfd.restitution=0.0f;circle.m_radius = 0.5;
	   ballfd.density = 1.0f;
	   ballbd.position.Set(31.0+i*0.001,i-1.5);
	  ballfd.density = 30.0f;
      spherebody = m_world->CreateBody(&ballbd);
	  spherebody->CreateFixture(&ballfd);
	  ballbd.position.Set(32.0+i*0.001,i-1.5);
	  spherebody1 = m_world->CreateBody(&ballbd);
	  spherebody1->CreateFixture(&ballfd);}
	}
    }

     //The pulley system
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-31.5,10);
      bd->fixedRotation = true;

      //The open box
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.5;
      fd1->restitution = 0.0f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(2,0.2, b2Vec2(0.f,-1.9f), 0);
      fd1->shape = &bs1;
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.5;
      fd2->restitution = 0.f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.2,2, b2Vec2(2.0f,0.f), 0);
      fd2->shape = &bs2;
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 10.0;
      fd3->friction = 0.5;
      fd3->restitution = 0.f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape bs3;
      bs3.SetAsBox(0.2,2, b2Vec2(-2.0f,0.f), 0);
      fd3->shape = &bs3;

      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);
      box1->CreateFixture(fd2);
      box1->CreateFixture(fd3);

      //The bar
      bd->position.Set(-11.5,10);
      fd1->density = 40.0;
      b2Body* box2 = m_world->CreateBody(bd);
      box2->CreateFixture(fd1);

      // The pulley joint
      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody1(-31.5, 10); // Anchor point on body 1 in world axis
      b2Vec2 worldAnchorOnBody2(-11.5, 10); // Anchor point on body 2 in world axis
      b2Vec2 worldAnchorGround1(-31.5, 16); // Anchor point for ground 1 in world axis
      b2Vec2 worldAnchorGround2(-11.5, 16); // Anchor point for ground 2 in world axis
      float32 ratio = 1.0f; // Define ratio
      myjoint->Initialize(box1, box2, worldAnchorGround1, worldAnchorGround2, box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);
    }

        //The revolving horizontal platform
    {
      b2PolygonShape shape;
      shape.SetAsBox(2.8f, 0.2f);

      b2BodyDef bd;
      bd.type = b2_dynamicBody;

      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 1.f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;


      b2PolygonShape shape2;
      shape2.SetAsBox(0.2f, 2.8f);
      b2BodyDef bd2;

      for(int i=0;i<2;i++)
      { if(i==0){
        bd.position.Set(-6.8f, 10.0f);
        bd2.position.Set(-6.8f, 10.0f);
        }
        if(i==1){
        bd.position.Set(-4.8f, 20.0f);
        bd2.position.Set(-4.8f, 20.0f);
        }
        b2Body* body = m_world->CreateBody(&bd);
         body->CreateFixture(fd);
      b2Body* body2 = m_world->CreateBody(&bd2);
      b2RevoluteJointDef jointDef;
      jointDef.bodyA = body;
      jointDef.bodyB = body2;
      jointDef.localAnchorA.Set(0,0);
      jointDef.localAnchorB.Set(0,0);
      jointDef.collideConnected = false;
      m_world->CreateJoint(&jointDef);
      }

    }


    //The pulley system
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(0,15);
      bd->fixedRotation = true;

      //The open box
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.5;
      fd1->restitution = 0.5f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(2,0.2, b2Vec2(0.f,-2.0f), 0);
      fd1->shape = &bs1;
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.5;
      fd2->restitution = 0.5f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.2,2, b2Vec2(2.0f,0.f), 0);
      fd2->shape = &bs2;
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 10.0;
      fd3->friction = 0.5;
      fd3->restitution = 0.5f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape bs3;
      bs3.SetAsBox(0.2,2, b2Vec2(-2.0f,0.f), 0);
      fd3->shape = &bs3;

      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);
      box1->CreateFixture(fd2);
      box1->CreateFixture(fd3);
      box1->SetGravityScale(0);

     //The bar
      b2PolygonShape bs;
       bs.SetAsBox(2.0f, 0.2f);
      fd1->shape = &bs;
      bd->position.Set(12,20);
      fd1->density = 10.0;
      b2Body* box2 = m_world->CreateBody(bd);
      box2->CreateFixture(fd1);
      box2->SetGravityScale(0);

      // The pulley joint
      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody1(0, 15); // Anchor point on body 1 in world axis
      b2Vec2 worldAnchorOnBody2(12, 20); // Anchor point on body 2 in world axis
      b2Vec2 worldAnchorGround1(0, 20); // Anchor point for ground 1 in world axis
      b2Vec2 worldAnchorGround2(6, 20); // Anchor point for ground 2 in world axis
      float32 ratio = 1.0; // Define ratio
      myjoint->Initialize(box1, box2, worldAnchorGround1,worldAnchorGround2,box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);

    }

 // surface
 for(int i=0;i<14;i++){
 float a,b,c,d;
 if(i==0){a=8.0f;b=12.0f;c=25.0f;d=12.0f;}
 if(i==1){a=25.0f;b=12.0f;c=25.0f;d=8.0f;}
 if(i==2){a=25.0f;b=8.0f;c=29.0f;d=8.0f;}
 if(i==3){a=29.0f;b=8.0f;c=29.0f;d=12.0f;}
 if(i==4){a=29.0f;b=12.0f;c=42.0f;d=12.0f;}
 if(i==5){a=42.0f;b=12.0f;c=42.0f;d=30.0f;}
 if(i==6){a=10.1f;b=20.2f;c=10.1f;d=25.0f;}
 if(i==7){a=13.9f;b=20.2f;c=13.9f;d=25.0f;}
 if(i==8){a=10.1f;b=19.8f;c=11.1f;d=18.6f;}
 if(i==9){a=13.9f;b=19.8f;c=13.9f;d=19.6f;}
 if(i==10){a=30.0f;b=12.0f;c=30.0f;d=30.0f;}
 if(i==11){a=32.8f;b=13.5f;c=32.8f;d=30.0f;}
 if(i==12){a=33.22f;b=13.2f;c=33.22f;d=15.0f;}
 //spring
 if(i==13){a=10.5f;b=12.f;c=10.5f;d=16.0f;}
  b2Body* b1;
    {
      b2EdgeShape shape;
      shape.Set(b2Vec2(a,b), b2Vec2(c,d));
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->shape = &shape;
      fd1->friction =1;
      b2BodyDef bd;
      b1 = m_world->CreateBody(&bd);
      b1->CreateFixture(fd1);
    }
   }

    //The pulley system
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(27.0,11);
      bd->fixedRotation = true;

      //The open box
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.0;
      fd1->restitution = 0.0f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs;
      bs.SetAsBox(2.0f, 0.1f);
      fd1->shape = &bs;

      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);

      //The bar
      bd->position.Set(33,14.0);
      fd1->density = 5.0;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape s;
      s.SetAsBox(0.2f, 2.0f);
      fd1->shape = &s;
      b2Body* box2 = m_world->CreateBody(bd);
      box2->CreateFixture(fd1);

      // The pulley joint
      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody1(27, 11); // Anchor point on body 1 in world axis
      b2Vec2 worldAnchorOnBody2(33, 14.0); // Anchor point on body 2 in world axis
      b2Vec2 worldAnchorGround1(27, 24); // Anchor point for ground 1 in world axis
      b2Vec2 worldAnchorGround2(33, 24); // Anchor point for ground 2 in world axis
      float32 ratio = 1.0f; // Define ratio
      myjoint->Initialize(box1, box2, worldAnchorGround1, worldAnchorGround2, box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);
    }


    //bigpulley
    {
     //The pulley system

      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-36,30);
      bd->fixedRotation = true;

      //The open box
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 0.0;
      fd1->friction = 0.5;
      fd1->restitution = 0.0f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(2,0.2, b2Vec2(0.f,-1.9f), 0);
      fd1->shape = &bs1;
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 0.0;
      fd2->friction = 0.5;
      fd2->restitution = 0.f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.2,2, b2Vec2(1.0f,0.f), 0);
      fd2->shape = &bs2;
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 0.0;
      fd3->friction = 0.5;
      fd3->restitution = 0.f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape bs3;
      bs3.SetAsBox(0.2,2, b2Vec2(-1.0f,0.f), 0);
      fd3->shape = &bs3;

      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);
      box1->CreateFixture(fd2);
      box1->CreateFixture(fd3);

      //The bar
      bd->position.Set(-42,25);
    //  fd1->density = 40.0;
      b2Body* box2 = m_world->CreateBody(bd);
      //box2->CreateFixture(fd1);

      // The pulley joint fd1- fd1->density = 40.0;>density = 40.0;
      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody1(-36, 30); // Anchor point on body 1 in world axis
      b2Vec2 worldAnchorOnBody2(-42, 25); // Anchor point on body 2 in world axis
      b2Vec2 worldAnchorGround1(-36, 35); // Anchor point for ground 1 in world axis
      b2Vec2 worldAnchorGround2(-42, 35); // Anchor point for ground 2 in world axis
      float32 ratio = 1.0f; // Define ratio
      myjoint->Initialize(box1, box2, worldAnchorGround1, worldAnchorGround2, box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);

     //The pulley system
      bd->position.Set(-36,20);
     //The bar
      b2PolygonShape bs;
       bs.SetAsBox(1.6f, 0.2f);
      fd1->shape = &bs;
      fd1->density = 0.0;
      b2Body* box3 = m_world->CreateBody(bd);
      box3->CreateFixture(fd1);
      box3->SetGravityScale(0);

      // The pulley joint
      b2PulleyJointDef* myjoint1 = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody3(-42, 25); // Anchor point on body 1 in world axis
      b2Vec2 worldAnchorOnBody4(-36, 20); // Anchor point on body 2 in world axis
      b2Vec2 worldAnchorGround3(-42, 20); // Anchor point for ground 1 in world axis
      b2Vec2 worldAnchorGround4(-41.9, 20); // Anchor point for ground 2 in world axis
     // float32 ratio = 1.0; // Define ratio
      myjoint1->Initialize(box2, box3, worldAnchorGround3,worldAnchorGround4,box2->GetWorldCenter(), box3->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint1);
    }


    //spring
    {
      b2PolygonShape shape;
      shape.SetAsBox(2.5f, 0.2f);

      b2BodyDef bd1,bd2,bd3,bd4;
      bd1.type = b2_dynamicBody;
      bd2.type = b2_dynamicBody;
      bd3.type = b2_dynamicBody;
      bd4.type = b2_dynamicBody;

      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 1.2f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      fd->friction = 4;
      fd->restitution = 0.0f;
        bd1.position.Set(12.2f, 14.0f);
        bd2.position.Set(12.2f, 14.0f);
        bd3.position.Set(15.2f, 14.0f);
        bd4.position.Set(15.2f, 14.0f);
        bd1.angle=53*DEGTORAD;
        bd2.angle=-53*DEGTORAD;
        bd3.angle=53*DEGTORAD;
        bd4.angle=-53*DEGTORAD;

        b2Body* body1 = m_world->CreateBody(&bd1);
        b2Body* body2 = m_world->CreateBody(&bd2);
        b2Body* body3 = m_world->CreateBody(&bd3);
        b2Body* body4 = m_world->CreateBody(&bd4);
         body1->CreateFixture(fd);
         body2->CreateFixture(fd);
         body3->CreateFixture(fd);
         body4->CreateFixture(fd);
        /* body1->SetGravityScale(0);
         body2->SetGravityScale(0);
         body3->SetGravityScale(0);
         body4->SetGravityScale(0);*/
      b2RevoluteJointDef jointDef1;
      jointDef1.bodyA = body1;
      jointDef1.bodyB = body4;
      //jointDef1.maxLength=0.10001f;
      jointDef1.localAnchorA.Set(2.5,0);
      jointDef1.localAnchorB.Set(-2.5,0);
      jointDef1.collideConnected = true;
      m_world->CreateJoint(&jointDef1);
      b2RevoluteJointDef jointDef2;
      jointDef2.bodyA = body2;
      jointDef2.bodyB = body3;
      //jointDef2.maxLength=0.10001f;
      jointDef2.localAnchorA.Set(2.5,0);
      jointDef2.localAnchorB.Set(-2.5,0);
      jointDef2.collideConnected = true;
      m_world->CreateJoint(&jointDef2);
      b2RevoluteJointDef jointDef3;
      jointDef3.bodyA = body1;
      jointDef3.bodyB = body2;
      //jointDef3.maxLength=0.00001f;
      jointDef3.localAnchorA.Set(0,0);
      jointDef3.localAnchorB.Set(0,0);
      jointDef3.collideConnected = false;
      m_world->CreateJoint(&jointDef3);
      b2RevoluteJointDef jointDef4;
      jointDef4.bodyA = body3;
      jointDef4.bodyB = body4;
      //jointDef4.maxLength=0.00001f;
      jointDef4.localAnchorA.Set(0,0);
      jointDef4.localAnchorB.Set(0,0);
      jointDef4.collideConnected = false;
      m_world->CreateJoint(&jointDef4);
      }

      //conveyor belt
      {
      b2Body *s11,*s12,*s13,*s14,*s21,*s22,*s23,*s24,*sb11,*sb13,*s1,*s2;

      b2PolygonShape bs;
       bs.SetAsBox(0.5f, 0.5f);
      b2FixtureDef ballfd;
      ballfd.shape = &bs;
      ballfd.density = 3.0f;
      ballfd.friction = 0.2f;
      ballfd.restitution = 0.0f;
      b2BodyDef ballbd;
	  ballbd.type = b2_dynamicBody;
      ballbd.position.Set(0.f, 35.0f);sb11 = m_world->CreateBody(&ballbd);sb11->CreateFixture(&ballfd);sb11->SetAngularVelocity(0);
      ballbd.position.Set(0.f, 29.0f);sb13 = m_world->CreateBody(&ballbd);sb13->CreateFixture(&ballfd);sb13->SetAngularVelocity(0);
      //ballbd.position.Set(9.f, 35.0f);sb21 = m_world->CreateBody(&ballbd);sb21->CreateFixture(&ballfd);
      //ballbd.position.Set(9.f, 29.0f);sb23 = m_world->CreateBody(&ballbd);sb23->CreateFixture(&ballfd);
       s11=sb11;
       s13=sb13;
       s21 =sb11;

      for (int i = 0; i<13; ++i)
	{

	  if(i<13){
	  ballbd.position.Set(0.f+i*1.0f, 35.0f);s12 = m_world->CreateBody(&ballbd);s12->CreateFixture(&ballfd);s12->SetAngularVelocity(0);
      ballbd.position.Set(0.f+i*1.0f, 29.0f);s14 = m_world->CreateBody(&ballbd);s14->CreateFixture(&ballfd);s14->SetAngularVelocity(0);
      b2RopeJointDef jointDef11;jointDef11.bodyA = s11;jointDef11.bodyB = s12;jointDef11.localAnchorA.Set(0,0);
	   jointDef11.localAnchorB.Set(0,0);jointDef11.maxLength=1.f;jointDef11.collideConnected = false;m_world->CreateJoint(&jointDef11);
        s11=s12;
	   b2RopeJointDef jointDef21;jointDef21.bodyA = s13;jointDef21.bodyB = s14;jointDef21.localAnchorA.Set(0,0);
	   jointDef21.localAnchorB.Set(0,0);jointDef21.maxLength=1.f;jointDef21.collideConnected = false;m_world->CreateJoint(&jointDef21);
	   s13=s14;
	  }
	  }
	   s23=s11;
	  for (int i =10; i<16; ++i){
	  if(9<i && i<19){
	  ballbd.position.Set(-3.0f*sin((i-9)*30*DEGTORAD),32.0f+3.0f*cos((i-9)*30*DEGTORAD));s22 = m_world->CreateBody(&ballbd);s22->CreateFixture(&ballfd);s22->SetAngularVelocity(0);
      ballbd.position.Set(12.0f+3.0f*sin((i-9)*30*DEGTORAD),32.0f+3.0f*cos((i-9)*30*DEGTORAD));s24 = m_world->CreateBody(&ballbd);s24->CreateFixture(&ballfd);s24->SetAngularVelocity(0);
      b2RopeJointDef jointDef11;jointDef11.bodyA = s21;jointDef11.bodyB = s22;jointDef11.localAnchorA.Set(0,0);
	   jointDef11.localAnchorB.Set(0,0);jointDef11.maxLength=1.f;jointDef11.collideConnected = false;m_world->CreateJoint(&jointDef11);
        s21=s22;
	   b2RopeJointDef jointDef21;jointDef21.bodyA = s23;jointDef21.bodyB = s24;jointDef21.localAnchorA.Set(0,0);
	   jointDef21.localAnchorB.Set(0,0);jointDef21.maxLength=1.f;jointDef21.collideConnected = false;m_world->CreateJoint(&jointDef21);
	   s23=s24;
	  }
	  }
	  b2RopeJointDef jointDef11;jointDef11.bodyA = s21;jointDef11.bodyB = sb13;jointDef11.localAnchorA.Set(0,0);
	   jointDef11.localAnchorB.Set(0,0);jointDef11.maxLength=1.f;jointDef11.collideConnected = false;m_world->CreateJoint(&jointDef11);
	   b2RopeJointDef jointDef21;jointDef21.bodyA = s23;jointDef21.bodyB = s13;jointDef21.localAnchorA.Set(0,0);
	   jointDef21.localAnchorB.Set(0,0);jointDef21.maxLength=1.f;jointDef21.collideConnected = false;m_world->CreateJoint(&jointDef21);

      ballbd.type = b2_kinematicBody;
      b2CircleShape circle;
      circle.m_radius = 2.5;
      ballfd.shape = &circle;
      ballfd.friction = 1.f;
      ballbd.position.Set(0.f, 32.0f);s1 = m_world->CreateBody(&ballbd);s1->CreateFixture(&ballfd);
      ballbd.position.Set(12.f, 32.0f);s2 = m_world->CreateBody(&ballbd);s2->CreateFixture(&ballfd);
      s1->SetAngularVelocity(1);
      s2->SetAngularVelocity(1);
      // box
      b2PolygonShape shape;
      shape.SetAsBox(1.0f, 1.0f);

      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 10.0f;
      fd.friction = 1.0f;
      fd.restitution = 0.0f;
	  b2BodyDef bd;
	  bd.type = b2_dynamicBody;
	  bd.position.Set(19.5f, 13.0f);
	  b2Body* body = m_world->CreateBody(&bd);
	  body->CreateFixture(&fd);



    }



//skksm
  }
  dominos_t::dominos_t()
  {
    //Ground
    /*! \var ground 
     * \brief pointer to the body ground 
     */ 
     b2Body* ground;
    {
      
      b2EdgeShape shape; 
      shape.Set(b2Vec2(-90.0f, 0.0f), b2Vec2(90.0f, 0.0f));
      b2BodyDef bd;

      ground = m_world->CreateBody(&bd);

      ground->CreateFixture(&shape, 0.0f);

    }
       //Top horizontal shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(3.0f, 0.25f);
  
      b2BodyDef bd;
      bd.position.Set(-31.0f, 38.0f);
      b2Body* b1 = m_world->CreateBody(&bd);
      b1->CreateFixture(&shape, 0.0f);
    }    
    //horizontal shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(13.f, 0.5f);
  
      b2BodyDef bd21;
      bd21.position.Set(-22.0f, 25.0f);
      b2Body* b1 = m_world->CreateBody(&bd21);
      b1->CreateFixture(&shape, 0.0f);
      /*
      shape.SetAsBox(5.0f, 0.25f);
  
      b2BodyDef bd21;
      bd21.position.Set(-31.0f, 30.0f);
      b2Body* b1 = m_world->CreateBody(&bd);
      b1->CreateFixture(&shape, 0.0f);
    */
/*
      b2PolygonShape shape;
      shape.SetAsBox(5.0f, 0.25f);
  
      b2BodyDef bd2;
      bd2.position.Set(-30.0f, 20.0f);
      b2Body* b1 = m_world->CreateBody(&bd2);
      b1->CreateFixture(&shape, 0.0f);
  */  


	//    \  / edges on top
      b2Body* left;
      b2Body* right;
      b2EdgeShape shapel, shaper; 
      shapel.Set(b2Vec2(-31.5f, 29.0f), b2Vec2(-33.0f, 32.0f));
      shaper.Set(b2Vec2(-25.0f, 37.0f), b2Vec2(-28.0f, 34.0f));
      b2BodyDef bd;
      left = m_world->CreateBody(&bd);
      right = m_world->CreateBody(&bd);
      left->CreateFixture(&shapel, 0.0f);
      right->CreateFixture(&shaper, 0.0f);
    }
    //The sphere on the top platform
    {
      b2Body* sbody;
      b2CircleShape circle;
      circle.m_radius = 1.0;
  
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 15.0f;
      ballfd.friction = 1.0f;
      ballfd.restitution = 0.7f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(-28.5f, 38.25f);
      sbody = m_world->CreateBody(&ballbd);
      sbody->CreateFixture(&ballfd);
    }

    //Dominos on the top
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.0f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
      for (int i =0; i < 4; ++i)
      {
    	b2BodyDef bd;
    	bd.type = b2_dynamicBody;
    	bd.position.Set(-33.5f + 1.0f * i, 40.f);
    	b2Body* body = m_world->CreateBody(&bd);
    	body->CreateFixture(&fd);
      }
    }




    //The see-saw system
    {
      //The triangle wedge
      b2Body* sbody;
      b2PolygonShape poly;
      b2Vec2 vertices[3];
      vertices[0].Set(-1,0);
      vertices[1].Set(1,0);
      vertices[2].Set(0,1.5);
      poly.Set(vertices, 3);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(-20.0f, 25.0f);
      sbody = m_world->CreateBody(&wedgebd);
      sbody->CreateFixture(&wedgefd);



      //The plank on top of the wedge
      b2PolygonShape shape;
      shape.SetAsBox(8.0f, 0.2f);
      b2BodyDef bd2;
      bd2.position.Set(-20.0f, 26.5f);
      bd2.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd2);
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 1.f;
      fd2->shape = new b2PolygonShape;
      fd2->shape = &shape;
      body->CreateFixture(fd2);

      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-20.0f, 26.5f);
      jd.Initialize(sbody, body, anchor);
      m_world->CreateJoint(&jd);
  
    
      //The box on the right side of the see-saw
      b2PolygonShape shape2;
      shape2.SetAsBox(2.0f, 2.0f);
      b2BodyDef bd3;
      bd3.position.Set(-12.0f, 27.0f);
      bd3.type = b2_dynamicBody;
      b2Body *b3 = m_world->CreateBody(&bd3);
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = .01f;
      fd3->shape = new b2PolygonShape;
      fd3->shape = &shape2;
      b3->CreateFixture(fd3);
    }

      /*
    //Another horizontal shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(6.5f, 0.25f, b2Vec2(-20.f,20.f), 0.0f);
  
      b2BodyDef bd;
      bd.position.Set(1.0f, 6.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }

*/
    //The pendulum that knocks the dominos off
    {
      b2Body* b2;
      {
  	b2PolygonShape shape;
 	shape.SetAsBox(0.25f, 0.5f);
    
  	b2BodyDef bd;
  	bd.position.Set(-34.5f, 38.0f);
  	b2 = m_world->CreateBody(&bd);
  	b2->CreateFixture(&shape, 10.0f);
      }
  
      b2Body* b4;
      {
  	b2PolygonShape shape;
  	shape.SetAsBox(0.25f, 0.25f);
    
  	b2BodyDef bd;
 	bd.type = b2_dynamicBody;
  	bd.position.Set(-38.0f, 41.50f);
  	b4 = m_world->CreateBody(&bd);
  	b4->CreateFixture(&shape, 25.0f);
      }
      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-34.5f, 45.0f);
      jd.Initialize(b2, b4, anchor);


      m_world->CreateJoint(&jd);
    }
      /*
    //The train of small spheres
    {
      b2Body* spherebody;
  
      b2CircleShape circle;
      circle.m_radius = 0.5;
  
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 1.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
  
      for (int i = 0; i < 10; ++i)
      {
    	b2BodyDef ballbd;
    	ballbd.type = b2_dynamicBody;
    	ballbd.position.Set(-22.2f + i*1.0, 26.6f);
    	spherebody = m_world->CreateBody(&ballbd);
    	spherebody->CreateFixture(&ballfd);
      }
    }*/



    //The pulley system (bottom right corner)
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(18,5);
      bd->fixedRotation = true;
      
      //The open box
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.5;
      fd1->restitution = 0.f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(2,0.2, b2Vec2(0.f,-1.9f), 0);
      fd1->shape = &bs1;
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.5;
      fd2->restitution = 0.f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.2,2, b2Vec2(2.0f,0.f), 0);
      fd2->shape = &bs2;
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 10.0;
      fd3->friction = 0.5;
      fd3->restitution = 0.f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape bs3;
      bs3.SetAsBox(0.2,2, b2Vec2(-2.0f,0.f), 0);
      fd3->shape = &bs3;
       
      b2Body* box2 = m_world->CreateBody(bd);
      box2->CreateFixture(fd1);
      box2->CreateFixture(fd2);
      box2->CreateFixture(fd3);

      //The bar
      bd->position.Set(30,5);  
      fd1->density = 34.0;    
      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);

      // The pulley joint
      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody1(30, 5); // Anchor point on body 1 in world axis
      b2Vec2 worldAnchorOnBody2(18, 5); // Anchor point on body 2 in world axis
      b2Vec2 worldAnchorGround1(30, 10); // Anchor point for ground 1 in world axis
      b2Vec2 worldAnchorGround2(18, 10); // Anchor point for ground 2 in world axis
      float32 ratio = 1.0f; // Define ratio
      myjoint->Initialize(box1, box2, worldAnchorGround1, worldAnchorGround2, box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);
    }

    //The revolving horizontal platform
    {
      b2PolygonShape shape;
      shape.SetAsBox(2.2f, 0.2f);
  
      b2BodyDef bd;
      bd.position.Set(22.0f, 14.0f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 1.f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      body->CreateFixture(fd);

      b2PolygonShape shape2;
      shape2.SetAsBox(0.2f, 2.0f);
      b2BodyDef bd2;
      bd2.position.Set(22.0f, 14.0f);
      b2Body* body2 = m_world->CreateBody(&bd2);

      b2RevoluteJointDef jointDef;
      jointDef.bodyA = body;
      jointDef.bodyB = body2;
      jointDef.localAnchorA.Set(0,0);
      jointDef.localAnchorB.Set(0,0);
      jointDef.collideConnected = false;
      m_world->CreateJoint(&jointDef);
    }

/*///////////////////////////
{
      b2PolygonShape shape;
      shape.SetAsBox(2.0f, 0.10f);
      b2BodyDef bd;
      bd.position.Set(-24.0f, 32.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.10f, 4.0f);
      b2BodyDef bd;
      bd.position.Set(-25.5f, 35.5f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
    //////////////////////*/



    //The heavy sphere on the platform
    {
      b2Body* sbody;
      b2CircleShape circle;
      circle.m_radius = 1.0;
  
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 40.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(22.0f, 16.0f);
      sbody = m_world->CreateBody(&ballbd);
      sbody->CreateFixture(&ballfd);
    }


    //The see-saw system at the bottom
    {
      //The triangle wedge
      b2Body* sbody;
      b2PolygonShape poly;
      b2Vec2 vertices[3];
      vertices[0].Set(-1,0);
      vertices[1].Set(1,0);
      vertices[2].Set(0,1.5);
      poly.Set(vertices, 3);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(8.0f, 0.0f);
      sbody = m_world->CreateBody(&wedgebd);
      sbody->CreateFixture(&wedgefd);



      //The plank on top of the wedge
      b2PolygonShape shape;
      shape.SetAsBox(10.0f, 0.2f);
      b2BodyDef bd2;
      bd2.position.Set(8.0f, 1.5f);
      bd2.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd2);
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 1.f;
      fd2->shape = new b2PolygonShape;
      fd2->shape = &shape;
      body->CreateFixture(fd2);

      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(8.0f, 1.5f);
      jd.Initialize(sbody, body, anchor);
      m_world->CreateJoint(&jd);
  
    
      //The light box on the right side of the see-saw
      b2PolygonShape shape2;
      shape2.SetAsBox(2.0f, 2.0f);
      b2BodyDef bd3;
      bd3.position.Set(40.0f, 2.0f);
      bd3.type = b2_dynamicBody;
      b2Body *b3 = m_world->CreateBody(&bd3);
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 0.01f;
      fd3->shape = new b2PolygonShape;
      fd3->shape = &shape2;
      b3->CreateFixture(fd3);
    }


    //The see-saw system at the bottom
    {
      //The triangle wedge
      b2Body* sbody;
      b2PolygonShape poly;
      b2Vec2 vertices[3];
      vertices[0].Set(-1,0);
      vertices[1].Set(1,0);
      vertices[2].Set(0,2.5);
      poly.Set(vertices, 3);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(-10.0f, 0.0f);
      sbody = m_world->CreateBody(&wedgebd);
      sbody->CreateFixture(&wedgefd);

      //The plank on top of the wedge
      b2PolygonShape shape;
      shape.SetAsBox(10.0f, 0.2f);
      b2BodyDef bd2;
      bd2.position.Set(-10.0f, 2.5f);
      bd2.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd2);
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 1.f;
      fd2->shape = new b2PolygonShape;
      fd2->shape = &shape;
      body->CreateFixture(fd2);

      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-10.0f, 2.5f);
      jd.Initialize(sbody, body, anchor);
      m_world->CreateJoint(&jd);
      
      //The light box on the right side of the see-saw
      b2PolygonShape shape2;
      shape2.SetAsBox(2.0f, 2.0f);
      b2BodyDef bd3;
      bd3.position.Set(40.0f, 2.0f);
      bd3.type = b2_dynamicBody;
      b2Body *b3 = m_world->CreateBody(&bd3);
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 0.01f;
      fd3->shape = new b2PolygonShape;
      fd3->shape = &shape2;
      b3->CreateFixture(fd3);
    }
    //The open box
      {
       b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-3,5);
      //bd->fixedRotation = true;
           
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.5;
      fd1->restitution = 0.f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(2,0.2, b2Vec2(0.f,-1.9f), 0);
      fd1->shape = &bs1;
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.5;
      fd2->restitution = 0.f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.2,2, b2Vec2(2.0f,0.f), 0);
      fd2->shape = &bs2;
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 10.0;
      fd3->friction = 0.5;
      fd3->restitution = 0.f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape bs3;
      bs3.SetAsBox(0.2,2, b2Vec2(-2.0f,0.f), 0);
      fd3->shape = &bs3;
       
      b2Body* box2 = m_world->CreateBody(bd);
      box2->CreateFixture(fd1);
      box2->CreateFixture(fd2);
      box2->CreateFixture(fd3);
      }
  
}
Пример #7
0
  /**  This is the constructor \n
   * This is the documentation block for the constructor.
   */
  dominos_t::dominos_t()
  {
    //Ground
   /** The ground has an EdgeShape between co-ordinates (-90, 0) and (90, 0).
     * 
     */ 
    b2Body* b1;
    {
      
      b2EdgeShape shape; 
      shape.Set(b2Vec2(-90.0f, 0.0f), b2Vec2(90.0f, 0.0f));
      b2BodyDef bd; 
      b1 = m_world->CreateBody(&bd); 
      b1->CreateFixture(&shape, 0.0f);
    }      
    //Top horizontal shelf
    /** The top horizontal shelf has a PolygonShape of dimensions (6,0.25).\n
     * The center of the shelf is at (-31, 30).
     *
     */
    {
      b2PolygonShape shape;
      shape.SetAsBox(6.0f, 0.25f);
	
      b2BodyDef bd;
      bd.position.Set(-31.0f, 30.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }

    //Dominos
    /** The Dominos have PolygonShape of dimensions (0.2, 2.0). \n
     * The center of the ith domino is at (-35.5 + i, 31.25). \n
     * There are 10 dominos. \n
     * They have a density of 20.
     *
     */
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.0f);
	
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
		
      for (int i = 0; i < 10; ++i)
	{
	  b2BodyDef bd;
	  bd.type = b2_dynamicBody;
	  bd.position.Set(-35.5f + 1.0f * i, 31.25f);
	  b2Body* body = m_world->CreateBody(&bd);
	  body->CreateFixture(&fd);
	}
    }
      
    //Another horizontal shelf
    /** The second horizontal shelf has a PolygonShape of dimensions (14, 0.5). \n
     * Its center is located at (-20, 20).
     *
     */
    {
      b2PolygonShape shape;
      shape.SetAsBox(7.0f, 0.25f, b2Vec2(-20.f,20.f), 0.0f);
	
      b2BodyDef bd;
      bd.position.Set(1.0f, 6.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
    //The long box on the left
    /** The Long Box on the left has a PolygonShape SetAsBox of size (1, 16).\n
     * It's position is (-40, 8).\n
     * It's velocity is (0, 20).\n
     * It's angular velocity is -1.\n
     * It's density is 0.01
     *
     */
    {
      b2PolygonShape shape2;
      shape2.SetAsBox(1.0f, 16.0f);
      b2BodyDef bd3;
      bd3.position.Set(-40.0f, 8.0f);
      bd3.type = b2_dynamicBody;
      bd3.angularVelocity = -1.0f;
      bd3.linearVelocity.Set(0.0f, 20.0f);
      b2Body* body3 = m_world->CreateBody(&bd3);
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 0.01f;
      fd3->shape = new b2PolygonShape;
      fd3->shape = &shape2;
      body3->CreateFixture(fd3);
    }

    //The Ball Hitting the Long Box
    /** The ball has a CircleShape of radius 1. \n
     *  It's position is (-50,10). \n
     *  It has a linear velocity of (30,10). \n
     *  It has a density of 2.
     *
     */
  
    {
    b2Body* spherebody;	
      b2CircleShape circle;
      circle.m_radius = 1.0;
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 2.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
	  b2BodyDef ballbd;
	  ballbd.linearVelocity.Set(30.0f, 10.0f);
	  ballbd.type = b2_dynamicBody;
	  ballbd.position.Set(-50.0f, 10.0f);
	  spherebody = m_world->CreateBody(&ballbd);
	  spherebody->CreateFixture(&ballfd);
	
    }
    {
	//Projectile Hitting The Bob
    /** The projectile has a CircleShape of radius 1. \n
     *  It's position is (-50,50). \n
     *  It has a linear velocity of (30,10). \n
     *  It has a density of 2.
     *
     */
      b2Body* spherebody;
	
      b2CircleShape circle;
      circle.m_radius = 0.5;
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 0.2f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
	  b2BodyDef ballbd;
	  ballbd.linearVelocity.Set(40.0f, 0.0f);
	  ballbd.type = b2_dynamicBody;
	  ballbd.position.Set(-40.0f, 32.0f);
	  spherebody = m_world->CreateBody(&ballbd);
	  spherebody->CreateFixture(&ballfd);
	
    }
    //The pendulum that knocks the dominos off
    /** The pendulum system consists of a revolute joint between a bob and a static body. \n
     * The static body has a PolygonShape of dimensions (0.25,1.5) and is centered at (-36.5,28). \n
     * The bob has a PolygonShape of dimensions (0.25,0.25), is centered at (-40,33) and has a density of 2. \n
     * The anchor is set at (-37,40). 
     * 
     */
    {
      b2Body* b2;
      {
	b2PolygonShape shape;
	shape.SetAsBox(0.25f, 1.5f);
	  
	b2BodyDef bd;
	bd.position.Set(-36.5f, 29.0f);
	b2 = m_world->CreateBody(&bd);
	b2->CreateFixture(&shape, 10.0f);
      }

    
      b2Body* b4;
      {
	b2PolygonShape shape;
	shape.SetAsBox(0.5f, 0.5f);
	  
	b2BodyDef bd;
	bd.type = b2_dynamicBody;
	bd.position.Set(-37.0f, 32.0f);
	b4 = m_world->CreateBody(&bd);
	b4->CreateFixture(&shape, 2.0f);
      }
	
      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-37.0f, 40.0f);
      jd.Initialize(b2, b4, anchor);
      m_world->CreateJoint(&jd);
    }
  
    //The train of small spheres
    /** The train of spheres have a CircleShape of radius 0.5. \n
     *  They have densities of 1. \n
     *  There are 10 spheres. \n
     *  The ith sphere has a position of (-22.2+i,26.6).
     *
     */
    {
      b2Body* spherebody;
	
      b2CircleShape circle;
      circle.m_radius = 0.5;
	
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 1.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
	
      for (int i = 0; i < 10; ++i)
	{
	  b2BodyDef ballbd;
	  ballbd.type = b2_dynamicBody;
	  ballbd.position.Set(-22.2f + i*1.0, 26.6f);
	  spherebody = m_world->CreateBody(&ballbd);
	  spherebody->CreateFixture(&ballfd);
	}
    }

    //The pulley system
    /** The pulley system consists of an open box, a bar and a pulley joint. 
     */

    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-10,15);
      bd->fixedRotation = true;
      
      //The open box
      /** The open box is made up of 3 polygonShape and is centered at (-10,15). \n
       *  One of them has a size of (2,0.2) and have centers are located at (0,-1.9). \n
       *  The other two have sizes of (2,0.2) and centers located at (2,0) and (-2,0) respectively. \n
       *  It has the property of fixed rotation and a density of 10.
       * 
       */
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.5;
      fd1->restitution = 0.f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(2,0.2, b2Vec2(0.f,-1.9f), 0);
      fd1->shape = &bs1;
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.5;
      fd2->restitution = 0.f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.2,2, b2Vec2(2.0f,0.f), 0);
      fd2->shape = &bs2;
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 10.0;
      fd3->friction = 0.5;
      fd3->restitution = 0.f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape bs3;
      bs3.SetAsBox(0.2,2, b2Vec2(-2.0f,0.f), 0);
      fd3->shape = &bs3;
       
      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);
      box1->CreateFixture(fd2);
      box1->CreateFixture(fd3);

      //The bar
      /** The bar has its center at (10,15). \n
       * Its density is 34. 
       * 
       */
      bd->position.Set(10,15);	
      fd1->density = 34.0;	  
      b2Body* box2 = m_world->CreateBody(bd);
      box2->CreateFixture(fd1);

      // The pulley joint
      /** The pulley joint consists of anchor points at (-10,15), (10,15), (10,20) and (10,20). \n
       * The length ratio is 1.
       * 
       */
      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody1(-10, 15); // Anchor point on body 1 in world axis
      b2Vec2 worldAnchorOnBody2(10, 15); // Anchor point on body 2 in world axis
      b2Vec2 worldAnchorGround1(-10, 20); // Anchor point for ground 1 in world axis
      b2Vec2 worldAnchorGround2(10, 20); // Anchor point for ground 2 in world axis
      float32 ratio = 1.0f; // Define ratio
      myjoint->Initialize(box1, box2, worldAnchorGround1, worldAnchorGround2, box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);
    }

    //The revolving horizontal platform
    /** The revolving horizontal platform has a polygonShape of dimensions (2.2,0.2). \n
     *  Its center is located at (14,14). \n
     *  It has a density of 1. \n
     *  It is connected to a hidden static body located at (14,16) via a revolute joint.
     * 
     */
    {
      b2PolygonShape shape;
      shape.SetAsBox(2.2f, 0.2f);
	
      b2BodyDef bd;
      bd.position.Set(14.0f, 14.0f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 1.f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      body->CreateFixture(fd);

      b2PolygonShape shape2;
      shape2.SetAsBox(0.2f, 2.0f);
      b2BodyDef bd2;
      bd2.position.Set(14.0f, 16.0f);
      b2Body* body2 = m_world->CreateBody(&bd2);

      b2RevoluteJointDef jointDef;
      jointDef.bodyA = body;
      jointDef.bodyB = body2;
      jointDef.localAnchorA.Set(0,0);
      jointDef.localAnchorB.Set(0,0);
      jointDef.collideConnected = false;
      m_world->CreateJoint(&jointDef);
    }

    //The heavy sphere on the platform
    /** The heavy sphere on the platform has a CircleShape of radius 1. \n
     * Its center is located at (14,18) and it has a density of 50.
     * 
     */
    {
      b2Body* sbody;
      b2CircleShape circle;
      circle.m_radius = 1.0;
	
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 500.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(14.0f, 18.0f);
      sbody = m_world->CreateBody(&ballbd);
      sbody->CreateFixture(&ballfd);
    }


    //The see-saw system at the bottom
    /** The see-saw is made up of a revolute joint between a static triangle wedge and a plank on top of it. \n
     * The joint is anchored at (30,1.5).
     * 
     */
    {
      //The triangle wedge
      /** The triangular wedge has a PolygonShape consisting of 3 vertices located at (-1,0), (1,0) and (0,1.5). \n
       * It has a density of 10 and center located at (30,0).
       * 
       */
      b2Body* sbody;
      b2PolygonShape poly;
      b2Vec2 vertices[3];
      vertices[0].Set(-1,0);
      vertices[1].Set(1,0);
      vertices[2].Set(0,1.5);
      poly.Set(vertices, 3);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(30.0f, 0.0f);
      sbody = m_world->CreateBody(&wedgebd);
      sbody->CreateFixture(&wedgefd);

      //The plank on top of the wedge
      /** The plank has a PolygonShape of dimensions (15,0.2) and center at (30,1.5). \n
       * It has a density of 1.
       * 
       */
      b2PolygonShape shape;
      shape.SetAsBox(15.0f, 0.2f);
      b2BodyDef bd2;
      bd2.position.Set(30.0f, 1.5f);
      bd2.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd2);
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 1.f;
      fd2->shape = new b2PolygonShape;
      fd2->shape = &shape;
      body->CreateFixture(fd2);

      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(30.0f, 1.5f);
      jd.Initialize(sbody, body, anchor);
      m_world->CreateJoint(&jd);

      //The light box on the right side of the see-saw
      /** The light box on the see-saw has a PolygonShape of dimensions (2,2) and is centered at (40,2). \n
       * It has a density of 0.01.
       * 
       */
      b2PolygonShape shape2;
      shape2.SetAsBox(2.0f, 2.0f);
      b2BodyDef bd3;
      bd3.position.Set(40.0f, 2.0f);
      bd3.type = b2_dynamicBody;
      b2Body* body3 = m_world->CreateBody(&bd3);
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 0.001f;
      fd3->shape = new b2PolygonShape;
      fd3->shape = &shape2;
      body3->CreateFixture(fd3);
    }
  }
Пример #8
0
      /* The is the constructor \n
       * This is the documentation block for the constructor.
       */ 
       dominos_t::dominos_t()
       {

           {    

          /// \par GROUND
          /*! Variable - b1 \n
           *  is a pointer to the base ground
           *  \n Data type - b2Body*
           */
           b2Body* b1;

           {
			  /*! Variable - shape
			   *  \n \brief defines a shape that can be assigned to a body
			   *  \n Data type - b2EdgeShape
			   */
			  /*! b2EdgeShape2 shape is assigned to the b1 pointer
			   */
              b2EdgeShape shape2; 
              shape2.Set(b2Vec2(-90.0f, 0.0f), b2Vec2(-32.0f, 0.0f));
              b2BodyDef bd;  
                
              b1 = m_world->CreateBody(&bd); 
              b1->CreateFixture(&shape2, 0.0f);
              /*! 
               * floor at position = (-28.0f, 0.0f) to (-2.0f, 0.0f)
               */ 
              shape2.Set(b2Vec2(-28.0f, 0.0f), b2Vec2(-2.0f, 0.0f));
              b1->CreateFixture(&shape2, 0.0f);
              /*!  floor at position
               * = (-28.0f, 0.0f) to (-2.0f, 0.0f)
               */ 
              shape2.Set(b2Vec2(2.0f, 0.0f), b2Vec2(90.0f, 0.0f));
              b1->CreateFixture(&shape2, 0.0f);
              /*!  floor at
               * position =(10.0f, 20.0f) to (90.0f, 20.0f)
               */ 
              shape2.Set(b2Vec2(10.0f, 20.0f), b2Vec2(90.0f, 20.0f));
              b1->CreateFixture(&shape2, 0.0f);
              /*! floor at 
               * position =(10.0f, 3.0f) to (90.0f, 3.0f)
               */ 
              shape2.Set(b2Vec2(10.0f, 3.0f), b2Vec2(90.0f, 3.0f));
              b1->CreateFixture(&shape2, 0.0f);
              /*! floor at 
               * position =(10.0f, 37.0f) to (90.0f, 37.0f)
               */ 
              shape2.Set(b2Vec2(10.0f, 37.0f), b2Vec2(90.0f, 37.0f));
              b1->CreateFixture(&shape2, 0.0f);
              /*! floor at 
               * position =(90.0f, 20.0f) to (-35.0f, 20.0f)
               */ 
              shape2.Set(b2Vec2(-90.0f, 20.0f), b2Vec2(-35.0f, 20.0f));
              b1->CreateFixture(&shape2, 0.0f);
              /*! floor at 
               * position =(-90.0f, 3.0f) to (-35.0f, 3.0f)
               */ 
              shape2.Set(b2Vec2(-90.0f, 3.0f), b2Vec2(-35.0f, 3.0f));
              b1->CreateFixture(&shape2, 0.0f);
              /*! floor at 
               * position =(-90.0f, 37.0f) to (-35.0f, 37.0f)
               */ 
              shape2.Set(b2Vec2(-90.0f, 37.0f), b2Vec2(-35.0f, 37.0f));
              b1->CreateFixture(&shape2, 0.0f);

              /*! Variable - shape
               * \n \brief shape for pipe
               * \n Values - position=(0.5f , 10.0f)
               * Data Type = b2PolygonShape
               */ 
               b2PolygonShape shape;
               shape.SetAsBox(0.2f, 1.f);
               
               /*! Variable - bd1
                * \n \brief bode definition for pipe1( at bottom right position )
                * \n Values - position=(-31.5f , 0.0f)
                * Data Type = b2BodyDef
                */ 
               b2BodyDef bd1;
               bd1.position.Set(-31.5f, 0.0f);
               
               /*! Variable - fd2
                * \n \brief fixture for pipe1
                * \n Values - density = 5.0 friction = 0.0f , restitution = 0.0f
                * Data Type = b2FixtureDef
                */ 
               b2FixtureDef *fd2 = new b2FixtureDef;
               fd2->density = 5.0;
               fd2->friction = 0.0f;
               fd2->restitution = 0.f;
               fd2->shape = &shape;

              /*! Variable -  ground1
               *  \n \brief pipe for chain
               *  \n Data type - b2Body
               */
               b2Body* ground1 = m_world->CreateBody(&bd1);
               ground1->CreateFixture(fd2);

               b2BodyDef bd4;
               bd4.position.Set(1.5f, 0.0f);

              /*! Variable -  ground2
               *  \n \brief pipe for chain
               *  \n Data type - b2Body
               */
               b2Body* ground4 = m_world->CreateBody(&bd4);
               ground4->CreateFixture(fd2);

          }

      }

      {   /// \par ELEVATOR BOX

              /*! Variable -  bd
               *  \n \brief A body definition of elevator box
               *  \n Data type -  b2FixtureDef*
               *  \n Values - fixed rotation,position= (0,30)
               */
               b2BodyDef *bd = new b2BodyDef;
               bd->type = b2_dynamicBody;
               bd->position.Set(0,30);
               bd->fixedRotation = true;

              /*! Variable -  fd1
               *  \n \brief fixture for elevator box
               *  \n Data type -  b2FixtureDef*
               *  \n Values - friction = 0.0f, restitution = 0f
               */
               b2FixtureDef *fd1 = new b2FixtureDef;
               fd1->friction = 0.0f;
               fd1->restitution = 0.f;
               fd1->shape = new b2PolygonShape;

              /*! Variable -  bs1
               *  \n \brief The shape and position of the elevator box
               *  \n Data type -  b2PolygonShape
               */
               b2PolygonShape bs1;
               bs1.SetAsBox(7,5, b2Vec2(0.f,0.f), 0);
               fd1->shape = &bs1;

              
               bd->position.Set(0,25);
               fd1->density =  5.;
               fd1->filter.groupIndex = -1;

              /*! Variable -  box1
               * \n \brief The Elevator Box
               * \n Data type -  b2Body*
               * \n Values - fixture fd1
               */
               box1 = m_world->CreateBody(bd);
               box1->CreateFixture(fd1);
               fd1->filter.groupIndex = 0;


               { /// \par ELEVATOR DOORS
				   
                /*! Variable - centerCircleDef
                 * \n \brief body definition of center circle
                 * \n Values - position=(0,32)
                 * Data type - b2BodyDef
                 */ 
                 b2BodyDef centerCircleDef;
                 centerCircleDef.type = b2_dynamicBody;
                 centerCircleDef.position.Set(0,32);
                 b2Body* centreCircle = m_world->CreateBody(&centerCircleDef);
          
                /*! Variable - circleShape
                 * \n \brief shape for center circle
                 * \n Values - position=(0,0)
                 * \n Data Type - b2CircleShape
                 */
                 b2CircleShape circleShape;
                 circleShape.m_p.Set(0, 0); 
                 circleShape.m_radius = 1.5f; 
                 
                /*! Variable - centerCircleFixtureDef
                 * \n \brief fixture for center circle
                 * \n Values - density=1.0f 
                 * \n Data Type - b2FixtureDef
                 */
                 b2FixtureDef centerCircleFixtureDef;
                 centerCircleFixtureDef.shape = &circleShape;
                 centerCircleFixtureDef.density = 1.0f;
                 centerCircleFixtureDef.filter.groupIndex = -1;
                 centreCircle->CreateFixture(&centerCircleFixtureDef);
                 
                /*! Variable - rectBodyDef1
                 * \n \brief Body definition for door
                 * \n Values - position=(1,31)
                 * \n Data Type - b2BodyDef
                 */
                 b2BodyDef rectBodyDef1;
                 rectBodyDef1.type = b2_dynamicBody;
                 rectBodyDef1.position.Set(1,31);
                 b2Body* doorRect1 = m_world->CreateBody(&rectBodyDef1);
                 
                 /*! Variable - rectShape1
                  * \n \brief shape for door1
                  * \n Values - length=0.2 , height =1 ,  position= (0,0) , angle = 0
                  * \n Data Type - b2PolgonShape
                  */
                 b2PolygonShape rectShape1;
                 rectShape1.SetAsBox(0.2,1,b2Vec2(0,0), 0);
                 
                 /*! Variable - rectFixtureDef
                  * \n \brief fixture for door1
                  * \n Values - density=0.1f , 
                  * \n Data Type - b2CircleShape
                  */
                 b2FixtureDef rectFixtureDef;
                 rectFixtureDef.shape = &rectShape1;
                 rectFixtureDef.density = 0.1f;
                 rectFixtureDef.filter.groupIndex = -1;
                 doorRect1->CreateFixture(&rectFixtureDef);
                 
                 /*! Variable - rodJointDef1
                  * \n \brief revolute joint between door and center circle
                  * \n Values - collide connect = false
                  * \n Data Type - b2RevoluteJointDef
                  */
                 b2RevoluteJointDef rodJointDef1;
                 rodJointDef1.bodyA = centreCircle;
                 rodJointDef1.bodyB = doorRect1;
                 rodJointDef1.collideConnected = false;
                 
                 

                 rodJointDef1.localAnchorA.Set(1,0);
                 rodJointDef1.localAnchorB.Set(0,1);
                 m_world->CreateJoint(&rodJointDef1);
                 
                 /*! Variable - circleToWorldJointDef
                  * \n \brief revolute joint between center circle and elevator box
                  * \n Values - enable motor , collide connect , max motor torque , motor speed
                  * \n Data Type - b2CircleShape
                  */
                 b2RevoluteJointDef circleToWorldJointDef;
                 circleToWorldJointDef.bodyA = centreCircle;
                 circleToWorldJointDef.bodyB = box1;
                 circleToWorldJointDef.collideConnected = false;
                 circleToWorldJointDef.enableMotor = true;
                 circleToWorldJointDef.maxMotorTorque = 1000;
                 circleToWorldJointDef.motorSpeed = 0;

                 circleToWorldJointDef.localAnchorA.Set(0,0);
                 circleToWorldJointDef.localAnchorB.Set(0,7);
                 circleToWorldJoint = (b2RevoluteJoint *)m_world->CreateJoint(&circleToWorldJointDef);

                 {
                   
                  /*! Variable - rectShape3
                   * \n \brief shape for door1
                   * \n Values - position=(-2,5,-1) length=2.5 height=0.2
                   * \n Data Type - b2CircleShape
                   */ 
                  b2PolygonShape rectShape3;
                  rectShape3.SetAsBox(2.5,0.2,b2Vec2(-2.5,-1), 0);
                  
                  /*! Variable - rectFixtureDef3
                   * \n \brief fixture for door1
                   * \n Values - 
                   * \n Data Type - b2CircleShape
                   */
                  b2FixtureDef rectFixtureDef3;
                  rectFixtureDef3.shape = &rectShape3;
                  rectFixtureDef3.filter.groupIndex = -1;
                  doorRect1->CreateFixture(&rectFixtureDef3);

              }

              {
          
                  /*! Variable - doorMainRodDef
                   * \n \brief body definition for door main rod
                   * \n Values - position=(-4,29.5)
                   * \n Data Type - b2BodyDef
                   */
                  b2BodyDef doorMainRodDef;
                  doorMainRodDef.type = b2_dynamicBody;
                  doorMainRodDef.position.Set(-4,29.5);
                  b2Body *doorMainRod = m_world->CreateBody(&doorMainRodDef);
                  
                  /*! Variable - doorMainRodShape
                   * \n \brief shape for door Main Rod
                   * \n Values - length=0.3 height=2.5 position=(0,0)
                   * \n Data Type - b2PolygonShape
                   */
                  b2PolygonShape doorMainRodShape;
                  doorMainRodShape.SetAsBox(0.3,2.5,b2Vec2(0,0),0);
                  
                  /*! Variable - doorMainRodFixtureDef
                   * \n \brief fixture for door main rod
                   * \n Values - density = 0.1f 
                   * \n Data Type - b2FixtureDef
                   */
                  b2FixtureDef doorMainRodFixtureDef;
                  doorMainRodFixtureDef.shape = &doorMainRodShape;
                  doorMainRodFixtureDef.density = 0.1f;
                  doorMainRodFixtureDef.filter.groupIndex = -1;
                  doorMainRod->CreateFixture(&doorMainRodFixtureDef);
                  
                  /*! Variable - rodToWorldDef
                   * \n \brief Revolute joint between elevator box and door main rod
                   * \n Values - collide connect = false
                   * \n Data Type - b2RevoluteJointDef
                   */
                  b2RevoluteJointDef rodToWorldJointDef;
                  rodToWorldJointDef.bodyA = box1;
                  rodToWorldJointDef.bodyB = doorMainRod;
                  rodToWorldJointDef.collideConnected = false;

                  rodToWorldJointDef.localAnchorA.Set(-4,7);
                  rodToWorldJointDef.localAnchorB.Set(0,2.5);
                  m_world->CreateJoint(&rodToWorldJointDef);
                  
                  /*! Variable - rodToRodJointDef
                   * \n \brief Revolute joint between door1 and door main rod
                   * \n Values - collide connect = false
                   * \n Data Type - b2RevoluteJointDef
                   */
                  b2RevoluteJointDef rodToRodJointDef;
                  rodToRodJointDef.bodyA = doorRect1;
                  rodToRodJointDef.bodyB = doorMainRod;
                  rodToRodJointDef.collideConnected = false;

                  rodToRodJointDef.localAnchorA.Set(-3.5,-1);
                  rodToRodJointDef.localAnchorB.Set(0,0);
                  m_world->CreateJoint(&rodToRodJointDef);
                  
                  /*! Variable - doorBodyDef
                   * \n \brief body definition for door
                   * \n Values - position=(2,24)
                   * \n Data Type - b2BodyDef
                   */
                  b2BodyDef doorBodyDef;
                  doorBodyDef.type = b2_dynamicBody;
                  doorBodyDef.position.Set(2,24);
                  doorBody = m_world->CreateBody(&doorBodyDef);
                  doorBodyDef.position.Set(1,24);
                  b2Body* doorEntrance = m_world->CreateBody(&doorBodyDef);
                  
                  /*! Variable - doorBodyShape
                   * \n \brief shape for door
                   * \n Values - length = 2 , height = 4 , position = (0,0) 
                   * \n Data Type - b2PolygonShape
                   */
                  b2PolygonShape doorBodyShape;
                  doorBodyShape.SetAsBox(2,4,b2Vec2(0,0),0);
                  
                  /*! Variable - doorBodyFixtureDef
                   * \n \brief fixture for door
                   * \n Values - density = 0.1f 
                   * \n Data Type - b2FixtureDef
                   */
                  b2FixtureDef doorBodyFixtureDef;
                  doorBodyFixtureDef.shape = &doorBodyShape;
                  doorBodyFixtureDef.density = 0.1f;
                  doorBodyFixtureDef.filter.groupIndex = -1;
                  doorBody->CreateFixture(&doorBodyFixtureDef);

                  doorBodyShape.SetAsBox(1.5,4,b2Vec2(0,0),0);
                  doorBodyFixtureDef.shape = &doorBodyShape;
                  doorEntrance->CreateFixture(&doorBodyFixtureDef);

                  b2WeldJointDef* wj = new b2WeldJointDef;
                  wj->Initialize(box1,doorEntrance,box1->GetWorldCenter());
                  m_world->CreateJoint(wj);
                  
                  /*! Variable - doorTBoxJoint
                   * \n \brief prismatic joint between elevator box and door
                   * \n Values - collide connect = false , local axis = (1,0)
                   * \n Data Type - b2PrismaticJointDef
                   */
                  b2PrismaticJointDef doorToBoxJoint;
                  doorToBoxJoint.bodyA = box1;
                  doorToBoxJoint.bodyB = doorBody;
                  doorToBoxJoint.localAxisA = b2Vec2(1,0);
                  doorToBoxJoint.collideConnected = false;

                  doorToBoxJoint.localAnchorA.Set(0,-5);
                  doorToBoxJoint.localAnchorB.Set(0,-4);
                  m_world->CreateJoint(&doorToBoxJoint);

                 /*! Variable - mainRodToDoorJoint
                  * \n \brief wheel joint between door and door main rod
                  * \n Data Type - b2WheelJointDef
                  */
                  b2WheelJointDef mainRodToDoorJoint;
                  mainRodToDoorJoint.Initialize(doorBody, doorMainRod, doorMainRod->GetPosition()+b2Vec2(0,-2), b2Vec2(0,1));
                  mainRodToDoorJoint.localAnchorA.Set(-2,0);
                  m_world->CreateJoint(&mainRodToDoorJoint);

                  doorMainRod->SetTransform(b2Vec2(-4+3.5/2,32-3.5/2), 3.14/4);


              }

          }

          { /// \par FRAMES 

              /*! Variable - shape
               * \n \brief shape for frames
               * \n Values - position=(0.5f , 10.0f)
               * Data Type = b2PolygonShape
               */ 
               b2PolygonShape shape;
               shape.SetAsBox(0.5f, 10.f);
               
               /*! Variable - bd1
                * \n \brief bode definition for frame1( at bottom right position )
                * \n Values - position=(7.5f , 10.0f)
                * Data Type = b2BodyDef
                */ 
               b2BodyDef bd1;
               bd1.position.Set(7.5f, 10.0f);
               
               /*! Variable - fd2
                * \n \brief fixture for ground1
                * \n Values - density = 5.0 friction = 0.0f , restitution = 0.0f
                * Data Type = b2FixtureDef
                */ 
               b2FixtureDef *fd2 = new b2FixtureDef;
               fd2->density = 5.0;
               fd2->friction = 0.0f;
               fd2->restitution = 0.f;
               fd2->shape = &shape;
               fd2->filter.groupIndex = -1;

              /*! Variable -  ground1
               *  \n \brief body for frame1
               *  \n Data type - b2Body
               */
               b2Body* ground1 = m_world->CreateBody(&bd1);
               ground1->CreateFixture(fd2);

               /*! Variable - bd2
                * \n \brief body defintion for frame2 (at top right position)
                * \n Values - position=(7.5f , 38.0f)
                * Data Type = b2BodyDef
               */  
               b2BodyDef bd2;
               bd2.position.Set(7.5f, 30.0f);

              /*! Variable -  ground2
               * \n \brief body for frame2
               *  \n Data type - b2Body
               */
               b2Body* ground2 = m_world->CreateBody(&bd2);
               ground2->CreateFixture(fd2);

               /*! Variable - bd3
                * \n \brief body definition for frame3(at bottom left position)
                * \n Values - position=(-7.5f , 10.0f)
                * Data Type = b2BodyDef
                */ 
               b2BodyDef bd3;
               bd3.position.Set(-7.5f, 10.0f);

              /*! Variable -  ground3
               * \n \brief body for frame3
               *  \n Data type - b2Body
               */
               b2Body* ground3 = m_world->CreateBody(&bd3);
               ground3->CreateFixture(fd2);
               
               /*! Variable - bd4
                * \n \brief body definition for frame4(at top left position)
                * \n Values - position=(-7.5f , 38.0f)
                * Data Type = b2BodyDef
                */ 
               b2BodyDef bd4;
               bd4.position.Set(-7.5f, 30.0f);

              /*! Variable -  ground4
               * \n \brief body for frame4
               *  \n Data type - b2Body
               */
               b2Body* ground4 = m_world->CreateBody(&bd4);
               ground4->CreateFixture(fd2);
               
               /*! Variable - prismaticJointDef
                * \n \brief prismatic joint between frame3 and elevator box
                * Data Type = b2PrismaticJointDef
                */ 
               b2PrismaticJointDef* prismaticJointDef = new b2PrismaticJointDef;
               prismaticJointDef->bodyB = ground3;
               prismaticJointDef->bodyA = box1;
               prismaticJointDef->collideConnected = false;
               prismaticJointDef->localAxisA.Set(0,1);
               prismaticJointDef->localAnchorB.Set( 0.5,0);
               prismaticJointDef->localAnchorA.Set(-7,-5);
               prismaticJointDef->enableMotor = false;
               prismaticJointDef->maxMotorForce = 100000.;
               prismaticJointDef->motorSpeed = 5.;
               prismaticJointDef->enableLimit = true;
               prismaticJointDef->lowerTranslation = -10;
               prismaticJointDef->upperTranslation = 10;
               prismaticJoint =  (b2PrismaticJoint*)m_world->CreateJoint(prismaticJointDef);

               prismaticJointDef->bodyA = ground4;
               prismaticJointDef->bodyB = box1;
               prismaticJointDef->collideConnected = false;
               prismaticJointDef->localAxisA.Set(0,1);
               prismaticJointDef->localAnchorA.Set( 0.5,0);
               prismaticJointDef->localAnchorB.Set(-7,5);
               prismaticJointDef->enableMotor = false;  
               prismaticJointDef->enableLimit = false;    
               m_world->CreateJoint(prismaticJointDef);

             /*! Variable - prismaticJointDef2
              * \n \brief prismatic joint between elevator box and frame 
              * Data Type = b2PrismaticJointDef
              */ 
              b2PrismaticJointDef* prismaticJointDef2 = new b2PrismaticJointDef;
              prismaticJointDef2->bodyA = ground1;
              prismaticJointDef2->bodyB = box1;
              prismaticJointDef2->collideConnected = false;
              prismaticJointDef2->localAxisA.Set(0,1);
              prismaticJointDef2->localAnchorA.Set(-0.5,0);
              prismaticJointDef2->localAnchorB.Set(7,-5);
              m_world->CreateJoint(prismaticJointDef2);

              prismaticJointDef2->bodyA = ground2;
              prismaticJointDef2->bodyB = box1;
              prismaticJointDef2->collideConnected = false;
              prismaticJointDef2->localAxisA.Set(0,1);
              prismaticJointDef2->localAnchorA.Set( -0.5,0);
              prismaticJointDef2->localAnchorB.Set(7,5);
              prismaticJointDef2->enableMotor = false;    
              m_world->CreateJoint(prismaticJointDef2);

          }


          { /// \par PULLEY 
            
              /*! Variable -  bs2
               *  \n \brief The shape and position of the equilising box
               *  \n Data type -  b2PolygonShape
               */
               b2PolygonShape bs2;
               bs2.SetAsBox(3.5,7, b2Vec2(0.f,-1.9f), 0);
               fd1->shape = &bs2;

              //The bar2
               bd->position.Set(-30,10);
               fd1->density = 25.0f;

              /*! Variable -  box2
               * \n \brief the equilising box
               * \n Data type -  b2Body*
               */
               box2 = m_world->CreateBody(bd);
               box2->CreateFixture(fd1);

              /*! Variable -  bs3
               *  \n \brief The shape and position of box3
               *  \n Data type -  b2PolygonShape
               */
               b2PolygonShape bs3;
               bs3.SetAsBox(0.5,3, b2Vec2(0.f,0.f), 0);
               fd1->shape = &bs3;

              //The bar3
               bd->position.Set(6,32);
               bd->fixedRotation = false;
               fd1->density = 5.0;
               fd1->filter.groupIndex = -1;


              /*! Variable - shape
               * \n \brief shape for frames of counterweight
               * \n Values - position=(0.5f , 10.0f)
               * Data Type = b2PolygonShape
               */ 
               b2PolygonShape shape;
               shape.SetAsBox(0.5f, 10.f);
               
               /*! Variable - bd1
                * \n \brief bode definition for frame1( at bottom right position )
                * \n Values - position=(7.5f , 10.0f)
                * Data Type = b2BodyDef
                */ 
               b2BodyDef bd1;
               bd1.position.Set(-26.0f, 10.0f);
               
               /*! Variable - fd2
                * \n \brief fixture for ground1
                * \n Values - density = 5.0 friction = 0.0f , restitution = 0.0f
                * Data Type = b2FixtureDef
                */ 
               b2FixtureDef *fd2 = new b2FixtureDef;
               fd2->density = 5.0;
               fd2->friction = 0.0f;
               fd2->restitution = 0.f;
               fd2->shape = &shape;
               fd2->filter.groupIndex = -1;

              /*! Variable -  ground1
               *  \n \brief body for frame1
               *  \n Data type - b2Body
               */
               b2Body* ground1 = m_world->CreateBody(&bd1);
               ground1->CreateFixture(fd2);

               /*! Variable - bd2
                * \n \brief body defintion for frame2 (at top right position)
                * \n Values - position=(7.5f , 38.0f)
                * Data Type = b2BodyDef
                */ 
               b2BodyDef bd2;
               bd2.position.Set(-26.0f, 30.0f);

              /*! Variable -  ground2
               * \n \brief body for frame2
               *  \n Data type - b2Body
               */
               b2Body* ground2 = m_world->CreateBody(&bd2);
               ground2->CreateFixture(fd2);

               /*! Variable - bd3
                * \n \brief body definition for frame3(at bottom left position)
                * \n Values - position=(-7.5f , 10.0f)
                * Data Type = b2BodyDef
                */ 
               b2BodyDef bd3;
               bd3.position.Set(-34.0f, 10.0f);

              /*! Variable -  ground3
               * \n \brief body for frame3
               *  \n Data type - b2Body
               */
               b2Body* ground3 = m_world->CreateBody(&bd3);
               ground3->CreateFixture(fd2);
               
               /*! Variable - bd4
                * \n \brief body definition for frame4(at top left position)
                * \n Values - position=(-7.5f , 38.0f)
                * Data Type = b2BodyDef
                */ 
               b2BodyDef bd4;
               bd4.position.Set(-34.0f, 30.0f);

              /*! Variable -  ground4
               * \n \brief body for frame4
               *  \n Data type - b2Body
               */
               b2Body* ground4 = m_world->CreateBody(&bd4);
               ground4->CreateFixture(fd2);
               
               /*! Variable - prismaticJointDef
                * \n \brief prismatic joint between frame3 and elevator box
                * Data Type = b2PrismaticJointDef
                */ 
               b2PrismaticJointDef* prismaticJointDef = new b2PrismaticJointDef;
               prismaticJointDef->bodyB = ground3;
               prismaticJointDef->bodyA = box2;
               prismaticJointDef->collideConnected = false;
               prismaticJointDef->localAxisA.Set(0,1);
               prismaticJointDef->localAnchorB.Set( 0.5,0);
               prismaticJointDef->localAnchorA.Set(-3.5,-5);
               prismaticJointDef->enableMotor = false;
               prismaticJointDef->maxMotorForce = 100000.;
               prismaticJointDef->motorSpeed = 5.;
               prismaticJointDef->enableLimit = true;
               prismaticJointDef->lowerTranslation = -10;
               prismaticJointDef->upperTranslation = 10;
               m_world->CreateJoint(prismaticJointDef);

               prismaticJointDef->bodyA = ground4;
               prismaticJointDef->bodyB = box2;
               prismaticJointDef->collideConnected = false;
               prismaticJointDef->localAxisA.Set(0,1);
               prismaticJointDef->localAnchorA.Set( 0.5,0);
               prismaticJointDef->localAnchorB.Set(-3.5,5);
               prismaticJointDef->enableMotor = false; 
               prismaticJointDef->enableLimit = false;    
               m_world->CreateJoint(prismaticJointDef);

             /*! Variable - prismaticJointDef2
              * \n \brief prismatic joint between elevator box and frame 
              * Data Type = b2PrismaticJointDef
              */ 
              b2PrismaticJointDef* prismaticJointDef2 = new b2PrismaticJointDef;
              prismaticJointDef2->bodyA = ground1;
              prismaticJointDef2->bodyB = box2;
              prismaticJointDef2->collideConnected = false;
              prismaticJointDef2->localAxisA.Set(0,1);
              prismaticJointDef2->localAnchorA.Set(-0.5,0);
              prismaticJointDef2->localAnchorB.Set(3.5,-5);
              m_world->CreateJoint(prismaticJointDef2);

              prismaticJointDef2->bodyA = ground2;
              prismaticJointDef2->bodyB = box2;
              prismaticJointDef2->collideConnected = false;
              prismaticJointDef2->localAxisA.Set(0,1);
              prismaticJointDef2->localAnchorA.Set( -0.5,0);
              prismaticJointDef2->localAnchorB.Set(3.5,5);
              prismaticJointDef2->enableMotor = false;    
              m_world->CreateJoint(prismaticJointDef2);

              /*! Variable -  box3
               \n \brief safety latch1
               * \n Data type -  b2Body*
               * \n Values - side fd1
               */
               b2Body* box3 = m_world->CreateBody(bd);
               box3->CreateFixture(fd1);      

               b2Vec2 vertices[3];
               vertices[0].Set(0.5f, 3.0f);
               vertices[1].Set(1.f, 2.8f);
               vertices[2].Set(0.5f, 2.8f);
               int32 count = 3;
               b2PolygonShape safetyLatchShape2;
               safetyLatchShape2.Set(vertices, count);

               b2FixtureDef safetyLatchFixture2;
               safetyLatchFixture2.shape = &safetyLatchShape2;
               safetyLatchFixture2.density = 10.f;
               safetyLatchFixture2.filter.groupIndex = -1;
               safetyLatchFixture2.restitution = 0.f;
               box3->CreateFixture(&safetyLatchFixture2); 

               bd->position.Set(-6,32);
               bd->fixedRotation = false;
               fd1->density = 5.0;

              /*! Variable -  box4
               \n \brief safety latch2
               * \n Data type -  b2Body*
               * \n Values - side fd1
               */
               b2Body* box4 = m_world->CreateBody(bd);
               box4->CreateFixture(fd1);
 
               vertices[0].Set(-0.5f, 3.0f);
               vertices[1].Set(-1.f, 2.8f);
               vertices[2].Set(-0.5f, 2.8f);
               safetyLatchShape2.Set(vertices, count);

               safetyLatchFixture2.shape = &safetyLatchShape2;
               box4->CreateFixture(&safetyLatchFixture2);

              /*! Variable -  revoluteJointDef
               * \n \brief revolute joint between elevator and safety latch 1
               * \n Data type -  b2RevoluteJoint
               * \n Values - side fd1
               */
               b2RevoluteJointDef *revoluteJointDef = new b2RevoluteJointDef;
               revoluteJointDef->bodyA = box1;
               revoluteJointDef->bodyB = box3;
               revoluteJointDef->collideConnected = false;
               b2Vec2 worldAnchorOnBody3(6, 5);
               revoluteJointDef->localAnchorA.Set(6,5);
               revoluteJointDef->localAnchorB.Set(0,-2 );
               revoluteJointDef->referenceAngle = 0;
               revoluteJointDef->enableMotor = true;
               revoluteJointDef->maxMotorTorque = 1500;
               revoluteJointDef->motorSpeed = -1;
               revoluteJointDef->enableLimit = true;
               revoluteJointDef->lowerAngle = -3.14/4 ; 
               m_world->CreateJoint(revoluteJointDef);
               
              /*! Variable -  revoluteJointDef2
               * \n \brief revolute joint between elevator box and safety latch2
               * \n Data type -  b2RevoluteJoint
               * \n Values - side fd1
               */
               b2RevoluteJointDef *revoluteJointDef2 = new b2RevoluteJointDef;
               revoluteJointDef2->bodyA = box1;
               revoluteJointDef2->bodyB = box4;
               revoluteJointDef2->collideConnected = false;
               b2Vec2 worldAnchorOnBody4(-6, 5);
               revoluteJointDef2->localAnchorA.Set(-6,5);
               revoluteJointDef2->localAnchorB.Set(0,-2);
               revoluteJointDef2->referenceAngle = 0;
               revoluteJointDef2->enableMotor = true;
               revoluteJointDef2->maxMotorTorque = 1500;
               revoluteJointDef2->motorSpeed = 1;
               revoluteJointDef2->enableLimit = true;
               revoluteJointDef2->upperAngle =  3.14/4 ;
               m_world->CreateJoint(revoluteJointDef2);

              // The pulley joint
              /*! Variable -  myjoint
               * \n \brief The pulley joint between safety latch1 and equilising box
               * \n Data type -   b2PulleyJointDef*
               * \n Values - anchors = twoanchors on bodies worldAnchorOnBody1 and worldAnchorOnBody2, \n
               *  two anchors on ground worldAnchorGround1 and worldAnchorGround2, ratio
               */
              b2PulleyJointDef* myjoint = new b2PulleyJointDef();
              b2Vec2 worldAnchorOnBody1(0, 3); // Anchor point on body 1 in world axis
              b2Vec2 worldAnchorOnBody2(-30, 40); // Anchor point on body 2 in world axis
              b2Vec2 worldAnchorGround1(0, 42); // Anchor point for ground 1 in world axis
              b2Vec2 worldAnchorGround2(-30, 42); // Anchor point for ground 2 in world axis
              float32 ratio = 1.0f; // Define ratio
              /*! The pulley joint myjoint is initialised with all the input values - box1, box2, ratio, anchors
               */
              myjoint->Initialize(box3, box2, worldAnchorGround1, worldAnchorGround2, box3->GetWorldCenter()+worldAnchorOnBody1, box2->GetWorldCenter(), ratio);
              m_world->CreateJoint(myjoint);

              b2PulleyJointDef* myjoint2 = new b2PulleyJointDef();
              /*! The pulley joint myjoint is re-initialised with all the input values - equilising box and safety latch 2, ratio, anchors
               */
              myjoint2->Initialize(box4, box2, worldAnchorGround1, worldAnchorGround2, box4->GetWorldCenter()+worldAnchorOnBody1, box2->GetWorldCenter(), ratio);
              m_world->CreateJoint(myjoint2);

               
          }

          { /// \par SPIKES
          
			/*! Variable - spikesRightDef
			 * \n \brief body defintion for right spikes  in the frame
			 * \n Data type - b2BodyDef
			 */ 
            b2BodyDef spikesRightDef;
            spikesRightDef.type = b2_staticBody;
            spikesRightDef.position.Set(9,0);
            b2Body *spikesRight = m_world->CreateBody(&spikesRightDef);
            
            /*! Variable - vertices(array)
             * \n \brief keeps track of position of right spikes
             * \n Data type - b2Vec2
             */ 

            b2Vec2 vertices[3];
            vertices[0].Set(1.0f, 0.0f);
            vertices[1].Set(0.0f, 2.5f);
            vertices[2].Set(1.0f, 1.0f);
            int32 count = 3;
            b2PolygonShape spikeRightShape;
            spikeRightShape.Set(vertices, count);

            for(int i=0; i<40; i++) {
                b2FixtureDef spikeRightFixture;
                spikeRightFixture.shape = &spikeRightShape;
                spikeRightFixture.density = 0.1f;
                spikeRightFixture.filter.groupIndex = 0;
                spikeRightFixture.restitution = 0.f;
                spikesRight->CreateFixture(&spikeRightFixture);
                vertices[0] += b2Vec2(0,1);
                vertices[1] += b2Vec2(0,1);
                vertices[2] += b2Vec2(0,1);
                spikeRightShape.Set(vertices, count);
            }
        }

        {   /// \par SPIKES
          
			/*! Variable - spikesLeftDef
			 * \n \brief body defintion for left spikes  in the frame
			 * \n Data type - b2BodyDef
			 */ 
            b2BodyDef spikesLeftDef;
            spikesLeftDef.type = b2_staticBody;
            spikesLeftDef.position.Set(-9,0);
            b2Body *spikesLeft = m_world->CreateBody(&spikesLeftDef);
            
            /*! Variable - vertices(array)
             * \n \brief keeps track of position of left spikes
             * \n Data type - b2Vec2
             */ 

            b2Vec2 vertices[3];
            vertices[0].Set(-1.0f, 0.0f);
            vertices[1].Set(0.0f, 2.5f);
            vertices[2].Set(-1.0f, 1.0f);
            int32 count = 3;
            b2PolygonShape spikeLeftShape;
            spikeLeftShape.Set(vertices, count);

            for(int i=0; i<40; i++) {
                b2FixtureDef spikeLeftFixture;
                spikeLeftFixture.shape = &spikeLeftShape;
                spikeLeftFixture.density = 0.1f;
                spikeLeftFixture.filter.groupIndex = 0;
                spikeLeftFixture.restitution = 0.f;
                spikesLeft->CreateFixture(&spikeLeftFixture);
                vertices[0] += b2Vec2(0,1);
                vertices[1] += b2Vec2(0,1);
                vertices[2] += b2Vec2(0,1);
                spikeLeftShape.Set(vertices, count);
            }
        }
        
        {/// \par CHAIN	

			
            /*! Variable - bar
             * \n \brief shape of the segment of the chain attached to the elevator at the bottom
             * \n Values - length = 0.3 , height = 0.5 
             * \n Data type - b2PolygonShape
             */
            b2PolygonShape bar;
            bar.SetAsBox(0.2,0.5);
            
            /*! Variable - bodyDef
             * \n \brief body definition for body (link between elevator box and chain)
             * \n Values - position = (-30,1) , density = 1, friction = 0.5 , restitution = 0.2
             */ 
            b2BodyDef* bodyDef = new b2BodyDef();
            bodyDef->type = b2_dynamicBody;
            // initial body
            bodyDef->position.x=-30;
            bodyDef->position.y=1;
            b2FixtureDef* boxDef = new b2FixtureDef();
            boxDef->shape=&bar;
            boxDef->density=5;
            boxDef->friction=0.5;
            boxDef->restitution=0.2;
            
            /*! Variable - body
             * \n \brief link between elevator bax and chain
             * \n Data Type - b2Body
             */ 
            b2Body* body=m_world->CreateBody(bodyDef);
            body->CreateFixture(boxDef);
            link = body;

		    /*! Variable - weld_joint
             * \n \brief joint between equilising box  and link(body)
             * \n Data type = b2WeldJointDef
             */ 	
            b2WeldJointDef* weld_joint = new b2WeldJointDef;
            weld_joint->Initialize(box2, body, b2Vec2(-30, 1.5));
            m_world->CreateJoint(weld_joint); 

           for (int i = 1; i <= 1; i++) {
                // rope segment
                b2BodyDef* bodyDef = new b2BodyDef();
                bodyDef->type = b2_dynamicBody;
                bodyDef->position.x=-30;
                bodyDef->position.y=1-i;
                b2FixtureDef* boxDef = new b2FixtureDef();
                boxDef->shape=&bar;
                boxDef->density=5;
                boxDef->friction=0.5;
                boxDef->restitution=0.2;
                b2Body* body=m_world->CreateBody(bodyDef);
                body->CreateFixture(boxDef);
                // joint
                b2RevoluteJointDef* revolute_joint = new b2RevoluteJointDef;
                revolute_joint->Initialize(link, body, b2Vec2(-30, 1-i+0.5));
                m_world->CreateJoint(revolute_joint);
                // saving the reference of the last placed link
                link=body;
            }

            // final body

            bodyDef->position.x=-30;
            bodyDef->position.y=-1;
            /*! Variable - body2
             * \n \brief intermediate link of chain
             * \n Data type b2Body
             */ 
            b2Body* body2 = m_world->CreateBody(bodyDef);
            body2->CreateFixture(boxDef);
            b2RevoluteJointDef* revolute_joint = new b2RevoluteJointDef;
            revolute_joint->Initialize(link, body2, b2Vec2(-30, -0.5));
            m_world->CreateJoint(revolute_joint);

            link = body2;
            bar.SetAsBox(0.5,0.2);  

            for (int i = 1; i <= 29; i++) {
                // rope segment
                b2BodyDef* bodyDef = new b2BodyDef();
                bodyDef->type = b2_dynamicBody;
                bodyDef->position.x=-30+i-0.5;
                bodyDef->position.y=-1;
                b2FixtureDef* boxDef = new b2FixtureDef();
                boxDef->shape=&bar;
                boxDef->density=5;
                boxDef->friction=0.5;
                boxDef->restitution=0.2;
                b2Body* body=m_world->CreateBody(bodyDef);
                body->CreateFixture(boxDef);
                // joint
                b2RevoluteJointDef* revolute_joint = new b2RevoluteJointDef;
                revolute_joint->Initialize(link, body, b2Vec2(-30-1+i, -1));
                m_world->CreateJoint(revolute_joint);
                // saving the reference of the last placed link
                link=body;
            }

             // final body
            bodyDef->position.x=-0.5;
            bodyDef->position.y=-1;
            /*! Variable - body3
             * \n \brief 2nd intermediate link in chain
             * \n Data type - b2Body
             */ 
            b2Body* body3 = m_world->CreateBody(bodyDef);
            boxDef->shape=&bar;
            body3->CreateFixture(boxDef);
            /*! Variable - revolute_joint
             * \n \brief joint between links of chain
             * \n Data type - b2RevoluteJoint
             */ 
            revolute_joint->Initialize(link, body3, b2Vec2(-1, -1));
            m_world->CreateJoint(revolute_joint);

            link = body3;
            bar.SetAsBox(0.2,0.5);  

            for (int i = 1; i <= 21; i++) {
                // rope segment
                b2BodyDef* bodyDef = new b2BodyDef();
                bodyDef->type = b2_dynamicBody;
                bodyDef->position.x=0;
                bodyDef->position.y=-1+0.5+i-1;
                b2FixtureDef* boxDef = new b2FixtureDef();
                boxDef->shape=&bar;
                boxDef->density=5;
                boxDef->friction=0.5;
                boxDef->restitution=0.2;
                boxDef->filter.groupIndex = -1;
                b2Body* body=m_world->CreateBody(bodyDef);
                body->CreateFixture(boxDef);
                // joint
                b2RevoluteJointDef* revolute_joint = new b2RevoluteJointDef;
                revolute_joint->Initialize(link, body, b2Vec2(0, -1 +i -1));
                m_world->CreateJoint(revolute_joint);
                // saving the reference of the last placed link
                link=body;
            }

			/*! Variable - weld joint
             * \n linking elevator box and chain
             */ 
            weld_joint->Initialize(box1, link, b2Vec2(0, 20));
            m_world->CreateJoint(weld_joint); 

        }

           
          {      
              /*! Variable - centerCircleDef
               * \n \brief body definition of disc at bottom of frame
               * \n Values - position=(-28.5,-0)
               * Data type - b2BodyDef
               */ 
               b2BodyDef centerCircleDef;
               centerCircleDef.position.Set(-28.5,-0);
               centerCircleDef.type = b2_staticBody;       
               b2Body* nail = m_world->CreateBody(&centerCircleDef);

              /*! Variable - circleShape
               * \n \brief shape for disc
               * \n Values - position=(0,0) , radius = 0.8f
               * \n Data Type - b2CircleShape
               */
               b2CircleShape circleShape;
               circleShape.m_p.Set(0, 0); 
               circleShape.m_radius = 0.8f;
               
              /*! Variable - centerCircleFixtureDef
               * \n \brief fixture for disc
               * \n Values - density=1.0f 
               * \n Data Type - b2FixtureDef
               */
               b2FixtureDef centerCircleFixtureDef;
               centerCircleFixtureDef.shape = &circleShape;
               centerCircleFixtureDef.density = 1.0f;
  
               nail->CreateFixture(&centerCircleFixtureDef);
          }       

         {      
            /*! Variable - centerCircleDef
             * \n \brief body definition of another disc
             * \n Values - position=(-1.5,-0)
             * Data type - b2BodyDef
             */ 
             b2BodyDef centerCircleDef;
             centerCircleDef.position.Set(-1.5,-0);
             centerCircleDef.type = b2_staticBody;       
             b2Body* nail = m_world->CreateBody(&centerCircleDef);

            /*! Variable - circleShape
             * \n \brief shape for another disc
             * \n Values - position=(0,0) , radius = 0.8f
             * \n Data Type - b2CircleShape
             */
             b2CircleShape circleShape;
             circleShape.m_p.Set(0, 0); 
             circleShape.m_radius = 0.8f;
             
            /*! Variable - centerCircleFixtureDef
             * \n \brief fixture for another disc
             * \n Values - density=1.0f 
             * \n Data Type - b2FixtureDef
             */
             b2FixtureDef centerCircleFixtureDef;
             centerCircleFixtureDef.shape = &circleShape;
             centerCircleFixtureDef.density = 1.0f;

             nail->CreateFixture(&centerCircleFixtureDef);
        }       

      }

  }  
Пример #9
0
  dominos_t::dominos_t()
  {
    //Ground
    /*! \var b1 
     * \brief pointer to the body ground 
     */ 
    b2Body* b1;  
    {
      
      b2EdgeShape shape; 
      shape.Set(b2Vec2(-90.0f, 0.0f), b2Vec2(90.0f, 0.0f));
      b2BodyDef bd; 
      b1 = m_world->CreateBody(&bd); 
      b1->CreateFixture(&shape, 0.0f);
    }
         
    
    
    //The upper train of small spheres
   {
      b2Body* spherebody;
  
      b2CircleShape circle;
      circle.m_radius = 0.5;
  
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 5.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
    
      for (int i = 0; i < 6; ++i)
  {
    b2BodyDef ballbd;
    ballbd.type = b2_dynamicBody;
    ballbd.position.Set(-22.0f + i*1.0, 17.0f);
    spherebody = m_world->CreateBody(&ballbd);
    spherebody->CreateFixture(&ballfd);
  }
  }

   //The lower train of small spheres
   {
      b2Body* spherebody;
  
      b2CircleShape circle;
      circle.m_radius = 0.5;
  
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 5.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
    
      for (int i = 0; i < 6; ++i)
  {
    b2BodyDef ballbd;
    ballbd.type = b2_dynamicBody;
    ballbd.position.Set(-22.5f + i*1.0, 16.3f);
    spherebody = m_world->CreateBody(&ballbd);
    spherebody->CreateFixture(&ballfd);
  }
  }
    

    //base for keeping balls
    {
      b2PolygonShape shape;
      shape.SetAsBox(2.5f, 0.1f);
  
      b2BodyDef bd;
      bd.position.Set(-20.5f, 14.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }

// left rod of container for keeping balls
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 2.0f);
  
      b2BodyDef bd;
      bd.position.Set(-23.0f, 16.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }

    // right rod of container for keeping balls
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 2.0f);
  
      b2BodyDef bd;
      bd.position.Set(-16.0f, 16.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }

    // 3rd rod above pulley
    {
        b2Body* b2;
        b2PolygonShape shape;
        b2FixtureDef resti;
        resti.restitution=1.0;
        const b2Vec2 center(-18.0,12.0);
        shape.SetAsBox(1.5f, 0.1f,center,-0.5f);
        b2BodyDef bd;
        b2 = m_world->CreateBody(&bd);
        b2->CreateFixture(&shape, 10.0f);

    }

//2rd rod above pulley
  /*  {
        b2Body* b2;
        b2PolygonShape shape;
        b2FixtureDef resti;
        resti.restitution=1.0;
        const b2Vec2 center(-14.0,16.0);
        shape.SetAsBox(3.0f, 0.1f,center,0.5f);
        b2BodyDef bd;
        b2 = m_world->CreateBody(&bd);
        b2->CreateFixture(&shape, 10.0f);

    }


    // 1st rod above pulley
    {
        b2Body* b2;
        b2PolygonShape shape;
        b2FixtureDef resti;
        resti.restitution=1.0;
        const b2Vec2 center(-19.0,13.5);
        shape.SetAsBox(3.0f, 0.1f,center,-0.5f);
        b2BodyDef bd;
        b2 = m_world->CreateBody(&bd);
        b2->CreateFixture(&shape, 10.0f);

    }*/

    //The pulley system
   {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-10,15);
      bd->fixedRotation = true;
      
      //The open box left
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.5;
      fd1->restitution = 0.f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(2,0.1, b2Vec2(-19.0f,-15.0f), 0);
      fd1->shape = &bs1;
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.5;
      fd2->restitution = 0.f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.1,2, b2Vec2(-21.0f,-14.0f), 0);
      fd2->shape = &bs2;
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 10.0;
      fd3->friction = 0.5;
      fd3->restitution = 0.f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape bs3;
      bs3.SetAsBox(0.1,2, b2Vec2(-17.0f,-14.0f), 0);
      fd3->shape = &bs3;
       
      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);
      box1->CreateFixture(fd2);
      box1->CreateFixture(fd3);

       //The open box right
      b2FixtureDef *fd4 = new b2FixtureDef;
      fd4->density = 10.0;
      fd4->friction = 0.5;
      fd4->restitution = 0.f;
      fd4->shape = new b2PolygonShape;
      b2PolygonShape bs4;
      bs4.SetAsBox(3.0,0.1, b2Vec2(-3.0f,-6.0f), 0);
      fd4->shape = &bs4;
      b2FixtureDef *fd5 = new b2FixtureDef;
      fd5->density = 10.0;
      fd5->friction = 0.5;
      fd5->restitution = 0.f;
      fd5->shape = new b2PolygonShape;
      b2PolygonShape bs5;
      bs5.SetAsBox(0.1,1, b2Vec2(-6.0f,-5.0f), 0);
      fd5->shape = &bs5;
      b2FixtureDef *fd6 = new b2FixtureDef;
      fd6->density = 10.0;
      fd6->friction = 0.5;
      fd6->restitution = 0.f;
      fd6->shape = new b2PolygonShape;
      b2PolygonShape bs6;
      bs6.SetAsBox(0.1,1, b2Vec2(0.0f,-5.0f), 0);
      fd6->shape = &bs6;
       
      b2Body* box2 = m_world->CreateBody(bd);
      box2->CreateFixture(fd4);
      box2->CreateFixture(fd5);
      box2->CreateFixture(fd6);

      // The pulley joint
      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody1(-10, 15); // Anchor point on body 1 in world axis
      b2Vec2 worldAnchorOnBody2(10, 26); // Anchor point on body 2 in world axis
      b2Vec2 worldAnchorGround1(-28.5, 10); // Anchor point for ground 1 in world axis
      b2Vec2 worldAnchorGround2(-13, 10); // Anchor point for ground 2 in world axis
      float32 ratio = 1.0f; // Define ratio
      myjoint->Initialize(box1, box2, worldAnchorGround1, worldAnchorGround2, box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);
    } 

//The revolving horizontal platform
   {
      b2PolygonShape shape;
      shape.SetAsBox(7.0f, 0.2f);
  
      b2BodyDef bd;
      bd.position.Set(-8.0f, 7.5f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 1.f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      body->CreateFixture(fd);

      b2PolygonShape shape2;
      shape2.SetAsBox(0.2f, 2.0f);
      b2BodyDef bd2;
      bd2.position.Set(-8.0f, 7.5f);
      b2Body* body2 = m_world->CreateBody(&bd2);

      b2RevoluteJointDef jointDef;
      jointDef.bodyA = body;
      jointDef.bodyB = body2;
      jointDef.localAnchorA.Set(0,0);
      jointDef.localAnchorB.Set(0,0);
      jointDef.collideConnected = false;
      m_world->CreateJoint(&jointDef);
    }


    //negative gravity balls
    {
      b2CircleShape shape;
     // shape.SetAsBox(0.1f, 1.0f);
      shape.m_radius=0.3f;
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
  {
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(0.5f, 1.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->SetGravityScale(-0.2);
    body->CreateFixture(&fd);
  }

  {
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(1.0f, 1.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->SetGravityScale(-0.2);
    body->CreateFixture(&fd);
  }

  {
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(-0.5f, 1.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->SetGravityScale(-0.2);
    body->CreateFixture(&fd);
  }

  {
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(-1.0f, 1.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->SetGravityScale(-0.2);
    body->CreateFixture(&fd);
  }

  {
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(0.5f, 1.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->SetGravityScale(-0.2);
    body->CreateFixture(&fd);
  }

  {
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(1.0f, 1.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->SetGravityScale(-0.2);
    body->CreateFixture(&fd);
  }

  {
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(-0.5f, 1.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->SetGravityScale(-0.2);
    body->CreateFixture(&fd);
  }

  {
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(-1.0f, 1.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->SetGravityScale(-0.2);
    body->CreateFixture(&fd);
  }
    }


    //right box to stop table
    {
      b2PolygonShape shape;
      shape.SetAsBox(2.0f, 0.4f);
  
      b2BodyDef bd;
      bd.position.Set(5.0f, 26.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }

    //left box to stop table
    {
      b2PolygonShape shape;
      shape.SetAsBox(2.0f, 0.4f);
  
      b2BodyDef bd;
      bd.position.Set(-5.0f, 26.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }

    //right box to support table
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 0.4f);
  
      b2BodyDef bd;
      bd.position.Set(4.5f, 14.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }

    //left box to support table
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 0.4f);
  
      b2BodyDef bd;
      bd.position.Set(-3.0f, 14.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }


// table
    {
      b2PolygonShape shape;
      shape.SetAsBox(7.01f, 0.2f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 1.0f;
      fd.friction = 0.1f;
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(0.0f, 14.3f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);
  } 

/////////////////////clamps//////////////////
  //clamp
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 0.1f);
  
      b2BodyDef bd;
      bd.position.Set(9.0f, 23.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
    //clamp
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 0.1f);
  
      b2BodyDef bd;
      bd.position.Set(12.0f, 23.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
//clamp
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 0.1f);
  
      b2BodyDef bd;
      bd.position.Set(-9.0f, 23.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
      //clamp
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 0.1f);
  
      b2BodyDef bd;
      bd.position.Set(-12.0f, 23.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }

    //////////////////////////////////

///////////left hinge-rod pair involved n formation of table
    {
    b2Body* b2;
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.4f, 0.4f);
  
      b2BodyDef bd;
      bd.position.Set(9.0f, 22.0f);
   //   b2Body* ground = m_world->CreateBody(&bd);
     // ground->CreateFixture(&shape, 0.0f);
      b2 = m_world->CreateBody(&bd);
      b2->CreateFixture(&shape, 10.0f);
      
    }
    
    b2Body* b4;
    {
      b2PolygonShape shape;
      shape.SetAsBox(3.2f, 0.1f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 10.0f;
      fd.friction = 0.1f;

      b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(9.0f , 22.0f);
   // b2Body* body = m_world->CreateBody(&bd);
    //body->CreateFixture(&fd);
    b4 = m_world->CreateBody(&bd);
      b4->CreateFixture(&shape, 10.0f);
    }
      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(9.0f, 22.0f);
      jd.Initialize(b2, b4,anchor);

      m_world->CreateJoint(&jd);
    
    
  }

///////////right hinge-rod pair involved n formation of table

   {
    b2Body* b1;
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.4f, 0.4f);
  
      b2BodyDef bd;
      bd.position.Set(-9.0f, 22.0f);
   //   b2Body* ground = m_world->CreateBody(&bd);
     // ground->CreateFixture(&shape, 0.0f);
      b1 = m_world->CreateBody(&bd);
      b1->CreateFixture(&shape, 10.0f);
      
    }
    
    b2Body* b3;
    {
      b2PolygonShape shape;
      shape.SetAsBox(3.65f, 0.1f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 10.0f;
      fd.friction = 0.1f;

      b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(-9.0f , 22.0f);
    b3 = m_world->CreateBody(&bd);
      b3->CreateFixture(&shape, 10.0f);
    }
      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-9.0f, 22.0f);
      jd.Initialize(b1, b3,anchor);

      m_world->CreateJoint(&jd);
  }
  ////////////////////////////////// S starts ////////////////////////////////////
//Top horizontal shelf in S
    {
    b2Body* b2;
    {
      b2PolygonShape shape;
      shape.SetAsBox(6.0f, 0.25f);
  
      b2BodyDef bd;
      bd.position.Set(-31.0f, 40.0f);
   //   b2Body* ground = m_world->CreateBody(&bd);
     // ground->CreateFixture(&shape, 0.0f);
      b2 = m_world->CreateBody(&bd);
      b2->CreateFixture(&shape, 10.0f);
      
    }
    
    b2Body* b4;
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 2.0f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;

      b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(-36.5f , 42.25f);
   // b2Body* body = m_world->CreateBody(&bd);
    //body->CreateFixture(&fd);
    b4 = m_world->CreateBody(&bd);
      b4->CreateFixture(&shape, 10.0f);
    }
      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-36.5f, 40.0f);
      jd.Initialize(b2, b4,anchor);

      m_world->CreateJoint(&jd);
    
    
  }
// second horizontal shelf in S
  {
    b2Body* b5;
    {
      b2PolygonShape shape;
      shape.SetAsBox(6.0f, 0.25f);
  
      b2BodyDef bd;
      bd.position.Set(-31.0f, 35.3f);
   //   b2Body* ground = m_world->CreateBody(&bd);
     // ground->CreateFixture(&shape, 0.0f);
      b5 = m_world->CreateBody(&bd);
      b5->CreateFixture(&shape, 10.0f);
      
    }
    
    b2Body* b7;
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 2.0f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;

      b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(-25.5f , 37.25f);
   // b2Body* body = m_world->CreateBody(&bd);
    //body->CreateFixture(&fd);
    b7 = m_world->CreateBody(&bd);
      b7->CreateFixture(&shape, 10.0f);
    }
      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-25.5f, 35.3f);
      jd.Initialize(b5, b7,anchor);

      m_world->CreateJoint(&jd);
    
    
  }

  // third horizontal shelf in S
  
    b2Body* b8;
    {
      b2PolygonShape shape;
      shape.SetAsBox(6.0f, 0.25f);
  
      b2BodyDef bd;
      bd.position.Set(-31.0f, 30.6f);
   // b2Body* ground = m_world->CreateBody(&bd);
     // ground->CreateFixture(&shape, 0.0f);
      b8 = m_world->CreateBody(&bd);
      b8->CreateFixture(&shape, 10.0f);
      
    }
    
   
  
    //Dominos on top horizontal shelf on S
   {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.0f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
      for (int i = 0; i < 10; ++i)
  {
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(-35.5f + 1.0f * i, 41.25f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);
  }
    }

 //Dominos on second horizontal shelf of S
     {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.0f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
      for (int i = 0; i < 8; ++i)
  {
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(-35.5f + 1.0f * i, 38.25f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);
  }
    }

    //Dominos on third horizontal shelf of S
     {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.0f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
      for (int i = 2; i < 10; ++i)
  {
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(-35.5f + 1.0f * i, 33.25f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);
  }
    }
    // Box on the S
    {
     b2PolygonShape shape;
      shape.SetAsBox(0.5f, 0.5f);
      b2BodyDef bd3;
      bd3.position.Set(-36.0f, 33.0f);
      bd3.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd3);
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 0.01f;
      fd3->shape = new b2PolygonShape;
      fd3->shape = &shape;
      body->CreateFixture(fd3);

  }
  //////////////////////////////////S ends ////////////////////////////////////////

  //The pendulum that knocks the dominos off
   {
      b2Body* b3;
      {
  b2PolygonShape shape;
  shape.SetAsBox(0.25f, 0.1f);
    
  b2BodyDef bd;
  bd.position.Set(-25.5f, 40.0f);
  b3 = m_world->CreateBody(&bd);
  b3->CreateFixture(&shape, 10.0f);
      }
  
      b2Body* b6;
      {
  b2PolygonShape shape;
  shape.SetAsBox(0.4f, 0.4f);
    
  b2BodyDef bd;
  bd.type = b2_dynamicBody;
  bd.position.Set(-20.5f, 43.0f);
  b6 = m_world->CreateBody(&bd);
  b6->CreateFixture(&shape, 2.0f);
      }
  
      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-25.5f, 50.0f);
      jd.Initialize(b3, b6,anchor);

      m_world->CreateJoint(&jd);
    }
      ///////////////////////// W starts //////////////////////////
    // W 1st seg
     for(int i=0;i<7;i++)
    {
        b2Body* b2;
        b2PolygonShape shape;
        b2FixtureDef resti;
        resti.restitution=1.0;
        const b2Vec2 center((-20.0+1.0*i),(40.0-0.2*i*i));
        shape.SetAsBox(1.5f, 0.1f,center,-1.0f);
        b2BodyDef bd;
        b2 = m_world->CreateBody(&bd);
        b2->CreateFixture(&shape, 10.0f);

    }

    //W 4th seg
     for(int i=0;i<6;i++)
    {
        b2Body* b2;
        b2PolygonShape shape;
        b2FixtureDef resti;
        resti.restitution=1.0;
        const b2Vec2 center((-1.0*i),(38.0-0.2*i*i));
        shape.SetAsBox(1.0f, 0.1f,center,1.0f);
        b2BodyDef bd;
        b2 = m_world->CreateBody(&bd);
        b2->CreateFixture(&shape, 10.0f);

    }
// W 3rd seg
     for(int i=0;i<5;i++)
    {
        b2Body* b2;
        b2PolygonShape shape;
        b2FixtureDef resti;
        resti.restitution=1.0;
        const b2Vec2 center((-9.0-1.2*i),(36.0-0.2*i*i));
        shape.SetAsBox(1.0f, 0.1f,center,0.6f);
        b2BodyDef bd;
        b2 = m_world->CreateBody(&bd);
        b2->CreateFixture(&shape, 10.0f);

    }
// W 2nd seg
     for(int i=0;i<5;i++)
    {
        b2Body* b2;
        b2PolygonShape shape;
        b2FixtureDef resti;
        resti.restitution=1.0;
        const b2Vec2 center((-10.0+1.2*i),(36.0-0.2*i*i));
        shape.SetAsBox(0.5+0.1*i, 0.1,center,-0.6f);
        b2BodyDef bd;
        b2 = m_world->CreateBody(&bd);
        b2->CreateFixture(&shape, 10.0f);

    }
    //W plank 1

    {
        b2Body* b2;
        b2PolygonShape shape;
        b2FixtureDef resti;
        resti.restitution=1.0;
        const b2Vec2 center((-14.0),(35.0));
        shape.SetAsBox(1.5, 0.1,center,0.0f);
        b2BodyDef bd;
        b2 = m_world->CreateBody(&bd);
        b2->CreateFixture(&shape, 10.0f);
    }

    //W plank 2

    {
        b2Body* b2;
        b2PolygonShape shape;
        b2FixtureDef resti;
        resti.restitution=1.0;
        const b2Vec2 center((-6.0),(35.0));
        shape.SetAsBox(1.5, 0.1,center,0.0f);
        b2BodyDef bd;
        b2 = m_world->CreateBody(&bd);
        b2->CreateFixture(&shape, 10.0f);
    }

    //  launching plank of ball
    {
        b2Body* b2;
        b2PolygonShape shape;
        b2FixtureDef resti;
        resti.restitution=1.0;
        const b2Vec2 center((-20.0),(41.0));
        shape.SetAsBox(1.0, 0.1,center,-0.2f);
        b2BodyDef bd;
        b2 = m_world->CreateBody(&bd);
        b2->CreateFixture(&shape, 10.0f);
    }

    // The ball
  {
      b2Body* spherebody;

      b2CircleShape circle;
      circle.m_radius = 0.4;

      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 8.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 1.0f;

    b2BodyDef ballbd;
    ballbd.type = b2_dynamicBody;

    ballbd.position.Set(-20.0f, 45.0f);
    spherebody = m_world->CreateBody(&ballbd);
    spherebody->CreateFixture(&ballfd);

    }

    //Motor
    {
    b2Body* motorpane;
    {
     b2PolygonShape shape;
     b2BodyDef bd;
     shape.SetAsBox(0.2f, 3.5f);
     bd.position.Set(2.0f, 42.5f);
     bd.type = b2_dynamicBody;
     motorpane = m_world->CreateBody(&bd);
     motorpane->CreateFixture(&shape, 0.5f);

    }
    b2Body* pin;
    {
     b2CircleShape cshape;
     b2BodyDef bd;
     cshape.m_radius = 0.4;
     bd.position.Set(2.0f, 42.5f);
     pin = m_world->CreateBody(&bd);
     pin->CreateFixture(&cshape, 0.5f);
    }

  b2RevoluteJointDef revoluteJointDef;
  revoluteJointDef.bodyA = motorpane;
  revoluteJointDef.bodyB = pin;
  revoluteJointDef.collideConnected = false;
  revoluteJointDef.localAnchorA.Set(0,0);
  revoluteJointDef.localAnchorB.Set(0,0);
  revoluteJointDef.enableMotor = true;
  revoluteJointDef.maxMotorTorque = 1000.0f;
  revoluteJointDef.motorSpeed = 9.0f;
  b2RevoluteJoint* m_joint = (b2RevoluteJoint*)m_world->CreateJoint( &revoluteJointDef );
  }

     ////////////////////////// W ends  //////////////////////////

  //////////////////////////////G starts /////////////////////////
 //G part
  {
      b2PolygonShape shape;
      shape.SetAsBox(0.25f, 4.0f);

      b2BodyDef bd;
      bd.position.Set(29.0f, 30.0f);
      b2Body* g1 = m_world->CreateBody(&bd);
      g1->CreateFixture(&shape, 0.0f);

      shape.SetAsBox(4.0f,0.25f);
      bd.position.Set(33.0f, 25.5f);
      b2Body* g2 = m_world->CreateBody(&bd);
       g2->CreateFixture(&shape, 0.0f);

     const b2Vec2 center(33.0f,41.0f);
     shape.SetAsBox(4.0f,0.25f,center,0.0f);
     b2BodyDef bd2;
     b2Body* stop = m_world->CreateBody(&bd2);
     stop->CreateFixture(&shape, 10.0f);


       shape.SetAsBox(0.6f, 3.0f);
        bd.position.Set(38.0f, 29.0f);
      b2Body* g3 = m_world->CreateBody(&bd);
      g3->CreateFixture(&shape, 0.0f);

      shape.SetAsBox(0.6f, 0.6f);
        bd.position.Set(38.0f, 33.0f);
        bd.type = b2_dynamicBody;
      b2Body* g4 = m_world->CreateBody(&bd);
      g4->CreateFixture(&shape, 0.0f);



    }


    //G-Door
  {
  b2Body* top;
  {
     b2CircleShape cshape;
     b2BodyDef bd;
     cshape.m_radius = 0.4;
     bd.position.Set(29.0f, 38.0f);
     top = m_world->CreateBody(&bd);
     top->CreateFixture(&cshape, 0.5f);
  }
  b2Body* door;
  {
    b2PolygonShape shape;
    shape.SetAsBox(0.25f,3.0f);
    b2BodyDef doordef;
    doordef.type=b2_dynamicBody;
    doordef.position.Set(29.0f,38.0f);
    door=m_world->CreateBody(&doordef);
    door->CreateFixture(&shape,0.5f);
  }

  b2RevoluteJointDef revoluteJointDef;
  revoluteJointDef.bodyA = top;
  revoluteJointDef.bodyB = door;
  revoluteJointDef.collideConnected = false;
  revoluteJointDef.localAnchorA.Set(0.0f,0.0f);//the top right corner of the box
  revoluteJointDef.localAnchorB.Set(0.0f,0.0f);//center of the circle

  b2RevoluteJoint* m_joint2 = (b2RevoluteJoint*)m_world->CreateJoint( &revoluteJointDef );
  }

  //////////////////////////////G ends  //////////////////////////

    ////////////////////////// A starts ////////////////////////////
     //start of code for A

    //middle horizontal shelf

    {
      b2PolygonShape shape;
      shape.SetAsBox(6.0f, 0.15f, b2Vec2(-20.f,20.f), 0.0f);
  
      b2BodyDef bd;
      bd.position.Set(35.0f, 15.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
//firstdown1 from the middle hor shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(1.0f, 0.15f, b2Vec2(-20.f,20.f), 0.0f);
  
      b2BodyDef bd;
      bd.position.Set(27.0f, 13.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
//firstdown2 from mid hor shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(1.0f, 0.15f, b2Vec2(-20.f,20.f), 0.0f);
  
      b2BodyDef bd;
      bd.position.Set(43.0f, 13.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
//second1 from mid hor shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(1.0f, 0.15f, b2Vec2(-20.f,20.f), 0.0f);
  
      b2BodyDef bd;
      bd.position.Set(45.0f, 11.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
//second2 from mid hor shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(1.0f, 0.15f, b2Vec2(-20.f,20.f), 0.0f);
  
      b2BodyDef bd;
      bd.position.Set(25.0f, 11.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
//firstup1 from mid hor shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.3f, 0.15f, b2Vec2(-20.f,20.f), 0.0f);
  
      b2BodyDef bd;
      bd.position.Set(32.0f, 17.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
//firstup2 from mid hor shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.3f, 0.15f, b2Vec2(-20.f,20.f), 0.0f);
  
      b2BodyDef bd;
      bd.position.Set(38.0f, 17.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
//top hor shelf
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.5f, 0.15f, b2Vec2(-20.f,20.f), 0.0f);
  
      b2BodyDef bd;
      bd.position.Set(35.0f, 19.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }
    
    //Dominos on A

    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.7f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(15.0f, 47.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);
  
    }

    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.7f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(12.0f, 45.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);
  
    }

    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.7f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(18.0f, 45.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);
  
    }

    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.7f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(9.5f, 41.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);

    }

    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.7f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(20.5f, 41.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);
  
    }

    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.7f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(6.5f, 37.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);

    }

    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.7f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(23.5f, 37.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);
  
    }

    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.7f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
  
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(4.5f, 33.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);
  
    }

    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.7f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;
    
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(25.5f, 33.0f);
    b2Body* body = m_world->CreateBody(&bd);
    body->CreateFixture(&fd);
  
    }

    ////////////////////////// A ends  ////////////////////////////

  }
Пример #10
0
  dominos_t::dominos_t()
  {
    //Ground
   /*! \par Making Ground
	 * variable b1 :: <br>
	 * Data Type is b2Body* <br>
	 * pointer to the ground <br>
	 * variable shape :: <br>
	 * Data Type is b2EdgeShape <br>
	 * Its left value is (-90,0) and right value is (90,0) <br>
	 * variable bd :: <br>
	 * Data Type is b2BodyDef <br>
	 * CreateBody is used for Creating Bodies in the Physical world <br>
	 * CreateFixture is used for fixing body in its parent <br>
	 */
    b2Body* b1;
    {

      b2EdgeShape shape;
      shape.Set(b2Vec2(-90.0f, 0.0f), b2Vec2(90.0f, 0.0f));
      b2BodyDef bd;
      b1 = m_world->CreateBody(&bd);
      b1->CreateFixture(&shape, 0.0f);
    }

    //Top horizontal shelf
    /*! \par Top Horizontal Shelf
     * variable shape :: <br>
     * Data Type is b2PolygonShape <br>
     * length : 6 , width : 0.25 , Its Center coordinates are (-31,30) <br>
     * variable bd :: <br>
     * Data Type is b2BodyDef <br>
     * variable ground :: <br>
     * Data Type is b2Body* <br>
     */
    {
      b2PolygonShape shape;
      shape.SetAsBox(6.0f, 0.25f);

      b2BodyDef bd;
      bd.position.Set(-31.0f, 30.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 34.0f);
    }

    //Dominos
    /*! \par Dominos
     * variable shape :: <br>
     * Data Type is b2PolygonShape <br>
     * length : 0.1 , width : 1 <br>
     * 10 dominos are created using a for loop and center position of each domino is different <br>
     * variable fd :: <br>
     * Data Type is b2FixtureDef <br>
     * Density : 20 , Friction : 0.1 <br>
     * variable bd :: <br>
     * Data Type is b2BodyDef <br>
     * type is set to be dynamic <br>
     * variable body :: <br>
     * Data Type is b2Body* <br>
     */
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.0f);

      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 20.0f;
      fd.friction = 0.1f;

      for (int i = 0; i < 10; ++i)
	{
	  b2BodyDef bd;
	  bd.type = b2_dynamicBody;
	  bd.position.Set(-35.5f + 1.0f * i, 31.25f);
	  b2Body* body = m_world->CreateBody(&bd);
	  body->CreateFixture(&fd);
	}
    }

    //Another horizontal shelf
    /*! \par Another Horizontal Shelf
     * variable shape :: <br>
     * Data Type is b2PolygonShape <br>
     * length : 7 , width : 0.25 , Its Center coordinates are (-19,26) and Angle is 0 <br>
     * variable bd :: <br>
     * Data Type is b2BodyDef <br>
     * variable ground :: <br>
     * Data Type is b2Body* <br>
     */
    {
      b2PolygonShape shape;
      shape.SetAsBox(7.0f, 0.25f, b2Vec2(-20.f,20.f), 0.0f);

      b2BodyDef bd;
      bd.position.Set(1.0f, 6.0f);
      b2Body* ground = m_world->CreateBody(&bd);
      ground->CreateFixture(&shape, 0.0f);
    }


    //The pendulum that knocks the dominos off
    /*! \par The pendulum that knocks the dominos off
     * variable shape :: <br>
     * Data Type is b2PolygonShape <br>
     * length : 0.25 , width : 1.5 <br>
     * variable bd :: <br>
     * Data Type is b2BodyDef <br>
     * Its position set to be (-36.5,28) <br>
     * Pendulam Bob is attached to it <br>
     * variable b2 :: <br>
     * Data Type is b2Body* <br> <br>
     * variable shape :: <br>
     * Data Type is b2PolygonShape <br>
     * length : 0.25 , width : 0.25 <br>
     * variable bd :: <br>
     * Data Type is b2BodyDef <br>
     * Its position set to be (-40,33) <br>
     * Pendulam's Bob <br>
     * type is dynamic <br>
     * variable b4 :: <br>
     * Data Type is b2Body* <br><br>
     * variable jd :: <br>
     * Data Type is b2RevoluteJointDef <br>
     * connecting rope and bob <br>
     * Bob is set at coordinates(-37,40) <br>
     */
    {
      b2Body* b2;
      {
	b2PolygonShape shape;
	shape.SetAsBox(0.25f, 1.5f);

	b2BodyDef bd;
	bd.position.Set(-36.5f, 28.0f);
	b2 = m_world->CreateBody(&bd);
	b2->CreateFixture(&shape, 10.0f);
      }

      b2Body* b4;
      {
	b2PolygonShape shape;
	shape.SetAsBox(0.25f, 0.25f);

	b2BodyDef bd;
	bd.type = b2_dynamicBody;
	bd.position.Set(-40.0f, 33.0f);
	b4 = m_world->CreateBody(&bd);
	b4->CreateFixture(&shape, 2.0f);
      }

      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(-37.0f, 40.0f);
      jd.Initialize(b2, b4, anchor);
      m_world->CreateJoint(&jd);
    }

    //The train of small spheres
    /*! \par The train of small spheres
     * variable circle :: <br>
     * Data Type is b2CircleShape <br>
     * radius : 0.5 <br>
     * 10 circles are created using a for loop and center position of each circle is different <br>
     * variable ballfd :: <br>
     * Data Type is b2FixtureDef <br>
     * Density : 1 , Friction : 0.0 , Restitution : 0.0 <br>
     * variable ballbd :: <br>
     * Data Type is b2BodyDef <br>
     * Type is Dynamic <br>
     * Position is (-22.2+i,26.6) of ith circle from the left <br>
     * variable spherebody :: <br>
     * Data Type is b2Body* <br>
     */
    {
      b2Body* spherebody;

      b2CircleShape circle;
      circle.m_radius = 0.5;

      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 1.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;

      for (int i = 0; i < 10; ++i)
	{
	  b2BodyDef ballbd;
	  ballbd.type = b2_dynamicBody;
	  ballbd.position.Set(-22.2f + i*1.0, 26.6f);
	  spherebody = m_world->CreateBody(&ballbd);
	  spherebody->CreateFixture(&ballfd);
	}
    }

    //The pulley system
    /*! \par The pulley system
     * variable bd :: <br>
     * Data Type is b2BodyDef* <br>
     * Type is defined dynamic <br>
     * Its position set to be (-10,15) <br>
     * Fixed Rotation set to be true to remove its rotating degree of freedom <br><br>
     * \par The Open Box
     * variable fd1 :: <br>
     * Data Type is b2FixtureDef* <br>
     * density : 10 , friction : 0.5 , restitution : 0 <br>
     * variable bs1 :: <br>
     * Data Type is b2PolygonShape <br>
     * length : 2 , width : 0.2 its center coordinates are (0,-1.9) , Angle : 0 <br> <br>
     * variable fd2 :: <br>
     * Data Type is b2FixtureDef* <br>
     * density : 10 , friction : 0.5 , restitution : 0 <br>
     * variable bs2 :: <br>
     * Data Type is b2PolygonShape <br>
     * length : 0.2 , width : 2 its center coordinates are (2,0) , Angle : 0 <br> <br>
     * variable fd3 :: <br>
     * Data Type is b2FixtureDef* <br>
     * density : 10 , friction : 0.5 , restitution : 0 <br>
     * variable bs3 :: <br>
     * Data Type is b2PolygonShape <br>
     * length : 0.2 , width : 2 its center coordinates are (-2,0) , Angle : 0 <br> <br>
     * variable box1 :: <br>
     * Data Type is b2Body* <br>
     * \par The Bar
     * position of bd is resetted to (10,15) <br>
     * density of fd1 is changed to 34 <br>
     * variable box2 :: <br>
     * Data Type is b2Body* <br>
     * fd1 is created again with new parameters <br>
     * \par The Pully Joint
     * variable myjoint :: <br>
     * Data Type is b2PulleyJointDef* <br>
     * 4 2D vectors are defined <br>
     * worldAnchorOnBody1(-10, 15) , worldAnchorOnBody2(10, 15) ,worldAnchorGround1(-10, 20) ,worldAnchorGround2(10, 20) <br>
     * Ratio is Defined to be 1 <br>
     * intialise myjoint with box1,box2 and all 4 2D vectors <br>
     */
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-10,15);
      bd->fixedRotation = true;

      //The open box
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.5;
      fd1->restitution = 0.f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(2,0.2, b2Vec2(0.f,-1.9f), 0);
      fd1->shape = &bs1;
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.5;
      fd2->restitution = 0.f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.2,2, b2Vec2(2.0f,0.f), 0);
      fd2->shape = &bs2;
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 10.0;
      fd3->friction = 0.5;
      fd3->restitution = 0.f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape bs3;
      bs3.SetAsBox(0.2,2, b2Vec2(-2.0f,0.f), 0);
      fd3->shape = &bs3;

      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);
      box1->CreateFixture(fd2);
      box1->CreateFixture(fd3);

      //The bar
      bd->position.Set(10,15);
      fd1->density = 34.0;
      b2Body* box2 = m_world->CreateBody(bd);
      box2->CreateFixture(fd1);

      // The pulley joint
      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody1(-10, 15); // Anchor point on body 1 in world axis
      b2Vec2 worldAnchorOnBody2(10, 15); // Anchor point on body 2 in world axis
      b2Vec2 worldAnchorGround1(-10, 20); // Anchor point for ground 1 in world axis
      b2Vec2 worldAnchorGround2(10, 20); // Anchor point for ground 2 in world axis
      float32 ratio = 1.0f; // Define ratio
      myjoint->Initialize(box1, box2, worldAnchorGround1, worldAnchorGround2, box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);
    }

    //The revolving horizontal platform
    /*! \par Revolving Horizontal Platform
     * variable shape :: <br>
     * Data Type is b2PolygonShape <br>
     * length : 2.2 , width : 0.2 <br>
     * variable bd :: <br>
     * Data Type is b2BodyDef <br>
     * Position is (14,16) <br>
     * Type is dynamic <br>
     * variable fd :: <br>
     * density : 1 <br>
     * variable bd2 :: <br>
     * Data Type is b2BodyDef <br>
     * Position is (14,16) <br><br>
     * variable jointDef; <br>
     * Data Type is b2RevoluteJointDef <br>
     * It is used to connect two bodies from each other <br>
     * collideConnected is set to be false so that there is no collision between them <br>
     * variable ground :: <br>
     * Data Type is b2Body* <br>
     */
    {
      b2PolygonShape shape;
      shape.SetAsBox(2.2f, 0.2f);

      b2BodyDef bd;
      bd.position.Set(14.0f, 16.0f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 1.f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      body->CreateFixture(fd);
      b2BodyDef bd2;
      bd2.position.Set(14.0f, 16.0f);
      b2Body* body2 = m_world->CreateBody(&bd2);

      b2RevoluteJointDef jointDef;
      jointDef.bodyA = body;
      jointDef.bodyB = body2;
      jointDef.localAnchorA.Set(0,0);
      jointDef.localAnchorB.Set(0,0);
      jointDef.collideConnected = false;
      m_world->CreateJoint(&jointDef);
    }

    //The heavy sphere on the platform
    /*! \par The Heavy Sphere on the Platform
     * variable circle :: <br>
     * Data Type is b2CircleShape <br>
     * radius : 1 <br>
     * variable ballfd :: <br>
     * Data Type is b2FixtureDef <br>
     * Density : 40 , Friction : 0.0 , Restitution : 0.0 <br>
     * variable ballbd :: <br>
     * Data Type is b2BodyDef <br>
     * Type is set to be Dynamic <br>
     * Position is (14,18) <br>
     * variable sbody :: <br>
     * Data Type is b2Body* <br>
     */
    {
      b2Body* sbody;
      b2CircleShape circle;
      circle.m_radius = 1.0;

      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 40.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(14.0f, 18.0f);
      sbody = m_world->CreateBody(&ballbd);
      sbody->CreateFixture(&ballfd);
    }


    //The see-saw system at the bottom
    /*! \par The See-saw system at the bottom
     *  \par Triangle Wedge
     * variable poly :: <br>
     * Data Type is b2PolygonShape <br>
     * 3 2D vertices are defined (-1,0) (1,0) (0,1.5) <br>
     * variable wedgefd :: <br>
     * Data Type is b2FixtureDef <br>
     * Density : 10 , Friction : 0.0 , Restitution : 0.0 <br>
     * variable wedgebd :: <br>
     * Data Type is b2BodyDef <br>
     * Position is (30,0) <br>
     * variable sbody :: <br>
     * Data Type is b2Body* <br>
     */
    {
      //The triangle wedge
      b2Body* sbody;
      b2PolygonShape poly;
      b2Vec2 vertices[3];
      vertices[0].Set(-1,0);
      vertices[1].Set(1,0);
      vertices[2].Set(0,1.5);
      poly.Set(vertices, 3);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(30.0f, 0.0f);
      sbody = m_world->CreateBody(&wedgebd);
      sbody->CreateFixture(&wedgefd);

      //The plank on top of the wedge
      /*! \par Plank on top of the wedge
     * variable shape :: <br>
     * Data Type is b2PolygonShape <br>
     * length : 20 , width : 0.2 <br>
     * variable bd2 :: <br>
     * Data Type is b2BodyDef <br>
     * Position is (30,1.5) <br>
     * Type of body is Dynamic <br>
     * variable fd2 :: <br>
     * Data Type is b2FixtureDef* <br>
     * Density : 1  <br>
     * variable body :: <br>
     * Data Type is b2Body* <br>
     * variable jd :: <br>
     * Data Type is b2RevoluteJointDef <br>
     * Joint point is set to be (30,1.5) <br>
     */
      b2PolygonShape shape;
      shape.SetAsBox(20.0f, 0.2f);
      b2BodyDef bd2;
      bd2.position.Set(30.0f, 1.5f);
      bd2.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd2);
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 1.f;
      fd2->shape = new b2PolygonShape;
      fd2->shape = &shape;
      body->CreateFixture(fd2);

      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(30.0f, 1.5f);
      jd.Initialize(sbody, body, anchor);
      m_world->CreateJoint(&jd);

      //The light box on the right side of the see-saw
      /*! \par Light box on the right side of the see-saw
     * variable shape2 :: <br>
     * Data Type is b2PolygonShape <br>
     * length : 2 , width : 2 <br>
     * variable bd3 :: <br>
     * Data Type is b2BodyDef <br>
     * Position is (45,2) <br>
     * Type of body is Dynamic <br>
     * variable fd3 :: <br>
     * Data Type is b2FixtureDef* <br>
     * Density : 0.01  <br>
     * variable body3 :: <br>
     * Data Type is b2Body* <br>
     */
      b2PolygonShape shape2;
      shape2.SetAsBox(2.0f, 2.0f);
      b2BodyDef bd3;
      bd3.position.Set(45.0f, 2.0f);
      bd3.type = b2_dynamicBody;
      b2Body* body3 = m_world->CreateBody(&bd3);
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 0.01f;
      fd3->shape = new b2PolygonShape;
      fd3->shape = &shape2;
      body3->CreateFixture(fd3);
    }

      //New Things added
      /*! \par New Objects added for assignment <br>
     * \par Slant wedge
     * variable bdoo :: <br>
     * Data Type is b2BodyDef <br>
     * Position is (19,11) <br>
     * variable fd1 :: <br>
     * Data Type is b2FixtureDef* <br>
     * Density : 10 , friction : 0 , restitution : 0 <br>
     * variable :: bs1 <br>
     * Data Type is b2PolygonShape <br>
     * length : 2 , width : 0.2 , position is set to be (1,0) according to the position of body , Angle 0 <br> <br>
     * variable fd2 :: <br>
     * Data Type is b2FixtureDef* <br>
     * Density : 10 , friction : 0 , restitution : 0 <br>
     * variable :: bs2 <br>
     * Data Type is b2PolygonShape <br>
     * length : 2 , width : 0.2 , position is set to be (-2.5,1.5) according to the position of body , Angle is 2.5 <br>
     * variable box1 :: <br>
     * Data Type is b2Body* <br>
     */
	{
      b2BodyDef bdoo;
      bdoo.position.Set(19,11);
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.0;
      fd1->restitution = 0.f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(2,0.2, b2Vec2(1.0,0.0), 0);
      fd1->shape = &bs1;
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.0;
      fd2->restitution = 0.f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(2,0.2, b2Vec2(-2.5f,1.5f), 2.5);
      fd2->shape = &bs2;

      b2Body* box1 = m_world->CreateBody(&bdoo);
      box1->CreateFixture(fd1);
      box1->CreateFixture(fd2);
    }

    //Another pendulum
    /*! \par Second Pendulum  <br>
     * \par Attaching Floor
     * variable :: shape <br>
     * Data Type is b2PolygonShape <br>
     * length : 1.5 , width : 0.25 <br>
     * variable bd :: <br>
     * Data Type is b2BodyDef <br>
     * Position is (25,26) <br>
     * variable b2 :: <br>
     * Data Type is b2Body* <br>
     * density : 10 <br>
     * \par Bob of Pendulum
     * variable :: shape <br>
     * Data Type is b2CircleShape <br>
     * radius : 1 <br>
     * variable bd :: <br>
     * Data Type is b2BodyDef <br>
     * Position is (25,12) <br>
     * variable b2 :: <br>
     * Data Type is b2Body* <br>
     * density : 0.01 <br><br>
     * variable jd :: <br>
     * Data Type is b2RevoluteJointDef <br>
     * Joint is set to be at (25,26) <br>
     * Pendulum is used for controlling the speed of ball of revolving plateform <br>     
     */
    {
	// Floor
      b2Body* b2;
      {
	b2PolygonShape shape;
	shape.SetAsBox(1.5f, 0.25f);

	b2BodyDef bd;
	bd.position.Set(25.0f, 26.0f);
	b2 = m_world->CreateBody(&bd);
	b2->CreateFixture(&shape, 10.0f);
      }
      
      //Bob
      b2Body* b4;
      {
	b2CircleShape shape;
	shape.m_radius = 1.0;

	b2BodyDef bd;
	bd.type = b2_dynamicBody;
	bd.position.Set(25.0f, 12.0f);
	b4 = m_world->CreateBody(&bd);
	b4->CreateFixture(&shape, 0.01f);
      }

      b2RevoluteJointDef jd;
      b2Vec2 anchor;
      anchor.Set(25.0f, 26.0f);
      jd.Initialize(b2, b4, anchor);
      m_world->CreateJoint(&jd);
    }

	//vertical wall
	/*! \par Vertical Wall
     * variable bdoo :: <br>
     * Data Type is b2BodyDef <br>
     * Position is (29,7) <br>
     * variable fd2 :: <br>
     * Data Type is b2FixtureDef* <br>
     * Density : 10 , friction : 0 , restitution : 0.55 <br>
     * variable :: bs2 <br>
     * Data Type is b2PolygonShape <br>
     * length : 3 , width : 0.2 , position is set to be (0,2.5) according to the position of body , Angle 1.57 radians <br> <br>
     * variable box1 :: <br>
     * Data Type is b2Body* <br>
     */
	
    {
      b2BodyDef bdoo;
      bdoo.position.Set(29,7);

      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.0;
      fd2->restitution = 0.55;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(3,0.2, b2Vec2(0.0f,2.5f), 1.57);
      fd2->shape = &bs2;

      b2Body* box1 = m_world->CreateBody(&bdoo);
      box1->CreateFixture(fd2);
    }

    // Small ball near light box
    /*! \par Small ball near light box
     * variable :: shape <br>
     * Data Type is b2CircleShape <br>
     * radius : 0.2 <br>
     * variable bd :: <br>
     * Data Type is b2BodyDef <br>
     * Type is set to be Dynamic <br>
     * Position is (37,2) <br>
     * variable b4 :: <br>
     * Data Type is b2Body* <br>
     * density : 0.1 <br><br>
     */
	b2Body* b4;
    {
		b2CircleShape shape;
		shape.m_radius = 0.2f;

		b2BodyDef bd;
		bd.type = b2_dynamicBody;
		bd.position.Set(37.0f, 2.0f);
		b4 = m_world->CreateBody(&bd);
		b4->CreateFixture(&shape, 0.1f);
     }

     // Ball upon the bar of Pulley
     /*! \par Ball upon the bar of Pulley
     * variable :: shape <br>
     * Data Type is b2CircleShape <br>
     * radius : 1 <br>
     * variable bd :: <br>
     * Data Type is b2BodyDef <br>
     * Type is set to be Dynamic <br>
     * Position is (10,15) <br>
     * variable b5 :: <br>
     * Data Type is b2Body* <br>
     * density : 0.01 <br><br>
     */
     b2Body* b5;
    {
		b2CircleShape shape;
		shape.m_radius = 1.0f;

		b2BodyDef bd;
		bd.type = b2_dynamicBody;
		bd.position.Set(10.0f, 15.0f);
		b5 = m_world->CreateBody(&bd);
		b5->CreateFixture(&shape, 0.01f);
     }

     //Stopper
     /*! \par Vertical Wall
     * variable bdoo :: <br>
     * Data Type is b2BodyDef <br>
     * Position is (2.7,10.785) <br>
     * variable fd2 :: <br>
     * Data Type is b2FixtureDef* <br>
     * Density : 10 , friction : 0 , restitution : 0.55 <br>
     * variable :: bs2 <br>
     * Data Type is b2PolygonShape <br>
     * length : 2 , width : 0.2 , position is set to be (0,2.5) according to the position of body , Angle 1.57 radians <br> <br>
     * variable box1 :: <br>
     * Data Type is b2Body* <br>
     */
    {
      b2BodyDef bdoo;
      bdoo.position.Set(2.7,10.785);

      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.0;
      fd2->restitution = 0.55;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(2,0.2, b2Vec2(0.0f,2.5f), 1.57);
      fd2->shape = &bs2;

      b2Body* box1 = m_world->CreateBody(&bdoo);
      box1->CreateFixture(fd2);
    }

     //Rotational Horizontal plank
     /*! \par Rotational Horizontal plank
     * variable bdoo :: <br>
     * Data Type is b2BodyDef <br>
     * Position is (0,15.5) <br>
     * variable fd2 :: <br>
     * Data Type is b2FixtureDef* <br>
     * Density : 0.1 , friction : 0 , restitution : 0 <br>
     * variable :: bs2 <br>
     * Data Type is b2PolygonShape <br>
     * length : 0.2 , width : 3 , position is set to be (0,0) according to the position of body , Angle 1.57 radians <br> <br>
     * variable box1 :: <br>
     * Data Type is b2Body* <br>
     * variable bd2 :: <br>
     * Data Type is b2BodyDef <br>
     * Position is (0,15.5) <br>
     * variable box2 :: <br>
     * Data Type is b2Body* <br>
     * variable jointDef; <br>
     * Data Type is b2RevoluteJointDef <br>
     * It is used to connect two bodies from each other <br>
     * collideConnected is set to be false so that there is no collision between them <br>
     */
    {
      b2BodyDef bdoo;
      bdoo.position.Set(0,15.5);
      bdoo.type = b2_dynamicBody;

      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 0.1;
      fd2->friction = 0.0;
      fd2->restitution = 0.0;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.2,3, b2Vec2(0.0f,0.0f), 1.57);
      fd2->shape = &bs2;

      b2Body* box1 = m_world->CreateBody(&bdoo);
      box1->CreateFixture(fd2);

      b2BodyDef bd2;
      bd2.position.Set(0.0f, 15.5f);
      b2Body* box2 = m_world->CreateBody(&bd2);

      b2RevoluteJointDef jointDef;
      jointDef.bodyA = box1;
      jointDef.bodyB = box2;
      jointDef.localAnchorA.Set(0,0);
      jointDef.localAnchorB.Set(0,0);
      jointDef.collideConnected = false;
      m_world->CreateJoint(&jointDef);
    }
    
    /*! \par Ball upon Stopper
     * variable :: shape <br>
     * Data Type is b2CircleShape <br>
     * radius : 1 <br>
     * variable bd :: <br>
     * Data Type is b2BodyDef <br>
     * Type is set to be Dynamic <br>
     * Position is (2,17.5) <br>
     * variable b9 :: <br>
     * Data Type is b2Body* <br>
     * density : 0.01 <br><br>
     */
     
    b2Body* b9;
    {
		b2CircleShape shape;
		shape.m_radius = 1.0f;

		b2BodyDef bd;
		bd.type = b2_dynamicBody;
		bd.position.Set(2.0f, 17.5f);
		b9 = m_world->CreateBody(&bd);
		b9->CreateFixture(&shape, 0.01f);
     }
  }
Пример #11
0
     /**  The is the constructor \n
     * This is the documentation block for the constructor.
     */ 
     dominos_t::dominos_t()
     {


         {	  

        /// \par GROUND
        /*! Variable - b1 \n
         *  is a pointer to the base ground
         *  \n Data type - b2Body*
         */
         b2Body* b1;

        /*! Variable - shape
         *  \n \brief defines a shape that can be assigned to a body
         *  \n Data type - b2EdgeShape
         */

         {
        /*! b2EdgeShape shape is assigned to the b1 pointer
         */
            b2EdgeShape shape; 
            shape.Set(b2Vec2(-90.0f, 0.0f), b2Vec2(90.0f, 0.0f));
            b2BodyDef bd; 
            b1 = m_world->CreateBody(&bd); 
            b1->CreateFixture(&shape, 0.0f);
        }

    }

    {

			      /*! Variable -  bd
             *  \n \brief A body definition of a pulley wheel
             *  \n Data type -  b2FixtureDef*
             *  \n Values - fixed rotation
             */
             b2BodyDef *bd = new b2BodyDef;
             bd->type = b2_dynamicBody;
             bd->position.Set(0,30);
             bd->fixedRotation = true;

            /*! Variable -  fd1
             *  \n \brief The bar that is attached to the pulleys , size=2*0.2
             *  \n Data type -  b2FixtureDef*
             *  \n Values - density = 20f, friction = 0.5f, restitution = 0f
             */
             b2FixtureDef *fd1 = new b2FixtureDef;
             fd1->friction = 0.0f;
             fd1->restitution = 0.f;
             fd1->shape = new b2PolygonShape;

            /*! Variable -  bs1
             *  \n \brief The shape and position of the bar 
             *  \n Data type -  b2PolygonShape
             */
             b2PolygonShape bs1;
             bs1.SetAsBox(7,5, b2Vec2(0.f,0.f), 0);
             fd1->shape = &bs1;

            //The bar1
             bd->position.Set(0,25);
             fd1->density =  0.1;
             fd1->filter.groupIndex = -1;

            /*! Variable -  box1
             * \n \brief The bar at one end of the system , size=4*0.4
             * \n Data type -  b2Body*
             * \n Values - side fd1
             */
             box1 = m_world->CreateBody(bd);
             box1->CreateFixture(fd1);
             fd1->filter.groupIndex = 0;


             {
               b2BodyDef centerCircleDef;
               centerCircleDef.type = b2_dynamicBody;
               centerCircleDef.position.Set(0,32);
               b2Body* centreCircle = m_world->CreateBody(&centerCircleDef);

               b2CircleShape circleShape;
               circleShape.m_p.Set(0, 0); 
               circleShape.m_radius = 1.5f; 

               b2FixtureDef centerCircleFixtureDef;
               centerCircleFixtureDef.shape = &circleShape;
               centerCircleFixtureDef.density = 1.0f;
               centerCircleFixtureDef.filter.groupIndex = -1;
               centreCircle->CreateFixture(&centerCircleFixtureDef);

               b2BodyDef rectBodyDef1;
               rectBodyDef1.type = b2_dynamicBody;
               rectBodyDef1.position.Set(1,31);
               doorRect1 = m_world->CreateBody(&rectBodyDef1);

               b2PolygonShape rectShape1;
               rectShape1.SetAsBox(0.2,1,b2Vec2(0,0), 0);

               b2FixtureDef rectFixtureDef;
               rectFixtureDef.shape = &rectShape1;
               rectFixtureDef.density = 0.1f;
               rectFixtureDef.filter.groupIndex = -1;
               doorRect1->CreateFixture(&rectFixtureDef);

               b2RevoluteJointDef rodJointDef1;
               rodJointDef1.bodyA = centreCircle;
               rodJointDef1.bodyB = doorRect1;
               rodJointDef1.collideConnected = false;

               rodJointDef1.localAnchorA.Set(1,0);
               rodJointDef1.localAnchorB.Set(0,1);
               m_world->CreateJoint(&rodJointDef1);

               b2RevoluteJointDef circleToWorldJointDef;
               circleToWorldJointDef.bodyA = centreCircle;
               circleToWorldJointDef.bodyB = box1;
               circleToWorldJointDef.collideConnected = false;
               circleToWorldJointDef.enableMotor = true;
               circleToWorldJointDef.maxMotorTorque = 1000;
               circleToWorldJointDef.motorSpeed = 0;

               circleToWorldJointDef.localAnchorA.Set(0,0);
               circleToWorldJointDef.localAnchorB.Set(0,7);
               circleToWorldJoint = (b2RevoluteJoint *)m_world->CreateJoint(&circleToWorldJointDef);

               {
        // b2BodyDef rectBodyDef3;
        // rectBodyDef3.type = b2_dynamicBody;
        // rectBodyDef3.position.Set(-2.5,25.5);
        // b2Body* doorRect3 = m_world->CreateBody(&rectBodyDef3);

                b2PolygonShape rectShape3;
                rectShape3.SetAsBox(2.5,0.2,b2Vec2(-2.5,-1), 0);

                b2FixtureDef rectFixtureDef3;
                rectFixtureDef3.shape = &rectShape3;
                rectFixtureDef3.filter.groupIndex = -1;
                doorRect1->CreateFixture(&rectFixtureDef3);


        // b2WeldJointDef rodJointDef3;
        // rodJointDef3.bodyA = doorRect1;
        // rodJointDef3.bodyB = doorRect3;
        // rodJointDef3.collideConnected = false;

        // rodJointDef3.localAnchorA.Set(0,-2.5);
        // rodJointDef3.localAnchorB.Set(5,0);
        // m_world->CreateJoint(&rodJointDef3);
            }

            {
                b2BodyDef doorMainRodDef;
                doorMainRodDef.type = b2_dynamicBody;
                doorMainRodDef.position.Set(-4,29.5);
                b2Body *doorMainRod = m_world->CreateBody(&doorMainRodDef);

                b2PolygonShape doorMainRodShape;
                doorMainRodShape.SetAsBox(0.3,2.5,b2Vec2(0,0),0);

                b2FixtureDef doorMainRodFixtureDef;
                doorMainRodFixtureDef.shape = &doorMainRodShape;
                doorMainRodFixtureDef.density = 0.1f;
                doorMainRodFixtureDef.filter.groupIndex = -1;
                doorMainRod->CreateFixture(&doorMainRodFixtureDef);

                b2RevoluteJointDef rodToWorldJointDef;
                rodToWorldJointDef.bodyA = box1;
                rodToWorldJointDef.bodyB = doorMainRod;
                rodToWorldJointDef.collideConnected = false;

                rodToWorldJointDef.localAnchorA.Set(-4,7);
                rodToWorldJointDef.localAnchorB.Set(0,2.5);
                m_world->CreateJoint(&rodToWorldJointDef);

                b2RevoluteJointDef rodToRodJointDef;
                rodToRodJointDef.bodyA = doorRect1;
                rodToRodJointDef.bodyB = doorMainRod;
                rodToRodJointDef.collideConnected = false;

                rodToRodJointDef.localAnchorA.Set(-3.5,-1);
                rodToRodJointDef.localAnchorB.Set(0,0);
                m_world->CreateJoint(&rodToRodJointDef);


                b2BodyDef doorBodyDef;
                doorBodyDef.type = b2_dynamicBody;
                doorBodyDef.position.Set(2,24);
                b2Body *doorBody = m_world->CreateBody(&doorBodyDef);

                b2PolygonShape doorBodyShape;
                doorBodyShape.SetAsBox(2,4,b2Vec2(0,0),0);

                b2FixtureDef doorBodyFixtureDef;
                doorBodyFixtureDef.shape = &doorBodyShape;
                doorBodyFixtureDef.density = 0.1f;
                doorBodyFixtureDef.filter.groupIndex = -1;
                doorBody->CreateFixture(&doorBodyFixtureDef);

                b2BodyDef doorBodyDef2;
                doorBodyDef2.type = b2_dynamicBody;
                doorBodyDef2.position.Set(1.6,24);
                b2Body *doorBody2 = m_world->CreateBody(&doorBodyDef2);
                doorBodyShape.SetAsBox(1.6,4,b2Vec2(0,0),0);
                doorBodyFixtureDef.shape = &doorBodyShape;
                doorBody2->CreateFixture(&doorBodyFixtureDef);

                b2WeldJointDef * wj = new b2WeldJointDef;
                wj->Initialize(box1,doorBody2,box1->GetWorldCenter());
                m_world->CreateJoint(wj);

                b2PrismaticJointDef doorToBoxJoint;
                doorToBoxJoint.bodyA = box1;
                doorToBoxJoint.bodyB = doorBody;
                doorToBoxJoint.localAxisA = b2Vec2(1,0);
                doorToBoxJoint.collideConnected = false;

                doorToBoxJoint.localAnchorA.Set(0,-5);
                doorToBoxJoint.localAnchorB.Set(0,-4);
                m_world->CreateJoint(&doorToBoxJoint);

                b2WheelJointDef mainRodToDoorJoint;
                mainRodToDoorJoint.Initialize(doorBody, doorMainRod, doorMainRod->GetPosition()+b2Vec2(0,-2), b2Vec2(0,1));
                mainRodToDoorJoint.localAnchorA.Set(-2,0);
                m_world->CreateJoint(&mainRodToDoorJoint);

                doorMainRod->SetTransform(b2Vec2(-4+3.5/2,32-3.5/2), 3.14/4);


            }


        }

        {
            /// \par 1.SHELF
            /*! Creates a shelf \n
             *  b2EdgeShape shape is modified and assigned to ground
             */
             b2PolygonShape shape;
             shape.SetAsBox(0.5f, 10.f);

             b2BodyDef bd1;
             bd1.position.Set(7.5f, 10.0f);

             b2FixtureDef *fd2 = new b2FixtureDef;
             fd2->density = 5.0;
             fd2->friction = 0.0f;
             fd2->restitution = 0.f;
             fd2->shape = &shape;

            /*! Variable -  ground
             *  \n \brief A ground line , size=12.0*0.5
             *  \n Data type - b2EdgeShape
             */
             b2Body* ground1 = m_world->CreateBody(&bd1);
             ground1->CreateFixture(fd2);

             b2BodyDef bd2;
             bd2.position.Set(7.5f, 38.0f);

            /*! Variable -  ground
             *  \n \brief A ground line , size=12.0*0.5
             *  \n Data type - b2EdgeShape
             */
             b2Body* ground2 = m_world->CreateBody(&bd2);
             ground2->CreateFixture(fd2);

             b2BodyDef bd3;
             bd3.position.Set(-7.5f, 10.0f);
            /*! Variable -  ground
             *  \n \brief A ground line for the horizontal shelf , size=14.0*0.5
             *  \n Data type - b2EdgeShape
             */
             b2Body* ground3 = m_world->CreateBody(&bd3);
             ground3->CreateFixture(fd2);

             b2BodyDef bd4;
             bd4.position.Set(-7.5f, 38.0f);
            /*! Variable -  ground
             *  \n \brief A ground line , size=12.0*0.5
             *  \n Data type - b2EdgeShape
             */
             b2Body* ground4 = m_world->CreateBody(&bd4);
             ground4->CreateFixture(fd2);

            b2PrismaticJointDef* prismaticJointDef = new b2PrismaticJointDef;
            prismaticJointDef->bodyB = ground3;
            prismaticJointDef->bodyA = box1;
            prismaticJointDef->collideConnected = false;
            prismaticJointDef->localAxisA.Set(0,1);
            prismaticJointDef->localAnchorB.Set( 0.5,6);//a little outside the bottom right corner
            prismaticJointDef->localAnchorA.Set(-7,-5);//bottom left corner
  		      prismaticJointDef->enableMotor = false;//5 units per second in positive axis direction
            prismaticJointDef->maxMotorForce = 100000.;
            prismaticJointDef->motorSpeed = 5.;
            prismaticJointDef->enableLimit = true;
            prismaticJointDef->lowerTranslation = -20;
            prismaticJointDef->upperTranslation = 30;
            prismaticJoint =  (b2PrismaticJoint*)m_world->CreateJoint(prismaticJointDef);
            prismaticJointDef->bodyA = ground4;
            prismaticJointDef->bodyB = box1;
            prismaticJointDef->collideConnected = false;
            prismaticJointDef->localAxisA.Set(0,1);
            prismaticJointDef->localAnchorA.Set( 0.5,-6);//a little outside the bottom right corner
            prismaticJointDef->localAnchorB.Set(-7,5);//bottom left corner
            prismaticJointDef->enableMotor = false;//5 units per second in positive axis direction       
            m_world->CreateJoint(prismaticJointDef);

            b2PrismaticJointDef* prismaticJointDef2 = new b2PrismaticJointDef;
            prismaticJointDef2->bodyA = ground1;
            prismaticJointDef2->bodyB = box1;
            prismaticJointDef2->collideConnected = false;
            prismaticJointDef2->localAxisA.Set(0,1);
            prismaticJointDef2->localAnchorA.Set(-0.5,6);//a little outside the bottom right corner
            prismaticJointDef2->localAnchorB.Set(7,-5);//bottom left corner
  	        //prismaticJointDef2->enableMotor = true;//5 units per second in positive axis direction
            //prismaticJointDef2->maxMotorForce = 1000;
            //prismaticJointDef2->motorSpeed = -5;
            m_world->CreateJoint(prismaticJointDef2);
            prismaticJointDef2->bodyA = ground2;
            prismaticJointDef2->bodyB = box1;
            prismaticJointDef2->collideConnected = false;
            prismaticJointDef2->localAxisA.Set(0,1);
            prismaticJointDef2->localAnchorA.Set( -0.5,-6);//a little outside the bottom right corner
            prismaticJointDef2->localAnchorB.Set(7,5);//bottom left corner
            prismaticJointDef2->enableMotor = false;//5 units per second in positive axis direction       
            m_world->CreateJoint(prismaticJointDef2);

        }


        {
          /// \par 2. PULLEY
          /*! Creates the second, new pulley system \n
           * The box on the see-saw is caught by a bar on one end of the pulley \n
           * The bar on the other end catces a revolving platform
           */


            /*! Variable -  bs2
             *  \n \brief The shape and position of the bar
             *  \n Data type -  b2PolygonShape
             */
             b2PolygonShape bs2;
             bs2.SetAsBox(3.5,7, b2Vec2(0.f,-1.9f), 0);
             fd1->shape = &bs2;

            //The bar2
             bd->position.Set(-30,10);
             fd1->density = 25.0f;

            /*! Variable -  box2
             * \n \brief The bar at the other end of the system , siz=4*0.4
             * \n Data type -  b2Body*
             * \n Values - side fd1
             */
             box2 = m_world->CreateBody(bd);
             box2->CreateFixture(fd1);


            /*! Variable -  bs3
             *  \n \brief The shape and position of the bar
             *  \n Data type -  b2PolygonShape
             */
             b2PolygonShape bs3;
             bs3.SetAsBox(0.5,3, b2Vec2(0.f,0.f), 0);
             fd1->shape = &bs3;

            //The bar3
             bd->position.Set(6,32);
             bd->fixedRotation = false;
             fd1->density = 1.0;
            /*! Variable -  box3
             * \n \brief The bar at the other end of the system , siz=4*0.4
             * \n Data type -  b2Body*
             * \n Values - side fd1
             */
             b2Body* box3 = m_world->CreateBody(bd);
             box3->CreateFixture(fd1);
	          //  m_world->registerPhysicsConnector(new PhysicsConnector(box1, box3, true, true));        


            /*! Variable -  bs4
             *  \n \brief The shape and position of the bar
             *  \n Data type -  b2PolygonShape
             */

            //The bar4
             bd->position.Set(-6,32);
             bd->fixedRotation = false;
             fd1->density = 1.0;
            /*! Variable -  box4
             * \n \brief The bar at the other end of the system , siz=4*0.4
             * \n Data type -  b2Body*
             * \n Values - side fd1
             */
             b2Body* box4 = m_world->CreateBody(bd);
             box4->CreateFixture(fd1);
            //  m_world->registerPhysicsConnector(new PhysicsConnector(box1, box3, true, true));  


             b2RevoluteJointDef *revoluteJointDef = new b2RevoluteJointDef;
             revoluteJointDef->bodyA = box1;
             revoluteJointDef->bodyB = box3;
             revoluteJointDef->collideConnected = false;
             b2Vec2 worldAnchorOnBody3(6, 5);
             revoluteJointDef->localAnchorA.Set(6,5);
             revoluteJointDef->localAnchorB.Set(0,-2 );
             revoluteJointDef->referenceAngle = 0;
             revoluteJointDef->enableMotor = true;
             revoluteJointDef->maxMotorTorque = 800;
             revoluteJointDef->motorSpeed = -5*3.14;
             revoluteJointDef->enableLimit = true;
             revoluteJointDef->lowerAngle = -3.14/4 ;
     	      //revoluteJointDef->upperAngle =  3.14/2 ;
            //revoluteJointDef->Initialize(box1, box3, box1->GetWorldCenter()+worldAnchorOnBody3);    
             m_world->CreateJoint(revoluteJointDef);

             b2RevoluteJointDef *revoluteJointDef2 = new b2RevoluteJointDef;
             revoluteJointDef2->bodyA = box1;
             revoluteJointDef2->bodyB = box4;
             revoluteJointDef2->collideConnected = false;
             b2Vec2 worldAnchorOnBody4(-6, 5);
             revoluteJointDef2->localAnchorA.Set(-6,5);
             revoluteJointDef2->localAnchorB.Set(0,-2);
             revoluteJointDef2->referenceAngle = 0;
             revoluteJointDef2->enableMotor = true;
             revoluteJointDef2->maxMotorTorque = 800;
             revoluteJointDef2->motorSpeed = 5*3.14;
             revoluteJointDef2->enableLimit = true;
            //revoluteJointDef2->lowerAngle = -3.14/4 ;
             revoluteJointDef2->upperAngle =  3.14/4 ;
            //revoluteJointDef2->Initialize(box1, box4, box1->GetWorldCenter()+worldAnchorOnBody4);    
             m_world->CreateJoint(revoluteJointDef2);

            // The pulley joint
            /*! Variable -  myjoint
             * \n \brief The pulley joint with two anchors
             * \n Data type -   b2PulleyJointDef*
             * \n Values - anchors = twoanchors on bodies worldAnchorOnBody1 and worldAnchorOnBody2, \n
             *                      two anchors on ground worldAnchorGround1 and worldAnchorGround2, ratio
             */
            b2PulleyJointDef* myjoint = new b2PulleyJointDef();
            b2Vec2 worldAnchorOnBody1(0, 3); // Anchor point on body 1 in world axis
            b2Vec2 worldAnchorOnBody2(-30, 40); // Anchor point on body 2 in world axis
            b2Vec2 worldAnchorGround1(0, 42); // Anchor point for ground 1 in world axis
            b2Vec2 worldAnchorGround2(-30, 42); // Anchor point for ground 2 in world axis
            float32 ratio = 1.0f; // Define ratio
            /*! The pulley joint myjoint is initialised with all the input values - box1, box2, ratio, anchors
             */
            myjoint->Initialize(box3, box2, worldAnchorGround1, worldAnchorGround2, box3->GetWorldCenter()+worldAnchorOnBody1, box2->GetWorldCenter(), ratio);
            m_world->CreateJoint(myjoint);

            b2PulleyJointDef* myjoint2 = new b2PulleyJointDef();
            /*! The pulley joint myjoint is initialised with all the input values - box1, box2, ratio, anchors
             */
            myjoint2->Initialize(box4, box2, worldAnchorGround1, worldAnchorGround2, box4->GetWorldCenter()+worldAnchorOnBody1, box2->GetWorldCenter(), ratio);
            m_world->CreateJoint(myjoint2);

        }

    }

}  
Пример #12
0
  dominos_t::dominos_t()
  {
    //Ground  
    {      
      b2Body* b1;
      b2EdgeShape shape; 
      shape.Set(b2Vec2(-900.0f, -5.0f), b2Vec2(900.0f, -5.0f));
      b2BodyDef bd;
      b1 = m_world->CreateBody(&bd); 
      b1->CreateFixture(&shape, 0.0f);
    }
    
    /////////////////////////////////////////////

    //first ball
    {
      b2CircleShape circle;
      circle.m_radius = 0.6;
  
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 60.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(-39.5f, 45.0f);
      b2Body* body;
      body = m_world->CreateBody(&ballbd);
      body->CreateFixture(&ballfd);
    }

    /////////////////////////////////////////////

    //slant planks
    {
      b2Body* body;
      b2PolygonShape poly;
      b2Vec2 vertices[4];
      vertices[0].Set(0,0);
      vertices[1].Set(7.5,-2.5);
      vertices[2].Set(7.4,-2.8);
      vertices[3].Set(-0.1,-0.3);
      poly.Set(vertices, 4);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(-42.2f, 42.5f);
      body = m_world->CreateBody(&wedgebd);
      body->CreateFixture(&wedgefd);
    }

    {
      b2Body* body;
      b2PolygonShape poly;
      b2Vec2 vertices[4];
      vertices[0].Set(0,0);
      vertices[1].Set(7.5,-2.5);
      vertices[2].Set(7.4,-2.8);
      vertices[3].Set(-0.1,-0.3);
      poly.Set(vertices, 4);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(-42.5f, 37.5f);
      body = m_world->CreateBody(&wedgebd);
      body->CreateFixture(&wedgefd);
    }

    {
      b2Body* body;
      b2PolygonShape poly;
      b2Vec2 vertices[4];
      vertices[0].Set(0,0);
      vertices[1].Set(7.5,2.5);
      vertices[2].Set(7.4,2.8);
      vertices[3].Set(-0.1,0.3);
      poly.Set(vertices, 4);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(-35.5f,37.5f);
      body = m_world->CreateBody(&wedgebd);
      body->CreateFixture(&wedgefd);
    }

    //////////////////////////////////////////////

    //plank-spring mass system
    {
      b2Body* body;
      b2PolygonShape poly;
      b2Vec2 vertices[4];
      vertices[0].Set(0,0);
      vertices[1].Set(24,0);
      vertices[2].Set(24,0.25);
      vertices[3].Set(0,0.25);
      poly.Set(vertices, 4);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction =0.05f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(-33.0f, 32.5f);
      body = m_world->CreateBody(&wedgebd);
      body->CreateFixture(&wedgefd);
    }

    ////////////////////////////////////////////////     

    {
      b2Body* body;
      b2PolygonShape poly;
      b2Vec2 vertices[4];
      vertices[0].Set(0,0);
      vertices[1].Set(0.75,0);
      vertices[2].Set(0.75,0.75);
      vertices[3].Set(0,0.75);
      poly.Set(vertices, 4);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(-33.0f, 32.7f);
      body = m_world->CreateBody(&wedgebd);
      body->CreateFixture(&wedgefd);
    }

    //////////////////////////////////////////////////////////

    {
      b2Body* body;
      b2PolygonShape poly;
      b2Vec2 vertices[4];
      vertices[0].Set(0,0);
      vertices[1].Set(0.75,0);
      vertices[2].Set(0.75,0.75);
      vertices[3].Set(0,0.75);
      poly.Set(vertices, 4);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = 0.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(-31.0f, 32.7f);
      body = m_world->CreateBody(&wedgebd);
      body->CreateFixture(&wedgefd);
    }


    //////////////////////////////////////////////////////////

    //http://www.emanueleferonato.com/2009/01/05/box2d-joints-distance-joint/
    //http://www.learn-cocos2d.com/api-ref/1.0/Box2D/html/classb2_distance_joint.html

    //spring mass system 
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-28.5,33.5);

      b2Body* body10;

      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.0f;
      fd1->restitution = -1000.0f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(0.75,0.62, b2Vec2(-2.25,0.38), 0);
      fd1->shape = &bs1;
      
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.051f;
      fd2->restitution = -1000.0f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(1.5,1, b2Vec2(0.0f,0.0f), 0);
      fd2->shape = &bs2;
      
      body10 = m_world->CreateBody(bd);
      body10->CreateFixture(fd1);
      body10->CreateFixture(fd2);

      //**********************************************//

      b2BodyDef *bd2 = new b2BodyDef;
      bd2->type = b2_dynamicBody;
      bd2->position.Set(-23.25,33.5);

      b2Body* body11;
      
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 10.0;
      fd3->friction = 0.051f;
      fd3->restitution = -1000.0f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape bs3;
      bs3.SetAsBox(1.5,1, b2Vec2(0.0f,0.0f), 0);
      fd3->shape = &bs3;

      b2FixtureDef *fd4 = new b2FixtureDef;
      fd4->density = 10.0;
      fd4->friction = 0.0f;
      fd4->restitution = 0.0f;
      fd4->shape = new b2PolygonShape;
      b2PolygonShape bs4;
      bs4.SetAsBox(0.75,0.62, b2Vec2(2.25f,0.38f), 0);
      fd4->shape = &bs4;

      body11 = m_world->CreateBody(bd2);
      body11->CreateFixture(fd3);
      body11->CreateFixture(fd4);

      //********************************************//

      b2DistanceJointDef* distance_joint = new b2DistanceJointDef();

      b2Vec2 anchor1;
      anchor1.Set(-28.5, 33.5);
      b2Vec2 anchor2;
      anchor2.Set(-23.25, 33.5);
      
      distance_joint->Initialize(body10,body11,anchor1,anchor2);

      distance_joint->length =5.25f;
      distance_joint->collideConnected = true;
      distance_joint->frequencyHz =1.0f;
      distance_joint->dampingRatio = -0.097f;

      m_world->CreateJoint(distance_joint);

    }

    /////////////////////////////////////////////

    //small stand-second ball
    {
      b2Body* body;
      b2PolygonShape poly;
      b2Vec2 vertices[4];
      vertices[0].Set(0,0);
      vertices[1].Set(0.75,0);
      vertices[2].Set(0.75,0.75);
      vertices[3].Set(0,0.75);
      poly.Set(vertices, 4);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = -1000.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(-12.25f, 32.7f);
      body = m_world->CreateBody(&wedgebd);
      body->CreateFixture(&wedgefd);
    }

    /////////////////////////////////////

    //second ball

    {
      b2CircleShape circle;
      circle.m_radius = 0.6f;
  
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 700.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = -2.0f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(-11.875f,33.675f);
      b2Body* body;
      body = m_world->CreateBody(&ballbd);
      body->CreateFixture(&ballfd);
    }

    ///////////////////////////////////////////////////////////////////

    // revolving plank
    {
      b2PolygonShape shape;
      shape.SetAsBox(3.75f, 0.1f);
  
      b2BodyDef bd;
      bd.position.Set(-6.75f, 30.5f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 500.0f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      body->CreateFixture(fd);

      b2PolygonShape shape2;
      b2BodyDef bd2;
      bd2.position.Set(-6.25f, 30.5f);
      b2Body* body2 = m_world->CreateBody(&bd2);

      b2RevoluteJointDef jointDef;
      jointDef.bodyA = body;
      jointDef.bodyB = body2;
      jointDef.localAnchorA.Set(0,0);
      jointDef.localAnchorB.Set(0,0);
      jointDef.collideConnected = true;
      m_world->CreateJoint(&jointDef);
    }   

    /////////////////////////////////////

    //third ball

    {
      b2CircleShape circle;
      circle.m_radius = 0.8f;
  
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 0.1f;
      ballfd.friction = 0.0f;
      ballfd.restitution = -2.0f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(0.5f,32.7f);
      b2Body* body;
      body = m_world->CreateBody(&ballbd);
      body->CreateFixture(&ballfd);
    }
    ///////////////////////////////////////////////////////////////////

    // revolving plank-2
    {
      b2PolygonShape shape;
      shape.SetAsBox(3.75f, 0.1f);
  
      b2BodyDef bd;
      bd.position.Set(0.5f, 31.8f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 0.1f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      body->CreateFixture(fd);

      b2PolygonShape shape2;
      b2BodyDef bd2;
      bd2.position.Set(0.5f, 31.8f);
      b2Body* body2 = m_world->CreateBody(&bd2);

      b2RevoluteJointDef jointDef;
      jointDef.bodyA = body;
      jointDef.bodyB = body2;
      jointDef.localAnchorA.Set(0,0);
      jointDef.localAnchorB.Set(0,0);
      jointDef.collideConnected = true;
      m_world->CreateJoint(&jointDef);
    }

    ///////////////////////////////////////////////////////////////////////

    // plank-
    {
      b2PolygonShape shape12;
      shape12.SetAsBox(20.0f, 0.2f);
      b2BodyDef bd11;
      bd11.position.Set(21.0f, 30.2f);
      b2Body* body12 = m_world->CreateBody(&bd11);
      b2FixtureDef *fd11 = new b2FixtureDef;
      fd11->friction= 0.0f;
      fd11->density = 10.0f;
      fd11->shape = new b2PolygonShape;
      fd11->shape = &shape12;
      body12->CreateFixture(fd11);

      b2PolygonShape shape1;
      shape1.SetAsBox(2.2f, 0.55f);
      b2BodyDef bd1;
      bd1.position.Set(45.95f, 30.55f);
      b2Body* body1 = m_world->CreateBody(&bd1);
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->friction= 0.0f;
      fd1->density = 10.0f;
      fd1->shape = new b2PolygonShape;
      fd1->shape = &shape1;
      body1->CreateFixture(fd1);

      b2PolygonShape shape2;
      shape2.SetAsBox(16.5f, 0.8f);
      b2BodyDef bd2;
      bd2.type=b2_dynamicBody;
      bd2.position.Set(23.0f, 31.2f);
      b2Body* body2 = m_world->CreateBody(&bd2);
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->friction=0.0f;
      fd2->density = 0.01f;
      fd2->shape = new b2PolygonShape;
      fd2->shape = &shape2;
      body2->CreateFixture(fd2);

      b2PolygonShape shape3;
      shape3.SetAsBox(2.5f, 0.1f);
      b2BodyDef bd3;
      bd3.type=b2_dynamicBody;
      bd3.position.Set(42.4f, 31.2f);
      b2Body* body3 = m_world->CreateBody(&bd3);
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->friction= 0.0f;
      fd3->density = 0.01f;
      fd3->shape = new b2PolygonShape;
      fd3->shape = &shape3;
      body3->CreateFixture(fd3);
    }
    
    ///////////////////////////////////////////////////////////////////////

    // vertical pipes with balls
    {
      b2PolygonShape shape12;
      shape12.SetAsBox(0.2f, 12.0f);
      b2BodyDef bd11;
      bd11.position.Set(41.2f, 19.1f);
      b2Body* body12 = m_world->CreateBody(&bd11);
      b2FixtureDef *fd11 = new b2FixtureDef;
      fd11->friction= 0.0f;
      fd11->density = 10.0f;
      fd11->shape = new b2PolygonShape;
      fd11->shape = &shape12;
      body12->CreateFixture(fd11);

      bd11.position.Set(43.4f,19.1);
      b2Body* body2 = m_world->CreateBody(&bd11);
      body2->CreateFixture(fd11);

      b2PolygonShape shape3;
      shape3.SetAsBox(0.2f, 0.7f);
      fd11->shape = new b2PolygonShape;
      fd11->shape = &shape3;
      bd11.position.Set(48.4f,30.7f);
      b2Body* body3 = m_world->CreateBody(&bd11);
      body3->CreateFixture(fd11);

      b2PolygonShape shape4;
      shape4.SetAsBox(0.2f, 1.7f);
      fd11->shape = new b2PolygonShape;
      fd11->shape = &shape4;
      bd11.position.Set(41.2f,33.1f);
      b2Body* body4 = m_world->CreateBody(&bd11);
      body4->CreateFixture(fd11);

      bd11.position.Set(43.4f,33.1f);
      b2Body* body5 = m_world->CreateBody(&bd11);
      body5->CreateFixture(fd11);

      b2PolygonShape poly6;
      b2Vec2 vertices6[4];
      vertices6[0].Set(0,0);
      vertices6[1].Set(0.4,0);
      vertices6[2].Set(-7.5,7.5);
      vertices6[3].Set(-7.5,7.9);
      poly6.Set(vertices6, 4);
      fd11->shape = &poly6;
      bd11.position.Set(41.0f,34.8f);
      b2Body* body6 = m_world->CreateBody(&bd11);
      body6->CreateFixture(fd11);

      b2PolygonShape poly7;
      b2Vec2 vertices7[4];
      vertices7[0].Set(0,0);
      vertices7[1].Set(0.4,0);
      vertices7[2].Set(7.9,7.5);
      vertices7[3].Set(7.9,7.9);
      poly7.Set(vertices7, 4);
      fd11->shape = &poly7;
      bd11.position.Set(43.2f,34.8f);
      b2Body* body7 = m_world->CreateBody(&bd11);
      body7->CreateFixture(fd11);

      b2CircleShape circle;
      circle.m_radius = 0.15;
      
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 0.001f;
      ballfd.friction = 0.014f;
      ballfd.restitution = 0.0f;

      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      int count=7;

      for(int i=1;i<27;i++)
      {
        for(int j=0;j<count;j++)
        {

          if(i==10||i==15) continue;
          ballbd.position.Set(41.56 + j*0.31 - i*0.31 ,34.96 + i*0.31);
          b2Body* body1;
          body1 = m_world->CreateBody(&ballbd);
          body1->CreateFixture(&ballfd);
        }
        count+=2;
      }
    }

    ///////////////////////////////////////////////////////////////////////

    // plank-dominos
    {
      b2PolygonShape shape12;
      shape12.SetAsBox(12.0f, 0.2f);
      b2BodyDef bd11;
      bd11.position.Set(-21.0f, 28.8f);
      b2Body* body12 = m_world->CreateBody(&bd11);
      b2FixtureDef *fd11 = new b2FixtureDef;
      fd11->friction=100.0f;
      fd11->density = 10.0f;
      fd11->shape = new b2PolygonShape;
      fd11->shape = &shape12;
      body12->CreateFixture(fd11);
    }

    /////////////////////////////////////////////////////////////////////////

    //dominos
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.1f, 1.0f);
  
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 700.0f;
      fd.friction = 0.5f;
      fd.restitution=0.0f;
    
      for (int i = 0; i < 13; ++i)
      {
        b2BodyDef bd;
        bd.type = b2_dynamicBody;
        bd.position.Set(-29.625f + 1.25f * i, 29.5f);
        b2Body* body = m_world->CreateBody(&bd);
        body->CreateFixture(&fd);
      }

      b2FixtureDef fd1;
      fd1.shape = &shape;
      fd1.density = 700.0f;
      fd1.friction = 0.01f;
      fd1.restitution=0.0f;
      b2BodyDef bd1;
      bd1.type = b2_dynamicBody;
      bd1.position.Set(-31.5f , 30.5f);
      b2Body* body = m_world->CreateBody(&bd1);
      body->CreateFixture(&fd1);
    }

    ////////////////////////////////////////////////////////
    
    //plank-brain-dots
    {
      b2PolygonShape shape12;
      shape12.SetAsBox(7.0f, 0.2f);
      b2BodyDef bd11;
      bd11.position.Set(-34.5f, 23.8f);
      //bd11.type = b2_dynamicBody;
      b2Body* body12 = m_world->CreateBody(&bd11);
      b2FixtureDef *fd11 = new b2FixtureDef;
      fd11->friction=100.0f;
      //fd11->restitution=100.0f;
      fd11->density = 10.0f;
      fd11->shape = new b2PolygonShape;
      fd11->shape = &shape12;
      body12->CreateFixture(fd11);
    }

    /////////////////////////////////////////////////////////////

    //v shape bucket
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-34.5,24);

      b2Body* body10;

      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.1f;
      fd1->restitution = 0.f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape poly;
      b2Vec2 vertices[4];
      vertices[0].Set(0,0);
      vertices[1].Set(0,0.3);
      vertices[2].Set(-3,2.3);
      vertices[3].Set(-3,2);
      poly.Set(vertices, 4);
      fd1->shape = &poly;

      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.4;
      fd2->restitution = 0.0f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape poly2;
      b2Vec2 vertices2[4];
      vertices2[0].Set(0,0);
      vertices2[1].Set(3,2);
      vertices2[2].Set(3,2.3);
      vertices2[3].Set(0,0.3);
      poly2.Set(vertices2, 4);
      fd2->shape = &poly2;

      body10 = m_world->CreateBody(bd);
      body10->CreateFixture(fd1);
      body10->CreateFixture(fd2);
    }


    ////////////////////////////////////
        
    //fourth ball
    {
      b2CircleShape circle;
      circle.m_radius = 0.6;
      
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 75.0f;
      ballfd.friction = 0.001f;
      ballfd.restitution = -20.0f;
      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(-32.5f, 24.6f);
      b2Body* body;
      body = m_world->CreateBody(&ballbd);
      body->CreateFixture(&ballfd);
    }

    ///////////////////////////////////////////////

    //plank-bucket-full of balls
    {
      b2PolygonShape shape12;
      shape12.SetAsBox(8.0f, 0.2f);
      b2BodyDef bd11;
      bd11.position.Set(-19.0f, 19.8f);
      //bd11.type = b2_dynamicBody;
      b2Body* body12 = m_world->CreateBody(&bd11);
      b2FixtureDef *fd11 = new b2FixtureDef;
      fd11->friction=100.0f;
      fd11->density = 10.0f;
      fd11->shape = new b2PolygonShape;
      fd11->shape = &shape12;
      body12->CreateFixture(fd11);
    }

    
    ///////////////////////////////////////////////

    {
      b2Body* body;
      b2PolygonShape poly;
      b2Vec2 vertices[4];
      vertices[0].Set(0,0);
      vertices[1].Set(0.75,0);
      vertices[2].Set(0.75,0.75);
      vertices[3].Set(0,0.75);
      poly.Set(vertices, 4);
      b2FixtureDef wedgefd;
      wedgefd.shape = &poly;
      wedgefd.density = 10.0f;
      wedgefd.friction = 0.0f;
      wedgefd.restitution = -1.0f;
      b2BodyDef wedgebd;
      wedgebd.position.Set(-27.0f, 20.0f);
      body = m_world->CreateBody(&wedgebd);
      body->CreateFixture(&wedgefd);
    }

    //v shape bucket full of balls
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-19,20);

      b2Body* body10;

      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 60.0f;
      fd1->friction = 0.1f;
      fd1->restitution = 0.0f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape poly;
      b2Vec2 vertices[4];
      vertices[0].Set(0,0);
      vertices[1].Set(0,0.4);
      vertices[2].Set(-2,3.4);
      vertices[3].Set(-2,3);
      poly.Set(vertices, 4);
      fd1->shape = &poly;

      //*********************************************//

      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 60.0;
      fd3->friction = 0.4;
      fd3->restitution = 0.0f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape poly3;
      b2Vec2 vertices3[4];
      vertices3[0].Set(0,0);
      vertices3[1].Set(1.5,0);
      vertices3[2].Set(1.5,0.4);
      vertices3[3].Set(0,0.4);
      poly3.Set(vertices3, 4);
      fd3->shape = &poly3;

      //*******************************************//

      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 60.0;
      fd2->friction = 0.4;
      fd2->restitution = 0.0f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape poly2;
      b2Vec2 vertices2[4];
      vertices2[0].Set(1.5,0);
      vertices2[1].Set(3.5,3);
      vertices2[2].Set(3.5,3.4);
      vertices2[3].Set(1.5,0.4);
      poly2.Set(vertices2, 4);
      fd2->shape = &poly2;

      body10 = m_world->CreateBody(bd);
      body10->CreateFixture(fd1);
      body10->CreateFixture(fd3);
      body10->CreateFixture(fd2);

      //********************************************//

      b2CircleShape circle;
      circle.m_radius = 0.3;
      
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 4.0f;
      ballfd.friction = 0.0f;
      ballfd.restitution = 0.0f;
    
      for (int i = 0; i < 5; ++i)
      {
        b2BodyDef ballbd;
        ballbd.type = b2_dynamicBody;
        ballbd.position.Set(-17.95,20.3+ i*1);
        b2Body* body1;
        body1 = m_world->CreateBody(&ballbd);
        body1->CreateFixture(&ballfd);
        ballbd.position.Set(-18.55,20.3+ i*1);
        b2Body* body2;
        body2 = m_world->CreateBody(&ballbd);
        body2->CreateFixture(&ballfd);
      }
    }

    //////////////////////////////////////////////////

    //pulley system
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-8.7,13);
      bd->fixedRotation = true;
      
      //The open box

      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 10.0;
      fd1->friction = 0.5;
      fd1->restitution = 0.0f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(1.8,0.1, b2Vec2(0.0f,0.0f), 0);
      fd1->shape = &bs1;

      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 10.0;
      fd2->friction = 0.5;
      fd2->restitution = 0.0f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.1,1.5, b2Vec2(-1.90f,1.4f), 0);
      fd2->shape = &bs2;

      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 10.0;
      fd3->friction = 0.5;
      fd3->restitution = 0.0f;
      fd3->shape = new b2PolygonShape;
      b2PolygonShape bs3;
      bs3.SetAsBox(0.1,1.5, b2Vec2(1.90f,1.4f), 0);
      fd3->shape = &bs3;
       
      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);
      box1->CreateFixture(fd2);
      box1->CreateFixture(fd3);

      //The bar
      bd->position.Set(-3.5,13);  
      fd1->density =40.0f;    
      b2Body* box2 = m_world->CreateBody(bd);
      box2->CreateFixture(fd1);

      // The pulley joint
      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody1(-8.5, 13); 
      b2Vec2 worldAnchorOnBody2(-3.5, 13); 
      b2Vec2 worldAnchorGround1(-8.5, 17); 
      b2Vec2 worldAnchorGround2(-3.5, 17);
      float32 ratio = 1.0f; 
      myjoint->Initialize(box1, box2, worldAnchorGround1, worldAnchorGround2, box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);
    }

    ///////////////////////////////////////////////////////////////////

    // revolving plank
    {
      b2PolygonShape shape;
      shape.SetAsBox(1.0f, 0.2f);
  
      b2BodyDef bd;
      bd.position.Set(-0.9f, 14.7f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 100.0f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      body->CreateFixture(fd);

      b2PolygonShape shape2;
      b2BodyDef bd2;
      bd2.position.Set(-0.9f, 14.7f);
      b2Body* body2 = m_world->CreateBody(&bd2);

      b2RevoluteJointDef jointDef;
      jointDef.bodyA = body;
      jointDef.bodyB = body2;
      jointDef.localAnchorA.Set(0,0);
      jointDef.localAnchorB.Set(0,0);
      m_world->CreateJoint(&jointDef);

      //*******************************************//

      b2PolygonShape shape3;
      shape3.SetAsBox(1.0f, 0.2f);
  
      b2BodyDef bd3;
      bd3.position.Set(0.8f, 14.2f);
      bd3.type = b2_dynamicBody;
      b2Body* body3 = m_world->CreateBody(&bd3);
      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 100.0f;
      fd3->shape = new b2PolygonShape;
      fd3->shape = &shape3;
      body3->CreateFixture(fd3);

      b2PolygonShape shape4;
      b2BodyDef bd4;
      bd4.position.Set(0.8f, 14.2f);
      b2Body* body4 = m_world->CreateBody(&bd4);

      b2RevoluteJointDef jointDef2;
      jointDef2.bodyA = body3;
      jointDef2.bodyB = body4;
      jointDef2.localAnchorA.Set(0,0);
      jointDef2.localAnchorB.Set(0,0);
      m_world->CreateJoint(&jointDef2);
    }
    
    //////////////////////////////////////////////////

    {
      b2PolygonShape shape;
      shape.SetAsBox(1.0f, 0.2f);
  
      b2BodyDef bd;
      bd.position.Set(2.5f, 13.8f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 0.001f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      body->CreateFixture(fd);

      b2PolygonShape shape2;
      b2BodyDef bd2;
      bd2.position.Set(2.5f, 13.8f);
      b2Body* body2 = m_world->CreateBody(&bd2);

      b2RevoluteJointDef jointDef;
      jointDef.bodyA = body;
      jointDef.bodyB = body2;
      jointDef.localAnchorA.Set(0,0);
      jointDef.localAnchorB.Set(0,0);
      m_world->CreateJoint(&jointDef);
    }

    ///////////////////////////////////////////

    //pendulums
    {
      b2CircleShape circle;
      circle.m_radius = 0.6f;
  
      b2FixtureDef ballfd;
      ballfd.shape = &circle;
      ballfd.density = 0.01f;
      ballfd.friction = 1.0f;
      ballfd.restitution = 1.0f;

      b2BodyDef ballbd;
      ballbd.type = b2_dynamicBody;
      ballbd.position.Set(3.3f,14.6f);
      b2Body* b2 = m_world->CreateBody(&ballbd);
      b2->CreateFixture(&ballfd);
  
      b2Body* b4;
      {
        b2PolygonShape shape;
        shape.SetAsBox(4.2f, 0.2f);
          
        b2BodyDef bd;
        //bd.type = b2_dynamicBody;
        bd.position.Set(14.6f, 14.6f);
        b4 = m_world->CreateBody(&bd);
        b4->CreateFixture(&shape, 2.0f);
      }
  
      b2RevoluteJointDef jd;

      b2Vec2 anchor;
      anchor.Set(10.8f, 14.6f);


      jd.Initialize(b2, b4, anchor);
      m_world->CreateJoint(&jd);

      for(int i=0;i<6;i++)
      {
        b2BodyDef ballbd;
        ballbd.type = b2_dynamicBody;
        ballbd.position.Set(12+i*1.2001,7.1f);
        b2Body* b3 = m_world->CreateBody(&ballbd);
        b3->CreateFixture(&ballfd);

        b2RevoluteJointDef jd1;

        anchor.Set(12.0+ i*1.2001, 14.6f);

        jd1.Initialize(b3, b4, anchor);
        m_world->CreateJoint(&jd1);
      }
    }  

    /////////////////////////////////////////////////

    //another revolving plank
    {
      b2PolygonShape shape;
      shape.SetAsBox(2.0f, 0.2f);
    
      b2BodyDef bd;
      bd.position.Set(27.9f, 13.7f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 0.0001f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      body->CreateFixture(fd);

      b2PolygonShape shape2;
      b2BodyDef bd2;
      bd2.position.Set(27.9f, 13.7f);
      b2Body* body2 = m_world->CreateBody(&bd2);

      b2RevoluteJointDef jointDef;
      jointDef.bodyA = body;
      jointDef.bodyB = body2;
      jointDef.localAnchorA.Set(0,0);
      jointDef.localAnchorB.Set(0,0);
      //jointDef.collideConnected = true;
      m_world->CreateJoint(&jointDef);
    }
    
    //////////////////////////////////////

    //bar
    {
      b2PolygonShape shape;
      shape.SetAsBox(1.0f, 0.2f);
    
      b2BodyDef bd;
      bd.position.Set(27.9f, 14.1f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 0.01f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      body->CreateFixture(fd);
    }

    //////////////////////////////////////

    //another pulley system
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(28.9,10);
      bd->fixedRotation = true;
      
      //The Bar
      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density =0.015;
      fd1->friction = 0.5;
      fd1->restitution = 0.0f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(2,0.2);
      fd1->shape = &bs1;
      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);

      //The gate
      bd->position.Set(38.9,5);  
      fd1->density =40.0f;    
      b2Body* box2 = m_world->CreateBody(bd);
      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 0.0024f;
      fd2->friction = 0.5;
      fd2->restitution = 0.0f;
      fd2->shape = new b2PolygonShape;
      b2PolygonShape bs2;
      bs2.SetAsBox(0.5,5);
      fd2->shape = &bs2;
      box2->CreateFixture(fd2);

      // The pulley joint
      b2PulleyJointDef* myjoint = new b2PulleyJointDef();
      b2Vec2 worldAnchorOnBody1(28.9,10 ); 
      b2Vec2 worldAnchorOnBody2(38.9, 10);
      b2Vec2 worldAnchorGround1(28.9,12); 
      b2Vec2 worldAnchorGround2(38.9, 12);
      float32 ratio = 1.0f;
      myjoint->Initialize(box1, box2, worldAnchorGround1, worldAnchorGround2, box1->GetWorldCenter(), box2->GetWorldCenter(), ratio);
      m_world->CreateJoint(myjoint);
    }

    ///////////////////////////////////////

    //www/iforce2d.net/b2dtut/bodies
    //http://stackoverflow.com/questions/8007170/cocos2d-box2d-multiple-b2circle-shape-fixture-for-one-body-with-positioning

    //the car
    {
      b2BodyDef *bd = new b2BodyDef;
      bd->type = b2_dynamicBody;
      bd->position.Set(-124.5,3);
      //bd->fixedRotation = true;
      
      //The open box

      b2FixtureDef *fd1 = new b2FixtureDef;
      fd1->density = 0.001f;
      fd1->friction = 10.0;
      fd1->restitution = 0.0f;
      fd1->shape = new b2PolygonShape;
      b2PolygonShape bs1;
      bs1.SetAsBox(3,1.5, b2Vec2(0.0f,0.0f), 0);
      fd1->shape = &bs1;

      b2FixtureDef *fd2 = new b2FixtureDef;
      fd2->density = 0.001f;
      fd2->friction = 0.0;
      fd2->restitution = 0.0f;
      fd2->shape = new b2CircleShape;
      b2CircleShape circle;
      circle.m_radius = 0.75f;
      circle.m_p.Set(-2,-2.25);
      fd2->shape = &circle;

      b2FixtureDef *fd3 = new b2FixtureDef;
      fd3->density = 0.0001f;
      fd3->friction = 0.0;
      fd3->restitution = 0.0f;
      fd3->shape = new b2CircleShape;
      b2CircleShape circle2;
      circle2.m_radius = 0.75f;
      circle2.m_p.Set(2,-2.25);
      fd3->shape = &circle2;

       
      b2Body* box1 = m_world->CreateBody(bd);
      box1->CreateFixture(fd1);
      box1->CreateFixture(fd2);
      box1->CreateFixture(fd3);

      box1->SetLinearVelocity(b2Vec2(3.51,0));
    }

    /////////////////////////////////////////

    //ground with cavity
    {    
      //bd.type = b2_dynamicBody;
      b2BodyDef bd;
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 0.1f;
      fd->friction= 0.016f;

      b2PolygonShape poly2;
      b2Vec2 vertices2[4];
      vertices2[0].Set(-428.1,2.4);
      vertices2[1].Set(0,2.5);
      vertices2[2].Set(428.3,2.5);
      vertices2[3].Set(428.3,-2.5);
      vertices2[4].Set(-428.1,-2.5);
      poly2.Set(vertices2, 5);
      fd->shape = new b2PolygonShape;
      fd->shape = &poly2;
      bd.position.Set(471.7f, -2.5f);
      b2Body* body1 = m_world->CreateBody(&bd);
      body1->CreateFixture(fd);

      /*b2PolygonShape shape2;
      shape2.SetAsBox(11.0f, 1.75f);*/
      b2PolygonShape poly3;
      b2Vec2 vertices3[4];
      vertices3[0].Set(-17.0,1.55);
      vertices3[1].Set(-4.5,1.75);
      vertices3[2].Set(11.0,1.74);
      vertices3[3].Set(11.0,-1.75);
      vertices3[4].Set(-17.0,-1.75);
      poly3.Set(vertices3, 5);
      fd->shape = new b2PolygonShape;
      fd->shape = &poly3;
      bd.position.Set(30.0f, -1.75f);
      b2Body* body2 = m_world->CreateBody(&bd);
      body2->CreateFixture(fd);

      b2PolygonShape shape3;
      shape3.SetAsBox(456.0f, 2.5f);
      fd->shape = new b2PolygonShape;
      fd->shape = &shape3;
      bd.position.Set(-444.0f, -2.5f);
      b2Body* body3 = m_world->CreateBody(&bd);
      body3->CreateFixture(fd);
    }

    //////////////////////////////////////////

    //revolving hinge plank
    {
      b2PolygonShape shape;
      shape.SetAsBox(0.01f, 2.0f);
    
      b2BodyDef bd;
      bd.position.Set(41.0f, 1.8f);
      bd.type = b2_dynamicBody;
      b2Body* body = m_world->CreateBody(&bd);
      b2FixtureDef *fd = new b2FixtureDef;
      fd->density = 0.01f;
      fd->restitution = -0.5f;
      fd->shape = new b2PolygonShape;
      fd->shape = &shape;
      body->CreateFixture(fd);

      b2PolygonShape shape2;
      b2BodyDef bd2;
      bd2.position.Set(41.0f, 0.0f);
      b2Body* body2 = m_world->CreateBody(&bd2);

      b2RevoluteJointDef jointDef;
      jointDef.bodyA = body;
      jointDef.bodyB = body2;
      jointDef.localAnchorA.Set(0,-2.0);
      jointDef.localAnchorB.Set(0,0);
      m_world->CreateJoint(&jointDef);
    }
  }