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 
32 {
34 
39  struct btDbvtNode* m_node;
40 };
41 
43 {
44  return (c1.m_transform == c2.m_transform &&
45  c1.m_childShape == c2.m_childShape &&
47  c1.m_childMargin == c2.m_childMargin);
48 }
49 
57 {
58 protected:
62 
64 
67 
69 
71 
72 public:
74 
75  explicit btCompoundShape(bool enableDynamicAabbTree = true, const int initialChildCapacity = 0);
76 
77  virtual ~btCompoundShape();
78 
79  void addChildShape(const btTransform& localTransform, btCollisionShape* shape);
80 
82  virtual void removeChildShape(btCollisionShape * shape);
83 
84  void removeChildShapeByIndex(int childShapeindex);
85 
86  int getNumChildShapes() const
87  {
88  return int(m_children.size());
89  }
90 
92  {
93  return m_children[index].m_childShape;
94  }
95  const btCollisionShape* getChildShape(int index) const
96  {
97  return m_children[index].m_childShape;
98  }
99 
101  {
102  return m_children[index].m_transform;
103  }
104  const btTransform& getChildTransform(int index) const
105  {
106  return m_children[index].m_transform;
107  }
108 
110  void updateChildTransform(int childIndex, const btTransform& newChildTransform, bool shouldRecalculateLocalAabb = true);
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(const 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 // clang-format off
177 
180 {
185 };
186 
189 {
191 
193 
195 
197 
198 };
199 
200 // clang-format on
201 
203 {
204  return sizeof(btCompoundShapeData);
205 }
206 
207 #endif //BT_COMPOUND_SHAPE_H
btCompoundShape::getName
virtual const char * getName() const
Definition: btCompoundShape.h:141
btCollisionShapeData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition: btCollisionShape.h:151
btCompoundShapeChildData::m_childShape
btCollisionShapeData * m_childShape
Definition: btCompoundShape.h:182
btCollisionShape.h
btCompoundShape::getUpdateRevision
int getUpdateRevision() const
Definition: btCompoundShape.h:165
btCompoundShape::getChildTransform
btTransform & getChildTransform(int index)
Definition: btCompoundShape.h:100
btCompoundShape::calculateSerializeBufferSize
virtual int calculateSerializeBufferSize() const
Definition: btCompoundShape.h:202
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btCompoundShapeChild::m_node
struct btDbvtNode * m_node
Definition: btCompoundShape.h:39
btCompoundShape::getMargin
virtual btScalar getMargin() const
Definition: btCompoundShape.h:137
btCompoundShapeChildData::m_transform
btTransformFloatData m_transform
Definition: btCompoundShape.h:181
btCompoundShape::m_updateRevision
int m_updateRevision
increment m_updateRevision when adding/removing/replacing child shapes, so that some caches can be up...
Definition: btCompoundShape.h:66
btCompoundShapeChild::m_transform
btTransform m_transform
Definition: btCompoundShape.h:35
btCollisionMargin.h
btMatrix3x3.h
btCompoundShape::setMargin
virtual void setMargin(btScalar margin)
Definition: btCompoundShape.h:133
btCompoundShape::getChildTransform
const btTransform & getChildTransform(int index) const
Definition: btCompoundShape.h:104
btVector3.h
btCollisionShape
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
Definition: btCollisionShape.h:26
btDbvt
The btDbvt class implements a fast dynamic bounding volume tree based on axis aligned bounding boxes ...
Definition: btDbvt.h:228
btCompoundShapeChild::m_childShapeType
int m_childShapeType
Definition: btCompoundShape.h:37
btCompoundShape::getChildShape
const btCollisionShape * getChildShape(int index) const
Definition: btCompoundShape.h:95
btCompoundShapeData::m_collisionMargin
float m_collisionMargin
Definition: btCompoundShape.h:196
btCompoundShape::m_localAabbMax
btVector3 m_localAabbMax
Definition: btCompoundShape.h:61
btCompoundShapeData::m_childShapePtr
btCompoundShapeChildData * m_childShapePtr
Definition: btCompoundShape.h:192
btTransform.h
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:28
btCompoundShape::getLocalScaling
virtual const btVector3 & getLocalScaling() const
Definition: btCompoundShape.h:126
btCompoundShapeData::m_numChildShapes
int m_numChildShapes
Definition: btCompoundShape.h:194
BT_DECLARE_ALIGNED_ALLOCATOR
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:425
btCompoundShape::m_children
btAlignedObjectArray< btCompoundShapeChild > m_children
Definition: btCompoundShape.h:59
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:80
btCompoundShape::m_localScaling
btVector3 m_localScaling
Definition: btCompoundShape.h:70
btCompoundShape::getChildList
btCompoundShapeChild * getChildList()
Definition: btCompoundShape.h:112
btCompoundShape::m_dynamicAabbTree
btDbvt * m_dynamicAabbTree
Definition: btCompoundShape.h:63
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:99
btTransformFloatData
for serialization
Definition: btTransform.h:244
btAlignedObjectArray< btCompoundShapeChild >
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:98
btCompoundShapeChild::m_childShape
btCollisionShape * m_childShape
Definition: btCompoundShape.h:36
btCompoundShape::getDynamicAabbTree
btDbvt * getDynamicAabbTree()
Definition: btCompoundShape.h:151
btCompoundShapeChildData::m_childShapeType
int m_childShapeType
Definition: btCompoundShape.h:183
btCompoundShape
The btCompoundShape allows to store multiple other btCollisionShapes This allows for moving concave c...
Definition: btCompoundShape.h:55
btSerializer
Definition: btSerializer.h:65
btCompoundShape::getNumChildShapes
int getNumChildShapes() const
Definition: btCompoundShape.h:86
operator==
bool operator==(const btCompoundShapeChild &c1, const btCompoundShapeChild &c2)
Definition: btCompoundShape.h:42
btCompoundShape::m_collisionMargin
btScalar m_collisionMargin
Definition: btCompoundShape.h:68
btCompoundShapeChild::m_childMargin
btScalar m_childMargin
Definition: btCompoundShape.h:38
btCompoundShape::m_localAabbMin
btVector3 m_localAabbMin
Definition: btCompoundShape.h:60
btCompoundShapeChild
Definition: btCompoundShape.h:30
btAlignedObjectArray.h
btCompoundShapeData::m_collisionShapeData
btCollisionShapeData m_collisionShapeData
Definition: btCompoundShape.h:190
btCompoundShapeChildData::m_childMargin
float m_childMargin
Definition: btCompoundShape.h:184
btCompoundShapeData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition: btCompoundShape.h:188
btDbvtNode
Definition: btDbvt.h:180
btCompoundShape::getChildShape
btCollisionShape * getChildShape(int index)
Definition: btCompoundShape.h:91
btCompoundShape::getDynamicAabbTree
const btDbvt * getDynamicAabbTree() const
Definition: btCompoundShape.h:146
btAlignedObjectArray::size
int size() const
return the number of elements in the array
Definition: btAlignedObjectArray.h:142
btCompoundShapeChildData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition: btCompoundShape.h:179