Bullet Collision Detection & Physics Library
btCompoundShape.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
4 
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 
16 #ifndef BT_COMPOUND_SHAPE_H
17 #define BT_COMPOUND_SHAPE_H
18 
19 #include "btCollisionShape.h"
20 
21 #include "LinearMath/btVector3.h"
22 #include "LinearMath/btTransform.h"
23 #include "LinearMath/btMatrix3x3.h"
24 #include "btCollisionMargin.h"
26 
27 //class btOptimizedBvh;
28 struct btDbvt;
29 
31 {
33 
38  struct btDbvtNode* m_node;
39 };
40 
42 {
43  return ( c1.m_transform == c2.m_transform &&
44  c1.m_childShape == c2.m_childShape &&
46  c1.m_childMargin == c2.m_childMargin );
47 }
48 
55 {
59 
61 
64 
66 
67 protected:
69 
70 public:
72 
73  btCompoundShape(bool enableDynamicAabbTree = true);
74 
75  virtual ~btCompoundShape();
76 
77  void addChildShape(const btTransform& localTransform,btCollisionShape* shape);
78 
80  virtual void removeChildShape(btCollisionShape* shape);
81 
82  void removeChildShapeByIndex(int childShapeindex);
83 
84 
85  int getNumChildShapes() const
86  {
87  return int (m_children.size());
88  }
89 
90  btCollisionShape* getChildShape(int index)
91  {
92  return m_children[index].m_childShape;
93  }
94  const btCollisionShape* getChildShape(int index) const
95  {
96  return m_children[index].m_childShape;
97  }
98 
100  {
101  return m_children[index].m_transform;
102  }
103  const btTransform& getChildTransform(int index) const
104  {
105  return m_children[index].m_transform;
106  }
107 
109  void updateChildTransform(int childIndex, const btTransform& newChildTransform, bool shouldRecalculateLocalAabb = true);
110 
111 
113  {
114  return &m_children[0];
115  }
116 
118  virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
119 
122  virtual void recalculateLocalAabb();
123 
124  virtual void setLocalScaling(const btVector3& scaling);
125 
126  virtual const btVector3& getLocalScaling() const
127  {
128  return m_localScaling;
129  }
130 
131  virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
132 
133  virtual void setMargin(btScalar margin)
134  {
135  m_collisionMargin = margin;
136  }
137  virtual btScalar getMargin() const
138  {
139  return m_collisionMargin;
140  }
141  virtual const char* getName()const
142  {
143  return "Compound";
144  }
145 
146  const btDbvt* getDynamicAabbTree() const
147  {
148  return m_dynamicAabbTree;
149  }
150 
152  {
153  return m_dynamicAabbTree;
154  }
155 
156  void createAabbTreeFromChildren();
157 
163  void calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const;
164 
165  int getUpdateRevision() const
166  {
167  return m_updateRevision;
168  }
169 
170  virtual int calculateSerializeBufferSize() const;
171 
173  virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
174 
175 
176 };
177 
180 {
185 };
186 
189 {
191 
193 
195 
197 
198 };
199 
200 
202 {
203  return sizeof(btCompoundShapeData);
204 }
205 
206 
207 
208 
209 
210 
211 
212 #endif //BT_COMPOUND_SHAPE_H
virtual btScalar getMargin() const
btVector3 m_localAabbMax
btCompoundShapeChildData * m_childShapePtr
virtual const btVector3 & getLocalScaling() const
virtual int calculateSerializeBufferSize() const
btDbvt * m_dynamicAabbTree
btAlignedObjectArray< btCompoundShapeChild > m_children
int getUpdateRevision() const
The btDbvt class implements a fast dynamic bounding volume tree based on axis aligned bounding boxes ...
Definition: btDbvt.h:194
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
#define SIMD_FORCE_INLINE
Definition: btScalar.h:58
const btCollisionShape * getChildShape(int index) const
btCollisionShape * m_childShape
virtual void setMargin(btScalar margin)
const btDbvt * getDynamicAabbTree() const
btCollisionShapeData m_collisionShapeData
struct btDbvtNode * m_node
int m_updateRevision
increment m_updateRevision when adding/removing/replacing child shapes, so that some caches can be up...
btVector3 m_localAabbMin
btDbvt * getDynamicAabbTree()
int size() const
return the number of elements in the array
const btTransform & getChildTransform(int index) const
bool operator==(const btCompoundShapeChild &c1, const btCompoundShapeChild &c2)
btTransform & getChildTransform(int index)
virtual const char * getName() const
btTransformFloatData m_transform
btVector3 m_localScaling
btScalar m_collisionMargin
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:59
btCompoundShapeChild * getChildList()
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
for serialization
Definition: btTransform.h:253
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:357
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
The btCompoundShape allows to store multiple other btCollisionShapes This allows for moving concave c...
btCollisionShapeData * m_childShape
btCollisionShape * getChildShape(int index)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:266
int getNumChildShapes() const