ConstraintDistance2D.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 distance constraint component.
  8. class URHO3D_API ConstraintDistance2D : public Constraint2D
  9. {
  10. URHO3D_OBJECT(ConstraintDistance2D, Constraint2D);
  11. public:
  12. /// Construct.
  13. explicit ConstraintDistance2D(Context* context);
  14. /// Destruct.
  15. ~ConstraintDistance2D() override;
  16. /// Register object factory.
  17. /// @nobind
  18. static void RegisterObject(Context* context);
  19. /// Set owner body anchor.
  20. /// @property
  21. void SetOwnerBodyAnchor(const Vector2& anchor);
  22. /// Return owner body anchor.
  23. /// @property
  24. const Vector2& GetOwnerBodyAnchor() const { return ownerBodyAnchor_; }
  25. /// Set other body anchor.
  26. /// @property
  27. void SetOtherBodyAnchor(const Vector2& anchor);
  28. /// Return other body anchor.
  29. /// @property
  30. const Vector2& GetOtherBodyAnchor() const { return otherBodyAnchor_; }
  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. /// Set length.
  44. /// @property
  45. void SetLength(float length);
  46. /// Return length.
  47. /// @property
  48. float GetLength() const { return jointDef_.length; }
  49. /// Set min length.
  50. /// @property
  51. void SetMinLength(float minLength);
  52. /// Return min length.
  53. /// @property
  54. float GetMinLength() const { return jointDef_.minLength; }
  55. /// Set max length.
  56. /// @property
  57. void SetMaxLength(float maxLength);
  58. /// Return max length.
  59. /// @property
  60. float GetMaxLength() const { return jointDef_.maxLength; }
  61. /// Calc and set stiffness and damping. Must be used after set owner and other bodies.
  62. bool SetLinearStiffness(float frequencyHertz, float dampingRatio);
  63. private:
  64. /// Return joint def.
  65. b2JointDef* GetJointDef() override;
  66. /// Box2D joint def.
  67. b2DistanceJointDef jointDef_;
  68. /// Owner body anchor.
  69. Vector2 ownerBodyAnchor_;
  70. /// Other body anchor.
  71. Vector2 otherBodyAnchor_;
  72. };
  73. }