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