Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

151 рядки
4.4 KiB

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