/* 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(¢erCircleDef); /*! 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(¢erCircleFixtureDef); /*! 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(¢erCircleDef); /*! 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(¢erCircleFixtureDef); } { /*! 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(¢erCircleDef); /*! 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(¢erCircleFixtureDef); } } }
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 }
/** 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(¢erCircleDef); 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(¢erCircleFixtureDef); 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); } } }