The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.1KB

  1. /*
  2. * Copyright (c) 2007-2009 Erin Catto http://www.box2d.org
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. * Permission is granted to anyone to use this software for any purpose,
  8. * including commercial applications, and to alter it and redistribute it
  9. * freely, subject to the following restrictions:
  10. * 1. The origin of this software must not be misrepresented; you must not
  11. * claim that you wrote the original software. If you use this software
  12. * in a product, an acknowledgment in the product documentation would be
  13. * appreciated but is not required.
  14. * 2. Altered source versions must be plainly marked as such, and must not be
  15. * misrepresented as being the original software.
  16. * 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef PULLEYS_H
  19. #define PULLEYS_H
  20. class Pulleys : public Test
  21. {
  22. public:
  23. Pulleys()
  24. {
  25. float32 y = 16.0f;
  26. float32 L = 12.0f;
  27. float32 a = 1.0f;
  28. float32 b = 2.0f;
  29. b2Body* ground = NULL;
  30. {
  31. b2BodyDef bd;
  32. ground = m_world->CreateBody(&bd);
  33. b2EdgeShape edge;
  34. edge.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));
  35. //ground->CreateFixture(&shape, 0.0f);
  36. b2CircleShape circle;
  37. circle.m_radius = 2.0f;
  38. circle.m_p.Set(-10.0f, y + b + L);
  39. ground->CreateFixture(&circle, 0.0f);
  40. circle.m_p.Set(10.0f, y + b + L);
  41. ground->CreateFixture(&circle, 0.0f);
  42. }
  43. {
  44. b2PolygonShape shape;
  45. shape.SetAsBox(a, b);
  46. b2BodyDef bd;
  47. bd.type = b2_dynamicBody;
  48. //bd.fixedRotation = true;
  49. bd.position.Set(-10.0f, y);
  50. b2Body* body1 = m_world->CreateBody(&bd);
  51. body1->CreateFixture(&shape, 5.0f);
  52. bd.position.Set(10.0f, y);
  53. b2Body* body2 = m_world->CreateBody(&bd);
  54. body2->CreateFixture(&shape, 5.0f);
  55. b2PulleyJointDef pulleyDef;
  56. b2Vec2 anchor1(-10.0f, y + b);
  57. b2Vec2 anchor2(10.0f, y + b);
  58. b2Vec2 groundAnchor1(-10.0f, y + b + L);
  59. b2Vec2 groundAnchor2(10.0f, y + b + L);
  60. pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 1.5f);
  61. m_joint1 = (b2PulleyJoint*)m_world->CreateJoint(&pulleyDef);
  62. }
  63. }
  64. void Keyboard(unsigned char key)
  65. {
  66. switch (key)
  67. {
  68. case 0:
  69. break;
  70. }
  71. }
  72. void Step(Settings* settings)
  73. {
  74. Test::Step(settings);
  75. float32 ratio = m_joint1->GetRatio();
  76. float32 L = m_joint1->GetLengthA() + ratio * m_joint1->GetLengthB();
  77. m_debugDraw.DrawString(5, m_textLine, "L1 + %4.2f * L2 = %4.2f", (float) ratio, (float) L);
  78. m_textLine += 15;
  79. }
  80. static Test* Create()
  81. {
  82. return new Pulleys;
  83. }
  84. b2PulleyJoint* m_joint1;
  85. };
  86. #endif