ConstraintWheel2D.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 wheel constraint component.
  8. class URHO3D_API ConstraintWheel2D : public Constraint2D
  9. {
  10. URHO3D_OBJECT(ConstraintWheel2D, Constraint2D);
  11. public:
  12. /// Construct.
  13. explicit ConstraintWheel2D(Context* context);
  14. /// Destruct.
  15. ~ConstraintWheel2D() 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 axis.
  26. /// @property
  27. void SetAxis(const Vector2& axis);
  28. /// Return axis.
  29. /// @property
  30. const Vector2& GetAxis() const { return axis_; }
  31. /// Set enable motor.
  32. /// @property
  33. void SetEnableMotor(bool enableMotor);
  34. /// Return enable motor.
  35. /// @property
  36. bool GetEnableMotor() const { return jointDef_.enableMotor; }
  37. /// Set max motor torque.
  38. /// @property
  39. void SetMaxMotorTorque(float maxMotorTorque);
  40. /// Return maxMotor torque.
  41. /// @property
  42. float GetMaxMotorTorque() const { return jointDef_.maxMotorTorque; }
  43. /// Set motor speed.
  44. /// @property
  45. void SetMotorSpeed(float motorSpeed);
  46. /// Return motor speed.
  47. /// @property
  48. float GetMotorSpeed() const { return jointDef_.motorSpeed; }
  49. /// Set linear stiffness in N/m.
  50. /// @property
  51. void SetStiffness(float stiffness);
  52. /// Return linear stiffness in N/m.
  53. /// @property
  54. float GetStiffness() const { return jointDef_.stiffness; }
  55. /// Set linear damping in N*s/m.
  56. /// @property
  57. void SetDamping(float damping);
  58. /// Return linear damping in N*s/m.
  59. /// @property
  60. float GetDamping() const { return jointDef_.damping; }
  61. /// Set enable limit.
  62. /// @property
  63. void SetEnableLimit(bool enableLimit);
  64. /// Return enable limit.
  65. /// @property
  66. bool GetEnableLimit() const { return jointDef_.enableLimit; }
  67. /// Set lower translation.
  68. /// @property
  69. void SetLowerTranslation(float lowerTranslation);
  70. /// Return lower translation.
  71. /// @property
  72. float GetLowerTranslation() const { return jointDef_.lowerTranslation; }
  73. /// Set upper translation.
  74. /// @property
  75. void SetUpperTranslation(float upperTranslation);
  76. /// Return upper translation.
  77. /// @property
  78. float GetUpperTranslation() const { return jointDef_.upperTranslation; }
  79. /// Calc and set stiffness and damping. Must be used after set owner and other bodies.
  80. bool SetLinearStiffness(float frequencyHertz, float dampingRatio);
  81. private:
  82. /// Return joint def.
  83. b2JointDef* GetJointDef() override;
  84. /// Box2D joint def.
  85. b2WheelJointDef jointDef_;
  86. /// Anchor.
  87. Vector2 anchor_;
  88. /// Axis.
  89. Vector2 axis_;
  90. };
  91. }