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.

127 lines
3.6KB

  1. /*
  2. * Copyright (c) 2006-2007 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 B2_MOUSE_JOINT_H
  19. #define B2_MOUSE_JOINT_H
  20. #include "b2Joint.h"
  21. /// Mouse joint definition. This requires a world target point,
  22. /// tuning parameters, and the time step.
  23. struct b2MouseJointDef : public b2JointDef
  24. {
  25. b2MouseJointDef()
  26. {
  27. type = e_mouseJoint;
  28. target.Set(0.0f, 0.0f);
  29. maxForce = 0.0f;
  30. frequencyHz = 5.0f;
  31. dampingRatio = 0.7f;
  32. }
  33. /// The initial world target point. This is assumed
  34. /// to coincide with the body anchor initially.
  35. b2Vec2 target;
  36. /// The maximum constraint force that can be exerted
  37. /// to move the candidate body. Usually you will express
  38. /// as some multiple of the weight (multiplier * mass * gravity).
  39. float32 maxForce;
  40. /// The response speed.
  41. float32 frequencyHz;
  42. /// The damping ratio. 0 = no damping, 1 = critical damping.
  43. float32 dampingRatio;
  44. };
  45. /// A mouse joint is used to make a point on a body track a
  46. /// specified world point. This a soft constraint with a maximum
  47. /// force. This allows the constraint to stretch and without
  48. /// applying huge forces.
  49. /// NOTE: this joint is not documented in the manual because it was
  50. /// developed to be used in the testbed. If you want to learn how to
  51. /// use the mouse joint, look at the testbed.
  52. class b2MouseJoint : public b2Joint
  53. {
  54. public:
  55. /// Implements b2Joint.
  56. b2Vec2 GetAnchorA() const;
  57. /// Implements b2Joint.
  58. b2Vec2 GetAnchorB() const;
  59. /// Implements b2Joint.
  60. b2Vec2 GetReactionForce(float32 inv_dt) const;
  61. /// Implements b2Joint.
  62. float32 GetReactionTorque(float32 inv_dt) const;
  63. /// Use this to update the target point.
  64. void SetTarget(const b2Vec2& target);
  65. const b2Vec2& GetTarget() const;
  66. /// Set/get the maximum force in Newtons.
  67. void SetMaxForce(float32 force);
  68. float32 GetMaxForce() const;
  69. /// Set/get the frequency in Hertz.
  70. void SetFrequency(float32 hz);
  71. float32 GetFrequency() const;
  72. /// Set/get the damping ratio (dimensionless).
  73. void SetDampingRatio(float32 ratio);
  74. float32 GetDampingRatio() const;
  75. /// The mouse joint does not support dumping.
  76. void Dump() { b2Log("Mouse joint dumping is not supported.\n"); }
  77. protected:
  78. friend class b2Joint;
  79. b2MouseJoint(const b2MouseJointDef* def);
  80. void InitVelocityConstraints(const b2SolverData& data);
  81. void SolveVelocityConstraints(const b2SolverData& data);
  82. bool SolvePositionConstraints(const b2SolverData& data);
  83. b2Vec2 m_localAnchorB;
  84. b2Vec2 m_targetA;
  85. float32 m_frequencyHz;
  86. float32 m_dampingRatio;
  87. float32 m_beta;
  88. // Solver shared
  89. b2Vec2 m_impulse;
  90. float32 m_maxForce;
  91. float32 m_gamma;
  92. // Solver temp
  93. juce::int32 m_indexA;
  94. juce::int32 m_indexB;
  95. b2Vec2 m_rB;
  96. b2Vec2 m_localCenterB;
  97. float32 m_invMassB;
  98. float32 m_invIB;
  99. b2Mat22 m_mass;
  100. b2Vec2 m_C;
  101. };
  102. #endif