PhysicsSpringConstraint.h 6.5 KB

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