btCollisionShape.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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) btCollisionShape
  22. {
  23. protected:
  24. int m_shapeType;
  25. void* m_userPointer;
  26. int m_userIndex;
  27. public:
  28. BT_DECLARE_ALIGNED_ALLOCATOR();
  29. btCollisionShape() : m_shapeType (INVALID_SHAPE_PROXYTYPE), m_userPointer(0), m_userIndex(-1)
  30. {
  31. }
  32. virtual ~btCollisionShape()
  33. {
  34. }
  35. ///getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
  36. virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const =0;
  37. virtual void getBoundingSphere(btVector3& center,btScalar& radius) const;
  38. ///getAngularMotionDisc returns the maximus radius needed for Conservative Advancement to handle time-of-impact with rotations.
  39. virtual btScalar getAngularMotionDisc() const;
  40. virtual btScalar getContactBreakingThreshold(btScalar defaultContactThresholdFactor) const;
  41. ///calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep)
  42. ///result is conservative
  43. void calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const;
  44. SIMD_FORCE_INLINE bool isPolyhedral() const
  45. {
  46. return btBroadphaseProxy::isPolyhedral(getShapeType());
  47. }
  48. SIMD_FORCE_INLINE bool isConvex2d() const
  49. {
  50. return btBroadphaseProxy::isConvex2d(getShapeType());
  51. }
  52. SIMD_FORCE_INLINE bool isConvex() const
  53. {
  54. return btBroadphaseProxy::isConvex(getShapeType());
  55. }
  56. SIMD_FORCE_INLINE bool isNonMoving() const
  57. {
  58. return btBroadphaseProxy::isNonMoving(getShapeType());
  59. }
  60. SIMD_FORCE_INLINE bool isConcave() const
  61. {
  62. return btBroadphaseProxy::isConcave(getShapeType());
  63. }
  64. SIMD_FORCE_INLINE bool isCompound() const
  65. {
  66. return btBroadphaseProxy::isCompound(getShapeType());
  67. }
  68. SIMD_FORCE_INLINE bool isSoftBody() const
  69. {
  70. return btBroadphaseProxy::isSoftBody(getShapeType());
  71. }
  72. ///isInfinite is used to catch simulation error (aabb check)
  73. SIMD_FORCE_INLINE bool isInfinite() const
  74. {
  75. return btBroadphaseProxy::isInfinite(getShapeType());
  76. }
  77. #ifndef __SPU__
  78. virtual void setLocalScaling(const btVector3& scaling) =0;
  79. virtual const btVector3& getLocalScaling() const =0;
  80. virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const = 0;
  81. //debugging support
  82. virtual const char* getName()const =0 ;
  83. #endif //__SPU__
  84. int getShapeType() const { return m_shapeType; }
  85. ///the getAnisotropicRollingFrictionDirection can be used in combination with setAnisotropicFriction
  86. ///See Bullet/Demos/RollingFrictionDemo for an example
  87. virtual btVector3 getAnisotropicRollingFrictionDirection() const
  88. {
  89. return btVector3(1,1,1);
  90. }
  91. virtual void setMargin(btScalar margin) = 0;
  92. virtual btScalar getMargin() const = 0;
  93. ///optional user data pointer
  94. void setUserPointer(void* userPtr)
  95. {
  96. m_userPointer = userPtr;
  97. }
  98. void* getUserPointer() const
  99. {
  100. return m_userPointer;
  101. }
  102. void setUserIndex(int index)
  103. {
  104. m_userIndex = index;
  105. }
  106. int getUserIndex() const
  107. {
  108. return m_userIndex;
  109. }
  110. virtual int calculateSerializeBufferSize() const;
  111. ///fills the dataBuffer and returns the struct name (and 0 on failure)
  112. virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
  113. virtual void serializeSingleShape(btSerializer* serializer) const;
  114. };
  115. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  116. struct btCollisionShapeData
  117. {
  118. char *m_name;
  119. int m_shapeType;
  120. char m_padding[4];
  121. };
  122. SIMD_FORCE_INLINE int btCollisionShape::calculateSerializeBufferSize() const
  123. {
  124. return sizeof(btCollisionShapeData);
  125. }
  126. #endif //BT_COLLISION_SHAPE_H