btPoint2PointConstraint.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef BT_POINT2POINTCONSTRAINT_H
  14. #define BT_POINT2POINTCONSTRAINT_H
  15. #include "bullet/LinearMath/btVector3.h"
  16. #include "btJacobianEntry.h"
  17. #include "btTypedConstraint.h"
  18. class btRigidBody;
  19. #ifdef BT_USE_DOUBLE_PRECISION
  20. #define btPoint2PointConstraintData2 btPoint2PointConstraintDoubleData2
  21. #define btPoint2PointConstraintDataName "btPoint2PointConstraintDoubleData2"
  22. #else
  23. #define btPoint2PointConstraintData2 btPoint2PointConstraintFloatData
  24. #define btPoint2PointConstraintDataName "btPoint2PointConstraintFloatData"
  25. #endif //BT_USE_DOUBLE_PRECISION
  26. struct btConstraintSetting
  27. {
  28. btConstraintSetting() :
  29. m_tau(btScalar(0.3)),
  30. m_damping(btScalar(1.)),
  31. m_impulseClamp(btScalar(0.))
  32. {
  33. }
  34. btScalar m_tau;
  35. btScalar m_damping;
  36. btScalar m_impulseClamp;
  37. };
  38. enum btPoint2PointFlags
  39. {
  40. BT_P2P_FLAGS_ERP = 1,
  41. BT_P2P_FLAGS_CFM = 2
  42. };
  43. /// point to point constraint between two rigidbodies each with a pivotpoint that descibes the 'ballsocket' location in local space
  44. ATTRIBUTE_ALIGNED16(class) btPoint2PointConstraint : public btTypedConstraint
  45. {
  46. #ifdef IN_PARALLELL_SOLVER
  47. public:
  48. #endif
  49. btJacobianEntry m_jac[3]; //3 orthogonal linear constraints
  50. btVector3 m_pivotInA;
  51. btVector3 m_pivotInB;
  52. int m_flags;
  53. btScalar m_erp;
  54. btScalar m_cfm;
  55. public:
  56. BT_DECLARE_ALIGNED_ALLOCATOR();
  57. ///for backwards compatibility during the transition to 'getInfo/getInfo2'
  58. bool m_useSolveConstraintObsolete;
  59. btConstraintSetting m_setting;
  60. btPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB);
  61. btPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA);
  62. virtual void buildJacobian();
  63. virtual void getInfo1 (btConstraintInfo1* info);
  64. void getInfo1NonVirtual (btConstraintInfo1* info);
  65. virtual void getInfo2 (btConstraintInfo2* info);
  66. void getInfo2NonVirtual (btConstraintInfo2* info, const btTransform& body0_trans, const btTransform& body1_trans);
  67. void updateRHS(btScalar timeStep);
  68. void setPivotA(const btVector3& pivotA)
  69. {
  70. m_pivotInA = pivotA;
  71. }
  72. void setPivotB(const btVector3& pivotB)
  73. {
  74. m_pivotInB = pivotB;
  75. }
  76. const btVector3& getPivotInA() const
  77. {
  78. return m_pivotInA;
  79. }
  80. const btVector3& getPivotInB() const
  81. {
  82. return m_pivotInB;
  83. }
  84. ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5).
  85. ///If no axis is provided, it uses the default axis for this constraint.
  86. virtual void setParam(int num, btScalar value, int axis = -1);
  87. ///return the local value of parameter
  88. virtual btScalar getParam(int num, int axis = -1) const;
  89. virtual int calculateSerializeBufferSize() const;
  90. ///fills the dataBuffer and returns the struct name (and 0 on failure)
  91. virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
  92. };
  93. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  94. struct btPoint2PointConstraintFloatData
  95. {
  96. btTypedConstraintData m_typeConstraintData;
  97. btVector3FloatData m_pivotInA;
  98. btVector3FloatData m_pivotInB;
  99. };
  100. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  101. struct btPoint2PointConstraintDoubleData2
  102. {
  103. btTypedConstraintDoubleData m_typeConstraintData;
  104. btVector3DoubleData m_pivotInA;
  105. btVector3DoubleData m_pivotInB;
  106. };
  107. #ifdef BT_BACKWARDS_COMPATIBLE_SERIALIZATION
  108. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  109. ///this structure is not used, except for loading pre-2.82 .bullet files
  110. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  111. struct btPoint2PointConstraintDoubleData
  112. {
  113. btTypedConstraintData m_typeConstraintData;
  114. btVector3DoubleData m_pivotInA;
  115. btVector3DoubleData m_pivotInB;
  116. };
  117. #endif //BT_BACKWARDS_COMPATIBLE_SERIALIZATION
  118. SIMD_FORCE_INLINE int btPoint2PointConstraint::calculateSerializeBufferSize() const
  119. {
  120. return sizeof(btPoint2PointConstraintData2);
  121. }
  122. ///fills the dataBuffer and returns the struct name (and 0 on failure)
  123. SIMD_FORCE_INLINE const char* btPoint2PointConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
  124. {
  125. btPoint2PointConstraintData2* p2pData = (btPoint2PointConstraintData2*)dataBuffer;
  126. btTypedConstraint::serialize(&p2pData->m_typeConstraintData,serializer);
  127. m_pivotInA.serialize(p2pData->m_pivotInA);
  128. m_pivotInB.serialize(p2pData->m_pivotInB);
  129. return btPoint2PointConstraintDataName;
  130. }
  131. #endif //BT_POINT2POINTCONSTRAINT_H