Blender V2.61 - r43446
|
00001 /* 00002 Bullet Continuous Collision Detection and Physics Library 00003 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 00004 00005 This software is provided 'as-is', without any express or implied warranty. 00006 In no event will the authors be held liable for any damages arising from the use of this software. 00007 Permission is granted to anyone to use this software for any purpose, 00008 including commercial applications, and to alter it and redistribute it freely, 00009 subject to the following restrictions: 00010 00011 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. 00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 00013 3. This notice may not be removed or altered from any source distribution. 00014 */ 00015 00016 #ifndef COMPOUND_SHAPE_H 00017 #define COMPOUND_SHAPE_H 00018 00019 #include "btCollisionShape.h" 00020 00021 #include "LinearMath/btVector3.h" 00022 #include "LinearMath/btTransform.h" 00023 #include "LinearMath/btMatrix3x3.h" 00024 #include "btCollisionMargin.h" 00025 #include "LinearMath/btAlignedObjectArray.h" 00026 00027 //class btOptimizedBvh; 00028 struct btDbvt; 00029 00030 ATTRIBUTE_ALIGNED16(struct) btCompoundShapeChild 00031 { 00032 BT_DECLARE_ALIGNED_ALLOCATOR(); 00033 00034 btTransform m_transform; 00035 btCollisionShape* m_childShape; 00036 int m_childShapeType; 00037 btScalar m_childMargin; 00038 struct btDbvtNode* m_node; 00039 }; 00040 00041 SIMD_FORCE_INLINE bool operator==(const btCompoundShapeChild& c1, const btCompoundShapeChild& c2) 00042 { 00043 return ( c1.m_transform == c2.m_transform && 00044 c1.m_childShape == c2.m_childShape && 00045 c1.m_childShapeType == c2.m_childShapeType && 00046 c1.m_childMargin == c2.m_childMargin ); 00047 } 00048 00054 ATTRIBUTE_ALIGNED16(class) btCompoundShape : public btCollisionShape 00055 { 00056 btAlignedObjectArray<btCompoundShapeChild> m_children; 00057 btVector3 m_localAabbMin; 00058 btVector3 m_localAabbMax; 00059 00060 btDbvt* m_dynamicAabbTree; 00061 00063 int m_updateRevision; 00064 00065 btScalar m_collisionMargin; 00066 00067 protected: 00068 btVector3 m_localScaling; 00069 00070 public: 00071 BT_DECLARE_ALIGNED_ALLOCATOR(); 00072 00073 btCompoundShape(bool enableDynamicAabbTree = true); 00074 00075 virtual ~btCompoundShape(); 00076 00077 void addChildShape(const btTransform& localTransform,btCollisionShape* shape); 00078 00080 virtual void removeChildShape(btCollisionShape* shape); 00081 00082 void removeChildShapeByIndex(int childShapeindex); 00083 00084 00085 int getNumChildShapes() const 00086 { 00087 return int (m_children.size()); 00088 } 00089 00090 btCollisionShape* getChildShape(int index) 00091 { 00092 return m_children[index].m_childShape; 00093 } 00094 const btCollisionShape* getChildShape(int index) const 00095 { 00096 return m_children[index].m_childShape; 00097 } 00098 00099 btTransform& getChildTransform(int index) 00100 { 00101 return m_children[index].m_transform; 00102 } 00103 const btTransform& getChildTransform(int index) const 00104 { 00105 return m_children[index].m_transform; 00106 } 00107 00109 void updateChildTransform(int childIndex, const btTransform& newChildTransform, bool shouldRecalculateLocalAabb = true); 00110 00111 00112 btCompoundShapeChild* getChildList() 00113 { 00114 return &m_children[0]; 00115 } 00116 00118 virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; 00119 00122 virtual void recalculateLocalAabb(); 00123 00124 virtual void setLocalScaling(const btVector3& scaling); 00125 00126 virtual const btVector3& getLocalScaling() const 00127 { 00128 return m_localScaling; 00129 } 00130 00131 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const; 00132 00133 virtual void setMargin(btScalar margin) 00134 { 00135 m_collisionMargin = margin; 00136 } 00137 virtual btScalar getMargin() const 00138 { 00139 return m_collisionMargin; 00140 } 00141 virtual const char* getName()const 00142 { 00143 return "Compound"; 00144 } 00145 00146 const btDbvt* getDynamicAabbTree() const 00147 { 00148 return m_dynamicAabbTree; 00149 } 00150 00151 btDbvt* getDynamicAabbTree() 00152 { 00153 return m_dynamicAabbTree; 00154 } 00155 00156 void createAabbTreeFromChildren(); 00157 00163 void calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const; 00164 00165 int getUpdateRevision() const 00166 { 00167 return m_updateRevision; 00168 } 00169 00170 virtual int calculateSerializeBufferSize() const; 00171 00173 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 00174 00175 00176 }; 00177 00179 struct btCompoundShapeChildData 00180 { 00181 btTransformFloatData m_transform; 00182 btCollisionShapeData *m_childShape; 00183 int m_childShapeType; 00184 float m_childMargin; 00185 }; 00186 00188 struct btCompoundShapeData 00189 { 00190 btCollisionShapeData m_collisionShapeData; 00191 00192 btCompoundShapeChildData *m_childShapePtr; 00193 00194 int m_numChildShapes; 00195 00196 float m_collisionMargin; 00197 00198 }; 00199 00200 00201 SIMD_FORCE_INLINE int btCompoundShape::calculateSerializeBufferSize() const 00202 { 00203 return sizeof(btCompoundShapeData); 00204 } 00205 00206 00207 00208 00209 00210 00211 00212 #endif //COMPOUND_SHAPE_H