btPolyhedralConvexShape.h 3.6 KB

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