btManifoldPoint.h 5.0 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_MANIFOLD_CONTACT_POINT_H
  14. #define BT_MANIFOLD_CONTACT_POINT_H
  15. #include "LinearMath/btVector3.h"
  16. #include "LinearMath/btTransformUtil.h"
  17. #ifdef PFX_USE_FREE_VECTORMATH
  18. #include "physics_effects/base_level/solver/pfx_constraint_row.h"
  19. typedef sce::PhysicsEffects::PfxConstraintRow btConstraintRow;
  20. #else
  21. // Don't change following order of parameters
  22. ATTRIBUTE_ALIGNED16(struct)
  23. btConstraintRow
  24. {
  25. btScalar m_normal[3];
  26. btScalar m_rhs;
  27. btScalar m_jacDiagInv;
  28. btScalar m_lowerLimit;
  29. btScalar m_upperLimit;
  30. btScalar m_accumImpulse;
  31. };
  32. typedef btConstraintRow PfxConstraintRow;
  33. #endif //PFX_USE_FREE_VECTORMATH
  34. enum btContactPointFlags
  35. {
  36. BT_CONTACT_FLAG_LATERAL_FRICTION_INITIALIZED = 1,
  37. BT_CONTACT_FLAG_HAS_CONTACT_CFM = 2,
  38. BT_CONTACT_FLAG_HAS_CONTACT_ERP = 4,
  39. BT_CONTACT_FLAG_CONTACT_STIFFNESS_DAMPING = 8,
  40. BT_CONTACT_FLAG_FRICTION_ANCHOR = 16,
  41. };
  42. /// ManifoldContactPoint collects and maintains persistent contactpoints.
  43. /// used to improve stability and performance of rigidbody dynamics response.
  44. class btManifoldPoint
  45. {
  46. public:
  47. btManifoldPoint()
  48. : m_userPersistentData(0),
  49. m_contactPointFlags(0),
  50. m_appliedImpulse(0.f),
  51. m_prevRHS(0.f),
  52. m_appliedImpulseLateral1(0.f),
  53. m_appliedImpulseLateral2(0.f),
  54. m_contactMotion1(0.f),
  55. m_contactMotion2(0.f),
  56. m_contactCFM(0.f),
  57. m_contactERP(0.f),
  58. m_frictionCFM(0.f),
  59. m_lifeTime(0)
  60. {
  61. }
  62. btManifoldPoint(const btVector3& pointA, const btVector3& pointB,
  63. const btVector3& normal,
  64. btScalar distance) : m_localPointA(pointA),
  65. m_localPointB(pointB),
  66. m_normalWorldOnB(normal),
  67. m_distance1(distance),
  68. m_combinedFriction(btScalar(0.)),
  69. m_combinedRollingFriction(btScalar(0.)),
  70. m_combinedSpinningFriction(btScalar(0.)),
  71. m_combinedRestitution(btScalar(0.)),
  72. m_userPersistentData(0),
  73. m_contactPointFlags(0),
  74. m_appliedImpulse(0.f),
  75. m_prevRHS(0.f),
  76. m_appliedImpulseLateral1(0.f),
  77. m_appliedImpulseLateral2(0.f),
  78. m_contactMotion1(0.f),
  79. m_contactMotion2(0.f),
  80. m_contactCFM(0.f),
  81. m_contactERP(0.f),
  82. m_frictionCFM(0.f),
  83. m_lifeTime(0)
  84. {
  85. }
  86. btVector3 m_localPointA;
  87. btVector3 m_localPointB;
  88. btVector3 m_positionWorldOnB;
  89. ///m_positionWorldOnA is redundant information, see getPositionWorldOnA(), but for clarity
  90. btVector3 m_positionWorldOnA;
  91. btVector3 m_normalWorldOnB;
  92. btScalar m_distance1;
  93. btScalar m_combinedFriction;
  94. btScalar m_combinedRollingFriction; //torsional friction orthogonal to contact normal, useful to make spheres stop rolling forever
  95. btScalar m_combinedSpinningFriction; //torsional friction around contact normal, useful for grasping objects
  96. btScalar m_combinedRestitution;
  97. //BP mod, store contact triangles.
  98. int m_partId0;
  99. int m_partId1;
  100. int m_index0;
  101. int m_index1;
  102. mutable void* m_userPersistentData;
  103. //bool m_lateralFrictionInitialized;
  104. int m_contactPointFlags;
  105. btScalar m_appliedImpulse;
  106. btScalar m_prevRHS;
  107. btScalar m_appliedImpulseLateral1;
  108. btScalar m_appliedImpulseLateral2;
  109. btScalar m_contactMotion1;
  110. btScalar m_contactMotion2;
  111. union {
  112. btScalar m_contactCFM;
  113. btScalar m_combinedContactStiffness1;
  114. };
  115. union {
  116. btScalar m_contactERP;
  117. btScalar m_combinedContactDamping1;
  118. };
  119. btScalar m_frictionCFM;
  120. int m_lifeTime; //lifetime of the contactpoint in frames
  121. btVector3 m_lateralFrictionDir1;
  122. btVector3 m_lateralFrictionDir2;
  123. btScalar getDistance() const
  124. {
  125. return m_distance1;
  126. }
  127. int getLifeTime() const
  128. {
  129. return m_lifeTime;
  130. }
  131. const btVector3& getPositionWorldOnA() const
  132. {
  133. return m_positionWorldOnA;
  134. // return m_positionWorldOnB + m_normalWorldOnB * m_distance1;
  135. }
  136. const btVector3& getPositionWorldOnB() const
  137. {
  138. return m_positionWorldOnB;
  139. }
  140. void setDistance(btScalar dist)
  141. {
  142. m_distance1 = dist;
  143. }
  144. ///this returns the most recent applied impulse, to satisfy contact constraints by the constraint solver
  145. btScalar getAppliedImpulse() const
  146. {
  147. return m_appliedImpulse;
  148. }
  149. };
  150. #endif //BT_MANIFOLD_CONTACT_POINT_H