BsHingeJoint.h 3.3 KB

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