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.

108 lines
3.3KB

  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 PRISMATIC_H
  19. #define PRISMATIC_H
  20. // The motor in this test gets smoother with higher velocity iterations.
  21. class Prismatic : public Test
  22. {
  23. public:
  24. Prismatic()
  25. {
  26. b2Body* ground = NULL;
  27. {
  28. b2BodyDef bd;
  29. 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. b2PolygonShape shape;
  36. shape.SetAsBox(2.0f, 0.5f);
  37. b2BodyDef bd;
  38. bd.type = b2_dynamicBody;
  39. bd.position.Set(-10.0f, 10.0f);
  40. bd.angle = 0.5f * b2_pi;
  41. bd.allowSleep = false;
  42. b2Body* body = m_world->CreateBody(&bd);
  43. body->CreateFixture(&shape, 5.0f);
  44. b2PrismaticJointDef pjd;
  45. // Bouncy limit
  46. b2Vec2 axis(2.0f, 1.0f);
  47. axis.Normalize();
  48. pjd.Initialize(ground, body, b2Vec2(0.0f, 0.0f), axis);
  49. // Non-bouncy limit
  50. //pjd.Initialize(ground, body, b2Vec2(-10.0f, 10.0f), b2Vec2(1.0f, 0.0f));
  51. pjd.motorSpeed = 10.0f;
  52. pjd.maxMotorForce = 10000.0f;
  53. pjd.enableMotor = true;
  54. pjd.lowerTranslation = 0.0f;
  55. pjd.upperTranslation = 20.0f;
  56. pjd.enableLimit = true;
  57. m_joint = (b2PrismaticJoint*)m_world->CreateJoint(&pjd);
  58. }
  59. }
  60. void Keyboard(unsigned char key)
  61. {
  62. switch (key)
  63. {
  64. case 'l':
  65. m_joint->EnableLimit(!m_joint->IsLimitEnabled());
  66. break;
  67. case 'm':
  68. m_joint->EnableMotor(!m_joint->IsMotorEnabled());
  69. break;
  70. case 's':
  71. m_joint->SetMotorSpeed(-m_joint->GetMotorSpeed());
  72. break;
  73. }
  74. }
  75. void Step(Settings* settings)
  76. {
  77. Test::Step(settings);
  78. m_debugDraw.DrawString(5, m_textLine, "Keys: (l) limits, (m) motors, (s) speed");
  79. m_textLine += 15;
  80. float32 force = m_joint->GetMotorForce(settings->hz);
  81. m_debugDraw.DrawString(5, m_textLine, "Motor Force = %4.0f", (float) force);
  82. m_textLine += 15;
  83. }
  84. static Test* Create()
  85. {
  86. return new Prismatic;
  87. }
  88. b2PrismaticJoint* m_joint;
  89. };
  90. #endif