BsHingeJoint.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsJoint.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup Physics
  9. * @{
  10. */
  11. /** Hinge joint removes all but a single rotation degree of freedom from its two attached bodies (e.g. a door hinge). */
  12. class BS_CORE_EXPORT HingeJoint : public Joint
  13. {
  14. public:
  15. /** Flags that control hinge joint options. */
  16. enum class Flag
  17. {
  18. Limit = 0x1, /** Joint limit is enabled. */
  19. Drive = 0x2 /** Joint drive is enabled. */
  20. };
  21. /** Properties of a drive that drives the joint's angular velocity towards a paricular value. */
  22. struct Drive
  23. {
  24. /** Target speed of the joint. */
  25. float speed = 0.0f;
  26. /** Maximum torque the drive is allowed to apply .*/
  27. float forceLimit = FLT_MAX;
  28. /** Scales the velocity of the first body, and its response to drive torque is scaled down. */
  29. float gearRatio = 1.0f;
  30. /**
  31. * If the joint is moving faster than the drive's target speed, the drive will try to break. If you don't want
  32. * the breaking to happen set this to true.
  33. */
  34. bool freeSpin = false;
  35. bool operator==(const Drive& other) const
  36. {
  37. return speed == other.speed && forceLimit == other.forceLimit && gearRatio == other.gearRatio &&
  38. freeSpin && other.freeSpin;
  39. }
  40. };
  41. public:
  42. virtual ~HingeJoint() { }
  43. /** Returns the current angle between the two attached bodes. */
  44. virtual Radian getAngle() const = 0;
  45. /** Returns the current angular speed of the joint. */
  46. virtual float getSpeed() const = 0;
  47. /**
  48. * Returns the limit of the joint. Limit constrains the motion to the specified angle range. You must enable the
  49. * limit flag on the joint in order for this to be recognized.
  50. *
  51. * @see LimitAngularRange
  52. */
  53. virtual LimitAngularRange getLimit() const = 0;
  54. /**
  55. * Sets the limit of the joint. Limit constrains the motion to the specified angle range. You must enable the limit
  56. * flag on the joint in order for this to be recognized.
  57. *
  58. * @see LimitAngularRange
  59. */
  60. virtual void setLimit(const LimitAngularRange& limit) = 0;
  61. /**
  62. * Returns the drive of the joint. It drives the joint's angular velocity towards a particular value. You must
  63. * enable the drive flag on the joint in order for this to be recognized.
  64. *
  65. * @see HingeJoint::Drive
  66. */
  67. virtual Drive getDrive() const = 0;
  68. /**
  69. * Sets the drive of the joint. It drives the joint's angular velocity towards a particular value. You must enable
  70. * the drive flag on the joint in order for this to be recognized.
  71. *
  72. * @see HingeJoint::Drive
  73. */
  74. virtual void setDrive(const Drive& drive) = 0;
  75. /** Enables or disables a flag that controls joint behaviour. */
  76. virtual void setFlag(Flag flag, bool enabled) = 0;
  77. /** Checks is the specified option enabled. */
  78. virtual bool hasFlag(Flag flag) const = 0;
  79. /** Creates a new hinge joint. */
  80. static SPtr<HingeJoint> create();
  81. };
  82. /** @} */
  83. }