pulleys.bmx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. SuperStrict
  2. Framework Physics.Box2d
  3. Import SDL.SDLRenderMax2D
  4. Import "test.bmx"
  5. Graphics 800,600, 0
  6. SetBlend alphablend
  7. Run(New Pulleys.Create(), New TSettings)
  8. Type Pulleys Extends Test
  9. Field m_joint1:b2PulleyJoint
  10. Method Create:Pulleys()
  11. Init(12, 12)
  12. Local ground:b2Body
  13. Local sd:b2PolygonDef = New b2PolygonDef
  14. sd.SetAsBox(50.0, 10.0)
  15. Local bd:b2BodyDef = New b2BodyDef
  16. bd.SetPosition(New b2Vec2.Create(0.0, -10.0))
  17. ground = m_world.CreateBody(bd)
  18. ground.CreateShape(sd)
  19. Local a:Float = 2.0
  20. Local b:Float = 4.0
  21. Local y:Float = 16.0
  22. Local L:Float = 12.0
  23. sd = New b2PolygonDef
  24. sd.SetAsBox(a, b)
  25. sd.SetDensity(5.0)
  26. bd = New b2BodyDef
  27. bd.SetPosition(New b2Vec2.Create(-10.0, y))
  28. Local body1:b2Body = m_world.CreateBody(bd)
  29. body1.CreateShape(sd)
  30. body1.SetMassFromShapes()
  31. bd.SetPosition(New b2Vec2.Create(10.0, y))
  32. Local body2:b2Body = m_world.CreateBody(bd)
  33. body2.CreateShape(sd)
  34. body2.SetMassFromShapes()
  35. Local pulleyDef:b2PulleyJointDef = New b2PulleyJointDef
  36. Local anchor1:b2Vec2 = New b2Vec2.Create(-10.0, y + b)
  37. Local anchor2:b2Vec2 = New b2Vec2.Create(10.0, y + b)
  38. Local groundAnchor1:b2Vec2 = New b2Vec2.Create(-10.0, y + b + L)
  39. Local groundAnchor2:b2Vec2 = New b2Vec2.Create(10.0, y + b + L)
  40. pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 2.0)
  41. m_joint1 = b2PulleyJoint(m_world.CreateJoint(pulleyDef))
  42. Return Self
  43. End Method
  44. Method DoStep(settings:TSettings)
  45. Super.DoStep(settings)
  46. Local ratio:Float = m_joint1.GetRatio()
  47. Local L:Float = m_joint1.GetLength1() + ratio * m_joint1.GetLength2()
  48. DrawString "L1 + " + ratio + " * L2 = " + L, 5, m_textLine
  49. m_textLine :+ 12
  50. End Method
  51. End Type