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.

137 lines
4.1KB

  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 BULLET_TEST_H
  19. #define BULLET_TEST_H
  20. class BulletTest : public Test
  21. {
  22. public:
  23. BulletTest()
  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. {
  37. b2BodyDef bd;
  38. bd.type = b2_dynamicBody;
  39. bd.position.Set(0.0f, 4.0f);
  40. b2PolygonShape box;
  41. box.SetAsBox(2.0f, 0.1f);
  42. m_body = m_world->CreateBody(&bd);
  43. m_body->CreateFixture(&box, 1.0f);
  44. box.SetAsBox(0.25f, 0.25f);
  45. //m_x = RandomFloat(-1.0f, 1.0f);
  46. m_x = 0.20352793f;
  47. bd.position.Set(m_x, 10.0f);
  48. bd.bullet = true;
  49. m_bullet = m_world->CreateBody(&bd);
  50. m_bullet->CreateFixture(&box, 100.0f);
  51. m_bullet->SetLinearVelocity(b2Vec2(0.0f, -50.0f));
  52. }
  53. }
  54. void Launch()
  55. {
  56. m_body->SetTransform(b2Vec2(0.0f, 4.0f), 0.0f);
  57. m_body->SetLinearVelocity(b2Vec2_zero);
  58. m_body->SetAngularVelocity(0.0f);
  59. m_x = RandomFloat(-1.0f, 1.0f);
  60. m_bullet->SetTransform(b2Vec2(m_x, 10.0f), 0.0f);
  61. m_bullet->SetLinearVelocity(b2Vec2(0.0f, -50.0f));
  62. m_bullet->SetAngularVelocity(0.0f);
  63. extern int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters;
  64. extern int32 b2_toiCalls, b2_toiIters, b2_toiMaxIters;
  65. extern int32 b2_toiRootIters, b2_toiMaxRootIters;
  66. b2_gjkCalls = 0;
  67. b2_gjkIters = 0;
  68. b2_gjkMaxIters = 0;
  69. b2_toiCalls = 0;
  70. b2_toiIters = 0;
  71. b2_toiMaxIters = 0;
  72. b2_toiRootIters = 0;
  73. b2_toiMaxRootIters = 0;
  74. }
  75. void Step(Settings* settings)
  76. {
  77. Test::Step(settings);
  78. extern int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters;
  79. extern int32 b2_toiCalls, b2_toiIters;
  80. extern int32 b2_toiRootIters, b2_toiMaxRootIters;
  81. if (b2_gjkCalls > 0)
  82. {
  83. m_debugDraw.DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d",
  84. b2_gjkCalls, b2_gjkIters / float32(b2_gjkCalls), b2_gjkMaxIters);
  85. m_textLine += 15;
  86. }
  87. if (b2_toiCalls > 0)
  88. {
  89. m_debugDraw.DrawString(5, m_textLine, "toi calls = %d, ave toi iters = %3.1f, max toi iters = %d",
  90. b2_toiCalls, b2_toiIters / float32(b2_toiCalls), b2_toiMaxRootIters);
  91. m_textLine += 15;
  92. m_debugDraw.DrawString(5, m_textLine, "ave toi root iters = %3.1f, max toi root iters = %d",
  93. b2_toiRootIters / float32(b2_toiCalls), b2_toiMaxRootIters);
  94. m_textLine += 15;
  95. }
  96. if (m_stepCount % 60 == 0)
  97. {
  98. Launch();
  99. }
  100. }
  101. static Test* Create()
  102. {
  103. return new BulletTest;
  104. }
  105. b2Body* m_body;
  106. b2Body* m_bullet;
  107. float32 m_x;
  108. };
  109. #endif