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.

102 lines
2.7KB

  1. /*
  2. * Copyright (c) 2011 Erin Catto http://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 ROPE_H
  19. #define ROPE_H
  20. ///
  21. class Rope : public Test
  22. {
  23. public:
  24. Rope()
  25. {
  26. const int32 N = 40;
  27. b2Vec2 vertices[N];
  28. float32 masses[N];
  29. for (int32 i = 0; i < N; ++i)
  30. {
  31. vertices[i].Set(0.0f, 20.0f - 0.25f * i);
  32. masses[i] = 1.0f;
  33. }
  34. masses[0] = 0.0f;
  35. masses[1] = 0.0f;
  36. b2RopeDef def;
  37. def.vertices = vertices;
  38. def.count = N;
  39. def.gravity.Set(0.0f, -10.0f);
  40. def.masses = masses;
  41. def.damping = 0.1f;
  42. def.k2 = 1.0f;
  43. def.k3 = 0.5f;
  44. m_rope.Initialize(&def);
  45. m_angle = 0.0f;
  46. m_rope.SetAngle(m_angle);
  47. }
  48. void Keyboard(unsigned char key)
  49. {
  50. switch (key)
  51. {
  52. case 'q':
  53. m_angle = b2Max(-b2_pi, m_angle - 0.05f * b2_pi);
  54. m_rope.SetAngle(m_angle);
  55. break;
  56. case 'e':
  57. m_angle = b2Min(b2_pi, m_angle + 0.05f * b2_pi);
  58. m_rope.SetAngle(m_angle);
  59. break;
  60. }
  61. }
  62. void Step(Settings* settings)
  63. {
  64. float32 dt = settings->hz > 0.0f ? 1.0f / settings->hz : 0.0f;
  65. if (settings->pause == 1 && settings->singleStep == 0)
  66. {
  67. dt = 0.0f;
  68. }
  69. m_rope.Step(dt, 1);
  70. Test::Step(settings);
  71. m_rope.Draw(&m_debugDraw);
  72. m_debugDraw.DrawString(5, m_textLine, "Press (q,e) to adjust target angle");
  73. m_textLine += 15;
  74. m_debugDraw.DrawString(5, m_textLine, "Target angle = %g degrees", m_angle * 180.0f / b2_pi);
  75. m_textLine += 15;
  76. }
  77. static Test* Create()
  78. {
  79. return new Rope;
  80. }
  81. b2Rope m_rope;
  82. float32 m_angle;
  83. };
  84. #endif