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.

100 lines
2.9KB

  1. /*
  2. * Copyright (c) 2011 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 TUMBLER_H
  19. #define TUMBLER_H
  20. class Tumbler : public Test
  21. {
  22. public:
  23. enum
  24. {
  25. e_count = 800
  26. };
  27. Tumbler()
  28. {
  29. b2Body* ground = NULL;
  30. {
  31. b2BodyDef bd;
  32. ground = m_world->CreateBody(&bd);
  33. }
  34. {
  35. b2BodyDef bd;
  36. bd.type = b2_dynamicBody;
  37. bd.allowSleep = false;
  38. bd.position.Set(0.0f, 10.0f);
  39. b2Body* body = m_world->CreateBody(&bd);
  40. b2PolygonShape shape;
  41. shape.SetAsBox(0.5f, 10.0f, b2Vec2( 10.0f, 0.0f), 0.0);
  42. body->CreateFixture(&shape, 5.0f);
  43. shape.SetAsBox(0.5f, 10.0f, b2Vec2(-10.0f, 0.0f), 0.0);
  44. body->CreateFixture(&shape, 5.0f);
  45. shape.SetAsBox(10.0f, 0.5f, b2Vec2(0.0f, 10.0f), 0.0);
  46. body->CreateFixture(&shape, 5.0f);
  47. shape.SetAsBox(10.0f, 0.5f, b2Vec2(0.0f, -10.0f), 0.0);
  48. body->CreateFixture(&shape, 5.0f);
  49. b2RevoluteJointDef jd;
  50. jd.bodyA = ground;
  51. jd.bodyB = body;
  52. jd.localAnchorA.Set(0.0f, 10.0f);
  53. jd.localAnchorB.Set(0.0f, 0.0f);
  54. jd.referenceAngle = 0.0f;
  55. jd.motorSpeed = 0.05f * b2_pi;
  56. jd.maxMotorTorque = 1e8f;
  57. jd.enableMotor = true;
  58. m_joint = (b2RevoluteJoint*)m_world->CreateJoint(&jd);
  59. }
  60. m_count = 0;
  61. }
  62. void Step(Settings* settings)
  63. {
  64. Test::Step(settings);
  65. if (m_count < e_count)
  66. {
  67. b2BodyDef bd;
  68. bd.type = b2_dynamicBody;
  69. bd.position.Set(0.0f, 10.0f);
  70. b2Body* body = m_world->CreateBody(&bd);
  71. b2PolygonShape shape;
  72. shape.SetAsBox(0.125f, 0.125f);
  73. body->CreateFixture(&shape, 1.0f);
  74. ++m_count;
  75. }
  76. }
  77. static Test* Create()
  78. {
  79. return new Tumbler;
  80. }
  81. b2RevoluteJoint* m_joint;
  82. int32 m_count;
  83. };
  84. #endif