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.

138 lines
4.2KB

  1. /*
  2. * Copyright (c) 2006-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 CONTINUOUS_TEST_H
  19. #define CONTINUOUS_TEST_H
  20. class ContinuousTest : public Test
  21. {
  22. public:
  23. ContinuousTest()
  24. {
  25. {
  26. b2BodyDef bd;
  27. bd.position.Set(0.0f, 0.0f);
  28. b2Body* body = m_world->CreateBody(&bd);
  29. b2EdgeShape edge;
  30. edge.Set(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f));
  31. body->CreateFixture(&edge, 0.0f);
  32. b2PolygonShape shape;
  33. shape.SetAsBox(0.2f, 1.0f, b2Vec2(0.5f, 1.0f), 0.0f);
  34. body->CreateFixture(&shape, 0.0f);
  35. }
  36. #if 1
  37. {
  38. b2BodyDef bd;
  39. bd.type = b2_dynamicBody;
  40. bd.position.Set(0.0f, 20.0f);
  41. //bd.angle = 0.1f;
  42. b2PolygonShape shape;
  43. shape.SetAsBox(2.0f, 0.1f);
  44. m_body = m_world->CreateBody(&bd);
  45. m_body->CreateFixture(&shape, 1.0f);
  46. m_angularVelocity = RandomFloat(-50.0f, 50.0f);
  47. //m_angularVelocity = 46.661274f;
  48. m_body->SetLinearVelocity(b2Vec2(0.0f, -100.0f));
  49. m_body->SetAngularVelocity(m_angularVelocity);
  50. }
  51. #else
  52. {
  53. b2BodyDef bd;
  54. bd.type = b2_dynamicBody;
  55. bd.position.Set(0.0f, 2.0f);
  56. b2Body* body = m_world->CreateBody(&bd);
  57. b2CircleShape shape;
  58. shape.m_p.SetZero();
  59. shape.m_radius = 0.5f;
  60. body->CreateFixture(&shape, 1.0f);
  61. bd.bullet = true;
  62. bd.position.Set(0.0f, 10.0f);
  63. body = m_world->CreateBody(&bd);
  64. body->CreateFixture(&shape, 1.0f);
  65. body->SetLinearVelocity(b2Vec2(0.0f, -100.0f));
  66. }
  67. #endif
  68. }
  69. void Launch()
  70. {
  71. m_body->SetTransform(b2Vec2(0.0f, 20.0f), 0.0f);
  72. m_angularVelocity = RandomFloat(-50.0f, 50.0f);
  73. m_body->SetLinearVelocity(b2Vec2(0.0f, -100.0f));
  74. m_body->SetAngularVelocity(m_angularVelocity);
  75. }
  76. void Step(Settings* settings)
  77. {
  78. if (m_stepCount == 12)
  79. {
  80. m_stepCount += 0;
  81. }
  82. Test::Step(settings);
  83. extern int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters;
  84. if (b2_gjkCalls > 0)
  85. {
  86. m_debugDraw.DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d",
  87. b2_gjkCalls, b2_gjkIters / float32(b2_gjkCalls), b2_gjkMaxIters);
  88. m_textLine += 15;
  89. }
  90. extern int32 b2_toiCalls, b2_toiIters;
  91. extern int32 b2_toiRootIters, b2_toiMaxRootIters;
  92. if (b2_toiCalls > 0)
  93. {
  94. m_debugDraw.DrawString(5, m_textLine, "toi calls = %d, ave toi iters = %3.1f, max toi iters = %d",
  95. b2_toiCalls, b2_toiIters / float32(b2_toiCalls), b2_toiMaxRootIters);
  96. m_textLine += 15;
  97. m_debugDraw.DrawString(5, m_textLine, "ave toi root iters = %3.1f, max toi root iters = %d",
  98. b2_toiRootIters / float32(b2_toiCalls), b2_toiMaxRootIters);
  99. m_textLine += 15;
  100. }
  101. if (m_stepCount % 60 == 0)
  102. {
  103. //Launch();
  104. }
  105. }
  106. static Test* Create()
  107. {
  108. return new ContinuousTest;
  109. }
  110. b2Body* m_body;
  111. float32 m_angularVelocity;
  112. };
  113. #endif