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.

70 lines
2.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 VARYING_RESTITUTION_H
  19. #define VARYING_RESTITUTION_H
  20. // Note: even with a restitution of 1.0, there is some energy change
  21. // due to position correction.
  22. class VaryingRestitution : public Test
  23. {
  24. public:
  25. VaryingRestitution()
  26. {
  27. {
  28. b2BodyDef bd;
  29. b2Body* ground = m_world->CreateBody(&bd);
  30. b2EdgeShape shape;
  31. shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));
  32. ground->CreateFixture(&shape, 0.0f);
  33. }
  34. {
  35. b2CircleShape shape;
  36. shape.m_radius = 1.0f;
  37. b2FixtureDef fd;
  38. fd.shape = &shape;
  39. fd.density = 1.0f;
  40. float32 restitution[7] = {0.0f, 0.1f, 0.3f, 0.5f, 0.75f, 0.9f, 1.0f};
  41. for (int32 i = 0; i < 7; ++i)
  42. {
  43. b2BodyDef bd;
  44. bd.type = b2_dynamicBody;
  45. bd.position.Set(-10.0f + 3.0f * i, 20.0f);
  46. b2Body* body = m_world->CreateBody(&bd);
  47. fd.restitution = restitution[i];
  48. body->CreateFixture(&fd);
  49. }
  50. }
  51. }
  52. static Test* Create()
  53. {
  54. return new VaryingRestitution;
  55. }
  56. };
  57. #endif