00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef BT_CONVEX_INTERNAL_SHAPE_H
00017 #define BT_CONVEX_INTERNAL_SHAPE_H
00018
00019 #include "btConvexShape.h"
00020 #include "LinearMath/btAabbUtil2.h"
00021
00022
00024 class btConvexInternalShape : public btConvexShape
00025 {
00026
00027 protected:
00028
00029
00030 btVector3 m_localScaling;
00031
00032 btVector3 m_implicitShapeDimensions;
00033
00034 btScalar m_collisionMargin;
00035
00036 btScalar m_padding;
00037
00038 btConvexInternalShape();
00039
00040 public:
00041
00042
00043
00044 virtual ~btConvexInternalShape()
00045 {
00046
00047 }
00048
00049 virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
00050
00051 const btVector3& getImplicitShapeDimensions() const
00052 {
00053 return m_implicitShapeDimensions;
00054 }
00055
00060 void setImplicitShapeDimensions(const btVector3& dimensions)
00061 {
00062 m_implicitShapeDimensions = dimensions;
00063 }
00064
00066 void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
00067 {
00068 getAabbSlow(t,aabbMin,aabbMax);
00069 }
00070
00071
00072
00073 virtual void getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
00074
00075
00076 virtual void setLocalScaling(const btVector3& scaling);
00077 virtual const btVector3& getLocalScaling() const
00078 {
00079 return m_localScaling;
00080 }
00081
00082 const btVector3& getLocalScalingNV() const
00083 {
00084 return m_localScaling;
00085 }
00086
00087 virtual void setMargin(btScalar margin)
00088 {
00089 m_collisionMargin = margin;
00090 }
00091 virtual btScalar getMargin() const
00092 {
00093 return m_collisionMargin;
00094 }
00095
00096 btScalar getMarginNV() const
00097 {
00098 return m_collisionMargin;
00099 }
00100
00101 virtual int getNumPreferredPenetrationDirections() const
00102 {
00103 return 0;
00104 }
00105
00106 virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
00107 {
00108 (void)penetrationVector;
00109 (void)index;
00110 btAssert(0);
00111 }
00112
00113 virtual int calculateSerializeBufferSize() const;
00114
00116 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
00117
00118
00119 };
00120
00122 struct btConvexInternalShapeData
00123 {
00124 btCollisionShapeData m_collisionShapeData;
00125
00126 btVector3FloatData m_localScaling;
00127
00128 btVector3FloatData m_implicitShapeDimensions;
00129
00130 float m_collisionMargin;
00131
00132 int m_padding;
00133
00134 };
00135
00136
00137
00138 SIMD_FORCE_INLINE int btConvexInternalShape::calculateSerializeBufferSize() const
00139 {
00140 return sizeof(btConvexInternalShapeData);
00141 }
00142
00144 SIMD_FORCE_INLINE const char* btConvexInternalShape::serialize(void* dataBuffer, btSerializer* serializer) const
00145 {
00146 btConvexInternalShapeData* shapeData = (btConvexInternalShapeData*) dataBuffer;
00147 btCollisionShape::serialize(&shapeData->m_collisionShapeData, serializer);
00148
00149 m_implicitShapeDimensions.serializeFloat(shapeData->m_implicitShapeDimensions);
00150 m_localScaling.serializeFloat(shapeData->m_localScaling);
00151 shapeData->m_collisionMargin = float(m_collisionMargin);
00152
00153 return "btConvexInternalShapeData";
00154 }
00155
00156
00157
00158
00160 class btConvexInternalAabbCachingShape : public btConvexInternalShape
00161 {
00162 btVector3 m_localAabbMin;
00163 btVector3 m_localAabbMax;
00164 bool m_isLocalAabbValid;
00165
00166 protected:
00167
00168 btConvexInternalAabbCachingShape();
00169
00170 void setCachedLocalAabb (const btVector3& aabbMin, const btVector3& aabbMax)
00171 {
00172 m_isLocalAabbValid = true;
00173 m_localAabbMin = aabbMin;
00174 m_localAabbMax = aabbMax;
00175 }
00176
00177 inline void getCachedLocalAabb (btVector3& aabbMin, btVector3& aabbMax) const
00178 {
00179 btAssert(m_isLocalAabbValid);
00180 aabbMin = m_localAabbMin;
00181 aabbMax = m_localAabbMax;
00182 }
00183
00184 inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const
00185 {
00186
00187
00188 btAssert(m_isLocalAabbValid);
00189 btTransformAabb(m_localAabbMin,m_localAabbMax,margin,trans,aabbMin,aabbMax);
00190 }
00191
00192 public:
00193
00194 virtual void setLocalScaling(const btVector3& scaling);
00195
00196 virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
00197
00198 void recalcLocalAabb();
00199
00200 };
00201
00202 #endif //BT_CONVEX_INTERNAL_SHAPE_H