PhysicsSpringConstraint.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #ifndef PHYSICSSPRINGCONSTRAINT_H_
  2. #define PHYSICSSPRINGCONSTRAINT_H_
  3. #include "PhysicsGenericConstraint.h"
  4. namespace gameplay
  5. {
  6. /**
  7. * Represents a generic spring constraint between two
  8. * rigid bodies (or one rigid body and the world)
  9. * where the spring strength and damping can be set
  10. * for all six degrees of freedom.
  11. */
  12. class PhysicsSpringConstraint : public PhysicsGenericConstraint
  13. {
  14. friend class PhysicsController;
  15. public:
  16. /**
  17. * Sets the angular damping along the constraint's local X axis.
  18. *
  19. * @param damping The angular damping value.
  20. */
  21. inline void setAngularDampingX(float damping);
  22. /**
  23. * Sets the angular damping along the constraint's local Y axis.
  24. *
  25. * @param damping The angular damping value.
  26. */
  27. inline void setAngularDampingY(float damping);
  28. /**
  29. * Sets the angular damping along the constraint's local Z axis.
  30. *
  31. * @param damping The angular damping value.
  32. */
  33. inline void setAngularDampingZ(float damping);
  34. /**
  35. * Sets the angular strength along the constraint's local X axis.
  36. *
  37. * Note: setting the strength to a non-zero value enables the
  38. * spring for angular movement about the X axis (setting to zero disables it).
  39. *
  40. * @param strength The angular strength value.
  41. */
  42. inline void setAngularStrengthX(float strength);
  43. /**
  44. * Sets the angular strength along the constraint's local Y axis.
  45. *
  46. * Note: setting the strength to a non-zero value enables the
  47. * spring for angular movement about the Y axis (setting to zero disables it).
  48. *
  49. * @param strength The angular strength value.
  50. */
  51. inline void setAngularStrengthY(float strength);
  52. /**
  53. * Sets the angular strength along the constraint's local Z axis.
  54. *
  55. * Note: setting the strength to a non-zero value enables the
  56. * spring for angular movement about the Z axis (setting to zero disables it).
  57. *
  58. * @param strength The angular strength value.
  59. */
  60. inline void setAngularStrengthZ(float strength);
  61. /**
  62. * Sets the linear damping along the constraint's local X axis.
  63. *
  64. * @param damping The linear damping value.
  65. */
  66. inline void setLinearDampingX(float damping);
  67. /**
  68. * Sets the linear damping along the constraint's local Y axis.
  69. *
  70. * @param damping The linear damping value.
  71. */
  72. inline void setLinearDampingY(float damping);
  73. /**
  74. * Sets the linear damping along the constraint's local Z axis.
  75. *
  76. * @param damping The linear damping value.
  77. */
  78. inline void setLinearDampingZ(float damping);
  79. /**
  80. * Sets the linear strength along the constraint's local X axis.
  81. *
  82. * Note: setting the strength to a non-zero value enables the
  83. * spring for linear movement along the X axis (setting to zero disables it).
  84. *
  85. * @param strength The linear strength value.
  86. */
  87. inline void setLinearStrengthX(float strength);
  88. /**
  89. * Sets the linear strength along the constraint's local Y axis.
  90. *
  91. * Note: setting the strength to a non-zero value enables the
  92. * spring for linear movement along the Y axis (setting to zero disables it).
  93. *
  94. * @param strength The linear strength value.
  95. */
  96. inline void setLinearStrengthY(float strength);
  97. /**
  98. * Sets the linear strength along the constraint's local Z axis.
  99. *
  100. * Note: setting the strength to a non-zero value enables the
  101. * spring for linear movement along the Z axis (setting to zero disables it).
  102. *
  103. * @param strength The linear strength value.
  104. */
  105. inline void setLinearStrengthZ(float strength);
  106. private:
  107. // Represents the different properties that
  108. // can be set on the spring constraint.
  109. //
  110. // (Note: the values map to the index parameter
  111. // used in the member functions of the Bullet
  112. // class btGeneric6DofSpringConstraint.)
  113. enum SpringProperty
  114. {
  115. LINEAR_X = 0,
  116. LINEAR_Y,
  117. LINEAR_Z,
  118. ANGULAR_X,
  119. ANGULAR_Y,
  120. ANGULAR_Z
  121. };
  122. /**
  123. * Creates a spring constraint so that the rigid body (or bodies) is
  124. * (are) constrained using its (their) current world position(s) for
  125. * the translation offset(s) to the constraint.
  126. *
  127. * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
  128. * body specified the constraint applies between it and the global physics world object.
  129. * @param b The second rigid body to constrain (optional).
  130. */
  131. PhysicsSpringConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b);
  132. /**
  133. * Creates a spring constraint.
  134. *
  135. * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
  136. * body specified the constraint applies between it and the global physics world object.
  137. * @param rotationOffsetA The rotation offset for the first rigid body
  138. * (in its local space) with respect to the constraint joint.
  139. * @param translationOffsetA The translation offset for the first rigid body
  140. * (in its local space) with respect to the constraint joint.
  141. * @param b The second rigid body to constrain (optional).
  142. * @param rotationOffsetB The rotation offset for the second rigid body
  143. * (in its local space) with respect to the constraint joint (optional).
  144. * @param translationOffsetB The translation offset for the second rigid body
  145. * (in its local space) with respect to the constraint joint (optional).
  146. */
  147. PhysicsSpringConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,
  148. PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB);
  149. /**
  150. * Destructor.
  151. */
  152. ~PhysicsSpringConstraint();
  153. // Sets the strength for the given angular/linear
  154. // X/Y/Z axis combination determined by the given index.
  155. //
  156. // See the Bullet class btGeneric6DofSpringConstraint
  157. // for more information.
  158. void setStrength(SpringProperty property, float strength);
  159. // Sets the damping for the given angular/linear
  160. // X/Y/Z axis combination determined by the given index.
  161. //
  162. // See the Bullet class btGeneric6DofSpringConstraint
  163. // for more information.
  164. void setDamping(SpringProperty property, float damping);
  165. };
  166. }
  167. #include "PhysicsSpringConstraint.inl"
  168. #endif