b3Point2PointConstraint.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 B3_POINT2POINTCONSTRAINT_H
  14. #define B3_POINT2POINTCONSTRAINT_H
  15. #include "Bullet3Common/b3Vector3.h"
  16. //#include "b3JacobianEntry.h"
  17. #include "b3TypedConstraint.h"
  18. class b3RigidBody;
  19. #ifdef B3_USE_DOUBLE_PRECISION
  20. #define b3Point2PointConstraintData b3Point2PointConstraintDoubleData
  21. #define b3Point2PointConstraintDataName "b3Point2PointConstraintDoubleData"
  22. #else
  23. #define b3Point2PointConstraintData b3Point2PointConstraintFloatData
  24. #define b3Point2PointConstraintDataName "b3Point2PointConstraintFloatData"
  25. #endif //B3_USE_DOUBLE_PRECISION
  26. struct b3ConstraintSetting
  27. {
  28. b3ConstraintSetting() :
  29. m_tau(b3Scalar(0.3)),
  30. m_damping(b3Scalar(1.)),
  31. m_impulseClamp(b3Scalar(0.))
  32. {
  33. }
  34. b3Scalar m_tau;
  35. b3Scalar m_damping;
  36. b3Scalar m_impulseClamp;
  37. };
  38. enum b3Point2PointFlags
  39. {
  40. B3_P2P_FLAGS_ERP = 1,
  41. B3_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. B3_ATTRIBUTE_ALIGNED16(class) b3Point2PointConstraint : public b3TypedConstraint
  45. {
  46. #ifdef IN_PARALLELL_SOLVER
  47. public:
  48. #endif
  49. b3Vector3 m_pivotInA;
  50. b3Vector3 m_pivotInB;
  51. int m_flags;
  52. b3Scalar m_erp;
  53. b3Scalar m_cfm;
  54. public:
  55. B3_DECLARE_ALIGNED_ALLOCATOR();
  56. b3ConstraintSetting m_setting;
  57. b3Point2PointConstraint(int rbA,int rbB, const b3Vector3& pivotInA,const b3Vector3& pivotInB);
  58. //b3Point2PointConstraint(int rbA,const b3Vector3& pivotInA);
  59. virtual void getInfo1 (b3ConstraintInfo1* info,const b3RigidBodyData* bodies);
  60. void getInfo1NonVirtual (b3ConstraintInfo1* info,const b3RigidBodyData* bodies);
  61. virtual void getInfo2 (b3ConstraintInfo2* info, const b3RigidBodyData* bodies);
  62. void getInfo2NonVirtual (b3ConstraintInfo2* info, const b3Transform& body0_trans, const b3Transform& body1_trans);
  63. void updateRHS(b3Scalar timeStep);
  64. void setPivotA(const b3Vector3& pivotA)
  65. {
  66. m_pivotInA = pivotA;
  67. }
  68. void setPivotB(const b3Vector3& pivotB)
  69. {
  70. m_pivotInB = pivotB;
  71. }
  72. const b3Vector3& getPivotInA() const
  73. {
  74. return m_pivotInA;
  75. }
  76. const b3Vector3& getPivotInB() const
  77. {
  78. return m_pivotInB;
  79. }
  80. ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5).
  81. ///If no axis is provided, it uses the default axis for this constraint.
  82. virtual void setParam(int num, b3Scalar value, int axis = -1);
  83. ///return the local value of parameter
  84. virtual b3Scalar getParam(int num, int axis = -1) const;
  85. // virtual int calculateSerializeBufferSize() const;
  86. ///fills the dataBuffer and returns the struct name (and 0 on failure)
  87. // virtual const char* serialize(void* dataBuffer, b3Serializer* serializer) const;
  88. };
  89. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  90. struct b3Point2PointConstraintFloatData
  91. {
  92. b3TypedConstraintData m_typeConstraintData;
  93. b3Vector3FloatData m_pivotInA;
  94. b3Vector3FloatData m_pivotInB;
  95. };
  96. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  97. struct b3Point2PointConstraintDoubleData
  98. {
  99. b3TypedConstraintData m_typeConstraintData;
  100. b3Vector3DoubleData m_pivotInA;
  101. b3Vector3DoubleData m_pivotInB;
  102. };
  103. /*
  104. B3_FORCE_INLINE int b3Point2PointConstraint::calculateSerializeBufferSize() const
  105. {
  106. return sizeof(b3Point2PointConstraintData);
  107. }
  108. ///fills the dataBuffer and returns the struct name (and 0 on failure)
  109. B3_FORCE_INLINE const char* b3Point2PointConstraint::serialize(void* dataBuffer, b3Serializer* serializer) const
  110. {
  111. b3Point2PointConstraintData* p2pData = (b3Point2PointConstraintData*)dataBuffer;
  112. b3TypedConstraint::serialize(&p2pData->m_typeConstraintData,serializer);
  113. m_pivotInA.serialize(p2pData->m_pivotInA);
  114. m_pivotInB.serialize(p2pData->m_pivotInB);
  115. return b3Point2PointConstraintDataName;
  116. }
  117. */
  118. #endif //B3_POINT2POINTCONSTRAINT_H