btPolyhedralConvexShape.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_POLYHEDRAL_CONVEX_SHAPE_H
  14. #define BT_POLYHEDRAL_CONVEX_SHAPE_H
  15. #include "LinearMath/btMatrix3x3.h"
  16. #include "btConvexInternalShape.h"
  17. class btConvexPolyhedron;
  18. ///The btPolyhedralConvexShape is an internal interface class for polyhedral convex shapes.
  19. ATTRIBUTE_ALIGNED16(class)
  20. btPolyhedralConvexShape : public btConvexInternalShape
  21. {
  22. protected:
  23. btConvexPolyhedron* m_polyhedron;
  24. public:
  25. BT_DECLARE_ALIGNED_ALLOCATOR();
  26. btPolyhedralConvexShape();
  27. virtual ~btPolyhedralConvexShape();
  28. ///optional method mainly used to generate multiple contact points by clipping polyhedral features (faces/edges)
  29. ///experimental/work-in-progress
  30. virtual bool initializePolyhedralFeatures(int shiftVerticesByMargin = 0);
  31. virtual void setPolyhedralFeatures(btConvexPolyhedron & polyhedron);
  32. const btConvexPolyhedron* getConvexPolyhedron() const
  33. {
  34. return m_polyhedron;
  35. }
  36. //brute force implementations
  37. virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const;
  38. virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const;
  39. virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const;
  40. virtual int getNumVertices() const = 0;
  41. virtual int getNumEdges() const = 0;
  42. virtual void getEdge(int i, btVector3& pa, btVector3& pb) const = 0;
  43. virtual void getVertex(int i, btVector3& vtx) const = 0;
  44. virtual int getNumPlanes() const = 0;
  45. virtual void getPlane(btVector3 & planeNormal, btVector3 & planeSupport, int i) const = 0;
  46. // virtual int getIndex(int i) const = 0 ;
  47. virtual bool isInside(const btVector3& pt, btScalar tolerance) const = 0;
  48. };
  49. ///The btPolyhedralConvexAabbCachingShape adds aabb caching to the btPolyhedralConvexShape
  50. class btPolyhedralConvexAabbCachingShape : public btPolyhedralConvexShape
  51. {
  52. btVector3 m_localAabbMin;
  53. btVector3 m_localAabbMax;
  54. bool m_isLocalAabbValid;
  55. protected:
  56. void setCachedLocalAabb(const btVector3& aabbMin, const btVector3& aabbMax)
  57. {
  58. m_isLocalAabbValid = true;
  59. m_localAabbMin = aabbMin;
  60. m_localAabbMax = aabbMax;
  61. }
  62. inline void getCachedLocalAabb(btVector3& aabbMin, btVector3& aabbMax) const
  63. {
  64. btAssert(m_isLocalAabbValid);
  65. aabbMin = m_localAabbMin;
  66. aabbMax = m_localAabbMax;
  67. }
  68. protected:
  69. btPolyhedralConvexAabbCachingShape();
  70. public:
  71. inline void getNonvirtualAabb(const btTransform& trans, btVector3& aabbMin, btVector3& aabbMax, btScalar margin) const
  72. {
  73. //lazy evaluation of local aabb
  74. btAssert(m_isLocalAabbValid);
  75. btTransformAabb(m_localAabbMin, m_localAabbMax, margin, trans, aabbMin, aabbMax);
  76. }
  77. virtual void setLocalScaling(const btVector3& scaling);
  78. virtual void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
  79. void recalcLocalAabb();
  80. };
  81. #endif //BT_POLYHEDRAL_CONVEX_SHAPE_H