btCollisionShape.h 4.8 KB

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