btCollisionShape.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
  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_COLLISION_SHAPE_H
  14. #define BT_COLLISION_SHAPE_H
  15. #include "LinearMath/btTransform.h"
  16. #include "LinearMath/btVector3.h"
  17. #include "LinearMath/btMatrix3x3.h"
  18. #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types
  19. class btSerializer;
  20. ///The btCollisionShape class provides an interface for collision shapes that can be shared among btCollisionObjects.
  21. ATTRIBUTE_ALIGNED16(class)
  22. btCollisionShape
  23. {
  24. protected:
  25. int m_shapeType;
  26. void* m_userPointer;
  27. int m_userIndex;
  28. int m_userIndex2;
  29. public:
  30. BT_DECLARE_ALIGNED_ALLOCATOR();
  31. btCollisionShape() : m_shapeType(INVALID_SHAPE_PROXYTYPE), m_userPointer(0), m_userIndex(-1), m_userIndex2(-1)
  32. {
  33. }
  34. virtual ~btCollisionShape()
  35. {
  36. }
  37. ///getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
  38. virtual void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const = 0;
  39. virtual void getBoundingSphere(btVector3 & center, btScalar & radius) const;
  40. ///getAngularMotionDisc returns the maximum radius needed for Conservative Advancement to handle time-of-impact with rotations.
  41. virtual btScalar getAngularMotionDisc() const;
  42. virtual btScalar getContactBreakingThreshold(btScalar defaultContactThresholdFactor) const;
  43. ///calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep)
  44. ///result is conservative
  45. void calculateTemporalAabb(const btTransform& curTrans, const btVector3& linvel, const btVector3& angvel, btScalar timeStep, btVector3& temporalAabbMin, btVector3& temporalAabbMax) const;
  46. SIMD_FORCE_INLINE bool isPolyhedral() const
  47. {
  48. return btBroadphaseProxy::isPolyhedral(getShapeType());
  49. }
  50. SIMD_FORCE_INLINE bool isConvex2d() const
  51. {
  52. return btBroadphaseProxy::isConvex2d(getShapeType());
  53. }
  54. SIMD_FORCE_INLINE bool isConvex() const
  55. {
  56. return btBroadphaseProxy::isConvex(getShapeType());
  57. }
  58. SIMD_FORCE_INLINE bool isNonMoving() const
  59. {
  60. return btBroadphaseProxy::isNonMoving(getShapeType());
  61. }
  62. SIMD_FORCE_INLINE bool isConcave() const
  63. {
  64. return btBroadphaseProxy::isConcave(getShapeType());
  65. }
  66. SIMD_FORCE_INLINE bool isCompound() const
  67. {
  68. return btBroadphaseProxy::isCompound(getShapeType());
  69. }
  70. SIMD_FORCE_INLINE bool isSoftBody() const
  71. {
  72. return btBroadphaseProxy::isSoftBody(getShapeType());
  73. }
  74. ///isInfinite is used to catch simulation error (aabb check)
  75. SIMD_FORCE_INLINE bool isInfinite() const
  76. {
  77. return btBroadphaseProxy::isInfinite(getShapeType());
  78. }
  79. #ifndef __SPU__
  80. virtual void setLocalScaling(const btVector3& scaling) = 0;
  81. virtual const btVector3& getLocalScaling() const = 0;
  82. virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const = 0;
  83. //debugging support
  84. virtual const char* getName() const = 0;
  85. #endif //__SPU__
  86. int getShapeType() const
  87. {
  88. return m_shapeType;
  89. }
  90. ///the getAnisotropicRollingFrictionDirection can be used in combination with setAnisotropicFriction
  91. ///See Bullet/Demos/RollingFrictionDemo for an example
  92. virtual btVector3 getAnisotropicRollingFrictionDirection() const
  93. {
  94. return btVector3(1, 1, 1);
  95. }
  96. virtual void setMargin(btScalar margin) = 0;
  97. virtual btScalar getMargin() const = 0;
  98. ///optional user data pointer
  99. void setUserPointer(void* userPtr)
  100. {
  101. m_userPointer = userPtr;
  102. }
  103. void* getUserPointer() const
  104. {
  105. return m_userPointer;
  106. }
  107. void setUserIndex(int index)
  108. {
  109. m_userIndex = index;
  110. }
  111. int getUserIndex() const
  112. {
  113. return m_userIndex;
  114. }
  115. void setUserIndex2(int index)
  116. {
  117. m_userIndex2 = index;
  118. }
  119. int getUserIndex2() const
  120. {
  121. return m_userIndex2;
  122. }
  123. virtual int calculateSerializeBufferSize() const;
  124. ///fills the dataBuffer and returns the struct name (and 0 on failure)
  125. virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
  126. virtual void serializeSingleShape(btSerializer * serializer) const;
  127. };
  128. // clang-format off
  129. // parser needs * with the name
  130. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  131. struct btCollisionShapeData
  132. {
  133. char *m_name;
  134. int m_shapeType;
  135. char m_padding[4];
  136. };
  137. // clang-format on
  138. SIMD_FORCE_INLINE int btCollisionShape::calculateSerializeBufferSize() const
  139. {
  140. return sizeof(btCollisionShapeData);
  141. }
  142. #endif //BT_COLLISION_SHAPE_H