ConstraintMouse2D.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Physics2D/Constraint2D.h"
  5. namespace Urho3D
  6. {
  7. /// 2D mouse constraint component.
  8. class URHO3D_API ConstraintMouse2D : public Constraint2D
  9. {
  10. URHO3D_OBJECT(ConstraintMouse2D, Constraint2D);
  11. public:
  12. /// Construct.
  13. explicit ConstraintMouse2D(Context* context);
  14. /// Destruct.
  15. ~ConstraintMouse2D() override;
  16. /// Register object factory.
  17. /// @nobind
  18. static void RegisterObject(Context* context);
  19. /// Set target.
  20. /// @property
  21. void SetTarget(const Vector2& target);
  22. /// Return target.
  23. /// @property
  24. const Vector2& GetTarget() const { return target_; }
  25. /// Set max force.
  26. /// @property
  27. void SetMaxForce(float maxForce);
  28. /// Return max force.
  29. /// @property
  30. float GetMaxForce() const { return jointDef_.maxForce; }
  31. /// Set linear stiffness in N/m.
  32. /// @property
  33. void SetStiffness(float stiffness);
  34. /// Return linear stiffness in N/m.
  35. /// @property
  36. float GetStiffness() const { return jointDef_.stiffness; }
  37. /// Set linear damping in N*s/m.
  38. /// @property
  39. void SetDamping(float damping);
  40. /// Return linear damping in N*s/m.
  41. /// @property
  42. float GetDamping() const { return jointDef_.damping; }
  43. /// Calc and set stiffness and damping. Must be used after set owner and other bodies.
  44. bool SetLinearStiffness(float frequencyHertz, float dampingRatio);
  45. private:
  46. /// Return joint def.
  47. b2JointDef* GetJointDef() override;
  48. /// Box2D joint def.
  49. b2MouseJointDef jointDef_;
  50. /// Target.
  51. Vector2 target_;
  52. };
  53. }