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.

106 lines
3.0KB

  1. /*
  2. * Copyright (c) 2008-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 SHAPE_EDITING_H
  19. #define SHAPE_EDITING_H
  20. class ShapeEditing : public Test
  21. {
  22. public:
  23. ShapeEditing()
  24. {
  25. {
  26. b2BodyDef bd;
  27. b2Body* ground = m_world->CreateBody(&bd);
  28. b2EdgeShape shape;
  29. shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));
  30. ground->CreateFixture(&shape, 0.0f);
  31. }
  32. b2BodyDef bd;
  33. bd.type = b2_dynamicBody;
  34. bd.position.Set(0.0f, 10.0f);
  35. m_body = m_world->CreateBody(&bd);
  36. b2PolygonShape shape;
  37. shape.SetAsBox(4.0f, 4.0f, b2Vec2(0.0f, 0.0f), 0.0f);
  38. m_fixture1 = m_body->CreateFixture(&shape, 10.0f);
  39. m_fixture2 = NULL;
  40. m_sensor = false;
  41. }
  42. void Keyboard(unsigned char key)
  43. {
  44. switch (key)
  45. {
  46. case 'c':
  47. if (m_fixture2 == NULL)
  48. {
  49. b2CircleShape shape;
  50. shape.m_radius = 3.0f;
  51. shape.m_p.Set(0.5f, -4.0f);
  52. m_fixture2 = m_body->CreateFixture(&shape, 10.0f);
  53. m_body->SetAwake(true);
  54. }
  55. break;
  56. case 'd':
  57. if (m_fixture2 != NULL)
  58. {
  59. m_body->DestroyFixture(m_fixture2);
  60. m_fixture2 = NULL;
  61. m_body->SetAwake(true);
  62. }
  63. break;
  64. case 's':
  65. if (m_fixture2 != NULL)
  66. {
  67. m_sensor = !m_sensor;
  68. m_fixture2->SetSensor(m_sensor);
  69. }
  70. break;
  71. }
  72. }
  73. void Step(Settings* settings)
  74. {
  75. Test::Step(settings);
  76. m_debugDraw.DrawString(5, m_textLine, "Press: (c) create a shape, (d) destroy a shape.");
  77. m_textLine += 15;
  78. m_debugDraw.DrawString(5, m_textLine, "sensor = %d", m_sensor);
  79. m_textLine += 15;
  80. }
  81. static Test* Create()
  82. {
  83. return new ShapeEditing;
  84. }
  85. b2Body* m_body;
  86. b2Fixture* m_fixture1;
  87. b2Fixture* m_fixture2;
  88. bool m_sensor;
  89. };
  90. #endif