PicoPicoGameEngine

Quick Links

Source Code

world=b2World.new(0,20)

shape=b2Shape.edge()
shape:set(50,0,-50,0)
ground=world:createBody()
ground:createFixture(shape)

circle1=b2Shape.circle({density=5})
circle1.radius=1
box=b2Shape.polygon({density=5})
box:setAsBox(0.5,5.0)
circle2=b2Shape.circle({density=5})
circle2.radius=2
body1=world:createBody(10,-9)
body1:createFixture(circle1)
body2=world:createBody("dynamic",10,-8)
body2:createFixture(box)
body3=world:createBody("dynamic",10,-6)
body3:createFixture(circle2)

joint1=world:createJoint(
   "revolute",body2,body1,
   {anchor={x=10,y=-9}})
joint2=world:createJoint(
   "revolute",body2,body3,
   {anchor={x=10,y=-6}})
world:createJoint("gear",body1,body3,
  {joint1=joint1,
   joint2=joint2,
   ratio=circle2.radius/circle1.radius})

circle1=b2Shape.circle({density=5})
circle1.radius=1
circle2=b2Shape.circle({density=5})
circle2.radius=2
box=b2Shape.polygon({density=5})
box:setAsBox(0.5,5.0)

body1=world:createBody("dynamic",-3,-12)
body1:createFixture(circle1)
joint1=world:createJoint(
  "revolute",ground,body1,
  {localAnchorA=ground:localPoint({x=-3,y=-12}),
   localAnchorB=body1:localPoint({x=-3,y=-12}),
   referenceAngle=body1.angle-ground.angle})

body2=world:createBody("dynamic",0,-12)
body2:createFixture(circle2)
joint2=world:createJoint(
  "revolute",ground,body2,
  {anchor={x=0,y=-12}})

body3=world:createBody("dynamic",2.5,-12)
body3:createFixture(box)
joint3=world:createJoint(
  "prismatic",ground,body3,
  {anchor={x=2.5,y=-12},
   axis={x=0,y=1},
   lowerTranslation=-5,
   upperTranslation=5,
   enableLimit=true})

joint4=world:createJoint(
  "gear",body1,body2,
  {joint1=joint1,
   joint2=joint2,
   ratio=circle2.radius/circle1.radius})

joint5=world:createJoint(
  "gear",body2,body3,
  {joint1=joint2,
   joint2=joint3,
   ratio=-1/circle2.radius})

world:shiftOrigin(-13,-30)

function start()
  world:debugDrag(pptouch())
  world:step()
  world:debugDrawBody()
  world:debugDrawJoint()
end