[7983] | 1 | /* |
---|
| 2 | Bullet Continuous Collision Detection and Physics Library |
---|
| 3 | Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org |
---|
[1963] | 4 | |
---|
[7983] | 5 | This software is provided 'as-is', without any express or implied warranty. |
---|
| 6 | In no event will the authors be held liable for any damages arising from the use of this software. |
---|
| 7 | Permission is granted to anyone to use this software for any purpose, |
---|
| 8 | including commercial applications, and to alter it and redistribute it freely, |
---|
| 9 | subject to the following restrictions: |
---|
| 10 | |
---|
| 11 | 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. |
---|
| 12 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. |
---|
| 13 | 3. This notice may not be removed or altered from any source distribution. |
---|
| 14 | */ |
---|
| 15 | |
---|
[1963] | 16 | #ifndef BT_CONVEX_INTERNAL_SHAPE_H |
---|
| 17 | #define BT_CONVEX_INTERNAL_SHAPE_H |
---|
| 18 | |
---|
| 19 | #include "btConvexShape.h" |
---|
[7983] | 20 | #include "LinearMath/btAabbUtil2.h" |
---|
[1963] | 21 | |
---|
[7983] | 22 | |
---|
[1963] | 23 | ///The btConvexInternalShape is an internal base class, shared by most convex shape implementations. |
---|
| 24 | class btConvexInternalShape : public btConvexShape |
---|
| 25 | { |
---|
| 26 | |
---|
| 27 | protected: |
---|
| 28 | |
---|
| 29 | //local scaling. collisionMargin is not scaled ! |
---|
| 30 | btVector3 m_localScaling; |
---|
| 31 | |
---|
| 32 | btVector3 m_implicitShapeDimensions; |
---|
| 33 | |
---|
| 34 | btScalar m_collisionMargin; |
---|
| 35 | |
---|
| 36 | btScalar m_padding; |
---|
| 37 | |
---|
| 38 | btConvexInternalShape(); |
---|
| 39 | |
---|
| 40 | public: |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | virtual ~btConvexInternalShape() |
---|
| 45 | { |
---|
| 46 | |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | virtual btVector3 localGetSupportingVertex(const btVector3& vec)const; |
---|
| 50 | |
---|
| 51 | const btVector3& getImplicitShapeDimensions() const |
---|
| 52 | { |
---|
| 53 | return m_implicitShapeDimensions; |
---|
| 54 | } |
---|
| 55 | |
---|
[7983] | 56 | ///warning: use setImplicitShapeDimensions with care |
---|
| 57 | ///changing a collision shape while the body is in the world is not recommended, |
---|
| 58 | ///it is best to remove the body from the world, then make the change, and re-add it |
---|
| 59 | ///alternatively flush the contact points, see documentation for 'cleanProxyFromPairs' |
---|
| 60 | void setImplicitShapeDimensions(const btVector3& dimensions) |
---|
| 61 | { |
---|
| 62 | m_implicitShapeDimensions = dimensions; |
---|
| 63 | } |
---|
| 64 | |
---|
[1963] | 65 | ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version |
---|
| 66 | void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const |
---|
| 67 | { |
---|
| 68 | getAabbSlow(t,aabbMin,aabbMax); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | virtual void getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | virtual void setLocalScaling(const btVector3& scaling); |
---|
| 77 | virtual const btVector3& getLocalScaling() const |
---|
| 78 | { |
---|
| 79 | return m_localScaling; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | const btVector3& getLocalScalingNV() const |
---|
| 83 | { |
---|
| 84 | return m_localScaling; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | virtual void setMargin(btScalar margin) |
---|
| 88 | { |
---|
| 89 | m_collisionMargin = margin; |
---|
| 90 | } |
---|
| 91 | virtual btScalar getMargin() const |
---|
| 92 | { |
---|
| 93 | return m_collisionMargin; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | btScalar getMarginNV() const |
---|
| 97 | { |
---|
| 98 | return m_collisionMargin; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | virtual int getNumPreferredPenetrationDirections() const |
---|
| 102 | { |
---|
| 103 | return 0; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const |
---|
| 107 | { |
---|
| 108 | (void)penetrationVector; |
---|
| 109 | (void)index; |
---|
| 110 | btAssert(0); |
---|
| 111 | } |
---|
| 112 | |
---|
[7983] | 113 | virtual int calculateSerializeBufferSize() const; |
---|
[1963] | 114 | |
---|
[7983] | 115 | ///fills the dataBuffer and returns the struct name (and 0 on failure) |
---|
| 116 | virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; |
---|
| 117 | |
---|
[1963] | 118 | |
---|
| 119 | }; |
---|
| 120 | |
---|
[7983] | 121 | ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 |
---|
| 122 | struct btConvexInternalShapeData |
---|
| 123 | { |
---|
| 124 | btCollisionShapeData m_collisionShapeData; |
---|
[1963] | 125 | |
---|
[7983] | 126 | btVector3FloatData m_localScaling; |
---|
| 127 | |
---|
| 128 | btVector3FloatData m_implicitShapeDimensions; |
---|
| 129 | |
---|
| 130 | float m_collisionMargin; |
---|
| 131 | |
---|
| 132 | int m_padding; |
---|
| 133 | |
---|
| 134 | }; |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | SIMD_FORCE_INLINE int btConvexInternalShape::calculateSerializeBufferSize() const |
---|
| 139 | { |
---|
| 140 | return sizeof(btConvexInternalShapeData); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | ///fills the dataBuffer and returns the struct name (and 0 on failure) |
---|
| 144 | SIMD_FORCE_INLINE const char* btConvexInternalShape::serialize(void* dataBuffer, btSerializer* serializer) const |
---|
| 145 | { |
---|
| 146 | btConvexInternalShapeData* shapeData = (btConvexInternalShapeData*) dataBuffer; |
---|
| 147 | btCollisionShape::serialize(&shapeData->m_collisionShapeData, serializer); |
---|
| 148 | |
---|
| 149 | m_implicitShapeDimensions.serializeFloat(shapeData->m_implicitShapeDimensions); |
---|
| 150 | m_localScaling.serializeFloat(shapeData->m_localScaling); |
---|
| 151 | shapeData->m_collisionMargin = float(m_collisionMargin); |
---|
| 152 | |
---|
| 153 | return "btConvexInternalShapeData"; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | ///btConvexInternalAabbCachingShape adds local aabb caching for convex shapes, to avoid expensive bounding box calculations |
---|
| 160 | class btConvexInternalAabbCachingShape : public btConvexInternalShape |
---|
| 161 | { |
---|
| 162 | btVector3 m_localAabbMin; |
---|
| 163 | btVector3 m_localAabbMax; |
---|
| 164 | bool m_isLocalAabbValid; |
---|
| 165 | |
---|
| 166 | protected: |
---|
| 167 | |
---|
| 168 | btConvexInternalAabbCachingShape(); |
---|
| 169 | |
---|
| 170 | void setCachedLocalAabb (const btVector3& aabbMin, const btVector3& aabbMax) |
---|
| 171 | { |
---|
| 172 | m_isLocalAabbValid = true; |
---|
| 173 | m_localAabbMin = aabbMin; |
---|
| 174 | m_localAabbMax = aabbMax; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | inline void getCachedLocalAabb (btVector3& aabbMin, btVector3& aabbMax) const |
---|
| 178 | { |
---|
| 179 | btAssert(m_isLocalAabbValid); |
---|
| 180 | aabbMin = m_localAabbMin; |
---|
| 181 | aabbMax = m_localAabbMax; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const |
---|
| 185 | { |
---|
| 186 | |
---|
| 187 | //lazy evaluation of local aabb |
---|
| 188 | btAssert(m_isLocalAabbValid); |
---|
| 189 | btTransformAabb(m_localAabbMin,m_localAabbMax,margin,trans,aabbMin,aabbMax); |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | public: |
---|
| 193 | |
---|
| 194 | virtual void setLocalScaling(const btVector3& scaling); |
---|
| 195 | |
---|
| 196 | virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; |
---|
| 197 | |
---|
| 198 | void recalcLocalAabb(); |
---|
| 199 | |
---|
| 200 | }; |
---|
| 201 | |
---|
[1963] | 202 | #endif //BT_CONVEX_INTERNAL_SHAPE_H |
---|