ConstraintWeld2D.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 weld constraint component.
  8. class URHO3D_API ConstraintWeld2D : public Constraint2D
  9. {
  10. URHO3D_OBJECT(ConstraintWeld2D, Constraint2D);
  11. public:
  12. /// Construct.
  13. explicit ConstraintWeld2D(Context* context);
  14. /// Destruct.
  15. ~ConstraintWeld2D() override;
  16. /// Register object factory.
  17. /// @nobind
  18. static void RegisterObject(Context* context);
  19. /// Set anchor.
  20. /// @property
  21. void SetAnchor(const Vector2& anchor);
  22. /// Return anchor.
  23. /// @property
  24. const Vector2& GetAnchor() const { return anchor_; }
  25. /// Set linear stiffness in N/m.
  26. /// @property
  27. void SetStiffness(float stiffness);
  28. /// Return linear stiffness in N/m.
  29. /// @property
  30. float GetStiffness() const { return jointDef_.stiffness; }
  31. /// Set linear damping in N*s/m.
  32. /// @property
  33. void SetDamping(float damping);
  34. /// Return linear damping in N*s/m.
  35. /// @property
  36. float GetDamping() const { return jointDef_.damping; }
  37. /// Calc and set stiffness and damping. Must be used after set owner and other bodies.
  38. bool SetAngularStiffness(float frequencyHertz, float dampingRatio);
  39. private:
  40. /// Return joint def.
  41. b2JointDef* GetJointDef() override;
  42. /// Box2D joint def.
  43. b2WeldJointDef jointDef_;
  44. /// Anchor.
  45. Vector2 anchor_;
  46. };
  47. }