Bullet Collision Detection & Physics Library: btCylinderShape.h Source File

Bullet Collision Detection & Physics Library

btCylinderShape.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_CYLINDER_MINKOWSKI_H
17 #define BT_CYLINDER_MINKOWSKI_H
18
19 #include "btBoxShape.h"
20 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
21 #include "LinearMath/btVector3.h"
22
24 ATTRIBUTE_ALIGNED16(class) btCylinderShape : public btConvexInternalShape
25
26 {
27
28 protected:
29
30 int m_upAxis;
31
32 public:
33
34 BT_DECLARE_ALIGNED_ALLOCATOR();
35
36 btVector3 getHalfExtentsWithMargin() const
37 {
38 btVector3 halfExtents = getHalfExtentsWithoutMargin();
39 btVector3 margin(getMargin(),getMargin(),getMargin());
40 halfExtents += margin;
41 return halfExtents;
42 }
43
44 const btVector3& getHalfExtentsWithoutMargin() const
45 {
46 return m_implicitShapeDimensions;//changed in Bullet 2.63: assume the scaling and margin are included
47 }
48
49 btCylinderShape (const btVector3& halfExtents);
50
51 void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
52
53 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
54
55 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
56
57 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
58
59 virtual void setMargin(btScalar collisionMargin)
60 {
61 //correct the m_implicitShapeDimensions for the margin
62 btVector3 oldMargin(getMargin(),getMargin(),getMargin());
63 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
64
65 btConvexInternalShape::setMargin(collisionMargin);
66 btVector3 newMargin(getMargin(),getMargin(),getMargin());
67 m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
68
69 }
70
71 virtual btVector3 localGetSupportingVertex(const btVector3& vec) const
72 {
73
74 btVector3 supVertex;
75 supVertex = localGetSupportingVertexWithoutMargin(vec);
76
77 if ( getMargin()!=btScalar(0.) )
78 {
79 btVector3 vecnorm = vec;
80 if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
81 {
82 vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
83 }
84 vecnorm.normalize();
85 supVertex+= getMargin() * vecnorm;
86 }
87 return supVertex;
88 }
89
90
91 //use box inertia
92 // virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
93
94
95 int getUpAxis() const
96 {
97 return m_upAxis;
98 }
99
100 virtual btVector3 getAnisotropicRollingFrictionDirection() const
101 {
102 btVector3 aniDir(0,0,0);
103 aniDir[getUpAxis()]=1;
104 return aniDir;
105 }
106
107 virtual btScalar getRadius() const
108 {
109 return getHalfExtentsWithMargin().getX();
110 }
111
112 virtual void setLocalScaling(const btVector3& scaling)
113 {
114 btVector3 oldMargin(getMargin(),getMargin(),getMargin());
115 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
116 btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
117
118 btConvexInternalShape::setLocalScaling(scaling);
119
120 m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
121
122 }
123
124 //debugging
125 virtual const char* getName()const
126 {
127 return "CylinderY";
128 }
129
130 virtual int calculateSerializeBufferSize() const;
131
133 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
134
135 };
136
137 class btCylinderShapeX : public btCylinderShape
138 {
139 public:
140 BT_DECLARE_ALIGNED_ALLOCATOR();
141
142 btCylinderShapeX (const btVector3& halfExtents);
143
144 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
145 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
146
147 //debugging
148 virtual const char* getName()const
149 {
150 return "CylinderX";
151 }
152
153 virtual btScalar getRadius() const
154 {
155 return getHalfExtentsWithMargin().getY();
156 }
157
158 };
159
160 class btCylinderShapeZ : public btCylinderShape
161 {
162 public:
163 BT_DECLARE_ALIGNED_ALLOCATOR();
164
165 btCylinderShapeZ (const btVector3& halfExtents);
166
167 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
168 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
169
170 //debugging
171 virtual const char* getName()const
172 {
173 return "CylinderZ";
174 }
175
176 virtual btScalar getRadius() const
177 {
178 return getHalfExtentsWithMargin().getX();
179 }
180
181 };
182
184 struct btCylinderShapeData
185 {
186 btConvexInternalShapeData m_convexInternalShapeData;
187
188 int m_upAxis;
189
190 char m_padding[4];
191 };
192
193 SIMD_FORCE_INLINE int btCylinderShape::calculateSerializeBufferSize() const
194 {
195 return sizeof(btCylinderShapeData);
196 }
197
199 SIMD_FORCE_INLINE const char* btCylinderShape::serialize(void* dataBuffer, btSerializer* serializer) const
200 {
201 btCylinderShapeData* shapeData = (btCylinderShapeData*) dataBuffer;
202
203 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer);
204
205 shapeData->m_upAxis = m_upAxis;
206
207 // Fill padding with zeros to appease msan.
208 shapeData->m_padding[0] = 0;
209 shapeData->m_padding[1] = 0;
210 shapeData->m_padding[2] = 0;
211 shapeData->m_padding[3] = 0;
212
213 return "btCylinderShapeData";
214 }
215
216
217
218 #endif //BT_CYLINDER_MINKOWSKI_H
219
btCylinderShape::getHalfExtentsWithMargin
btVector3 getHalfExtentsWithMargin() const
Definition: btCylinderShape.h:36
SIMD_EPSILON
#define SIMD_EPSILON
Definition: btScalar.h:521
btCylinderShapeZ::getName
virtual const char * getName() const
Definition: btCylinderShape.h:171
btCylinderShapeZ::btCylinderShapeZ
btCylinderShapeZ(const btVector3 &halfExtents)
Definition: btCylinderShape.cpp:39
btCylinderShape::getAnisotropicRollingFrictionDirection
virtual btVector3 getAnisotropicRollingFrictionDirection() const
the getAnisotropicRollingFrictionDirection can be used in combination with setAnisotropicFriction See...
Definition: btCylinderShape.h:100
btCylinderShape::setMargin
virtual void setMargin(btScalar collisionMargin)
Definition: btCylinderShape.h:59
btVector3::setValue
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:652
btVector3.h
btCylinderShape::localGetSupportingVertex
virtual btVector3 localGetSupportingVertex(const btVector3 &vec) const
Definition: btCylinderShape.h:71
btBoxShape.h
btConvexInternalShape
The btConvexInternalShape is an internal base class, shared by most convex shape implementations.
Definition: btConvexInternalShape.h:29
btCylinderShapeX::batchedUnitVectorGetSupportingVertexWithoutMargin
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const
Definition: btCylinderShape.cpp:274
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:81
btVector3::getY
const btScalar & getY() const
Return the y value.
Definition: btVector3.h:575
btConvexInternalShapeData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btConvexInternalShape.h:144
btCylinderShape::getUpAxis
int getUpAxis() const
Definition: btCylinderShape.h:95
btSerializer
Definition: btSerializer.h:68
btVector3::normalize
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition: btVector3.h:309
btCylinderShapeZ
Definition: btCylinderShape.h:160
btConvexInternalShape::serialize
virtual const char * serialize(void *dataBuffer, btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
Definition: btConvexInternalShape.h:166
btConvexInternalShape::setMargin
virtual void setMargin(btScalar margin)
Definition: btConvexInternalShape.h:109
btCylinderShapeZ::batchedUnitVectorGetSupportingVertexWithoutMargin
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const
Definition: btCylinderShape.cpp:263
btCylinderShapeX::BT_DECLARE_ALIGNED_ALLOCATOR
BT_DECLARE_ALIGNED_ALLOCATOR()
btCylinderShape::serialize
virtual const char * serialize(void *dataBuffer, btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
Definition: btCylinderShape.h:199
btCylinderShape::setLocalScaling
virtual void setLocalScaling(const btVector3 &scaling)
Definition: btCylinderShape.h:112
btBroadphaseProxy.h
btCylinderShapeZ::getRadius
virtual btScalar getRadius() const
Definition: btCylinderShape.h:176
btCylinderShape::getHalfExtentsWithoutMargin
const btVector3 & getHalfExtentsWithoutMargin() const
Definition: btCylinderShape.h:44
btCylinderShape::calculateSerializeBufferSize
virtual int calculateSerializeBufferSize() const
Definition: btCylinderShape.h:193
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:82
btCylinderShapeX::btCylinderShapeX
btCylinderShapeX(const btVector3 &halfExtents)
Definition: btCylinderShape.cpp:31
btCylinderShapeZ::BT_DECLARE_ALIGNED_ALLOCATOR
BT_DECLARE_ALIGNED_ALLOCATOR()
btCylinderShapeZ::localGetSupportingVertexWithoutMargin
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const
Definition: btCylinderShape.cpp:246
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btCylinderShapeX::localGetSupportingVertexWithoutMargin
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const
Definition: btCylinderShape.cpp:240
btCylinderShape::m_upAxis
int m_upAxis
Definition: btCylinderShape.h:30
btCylinderShapeX::getRadius
virtual btScalar getRadius() const
Definition: btCylinderShape.h:153
btCylinderShape::getRadius
virtual btScalar getRadius() const
Definition: btCylinderShape.h:107
BT_DECLARE_ALIGNED_ALLOCATOR
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:403
btCylinderShapeData::m_padding
char m_padding[4]
Definition: btCylinderShape.h:190
btCylinderShape
The btCylinderShape class implements a cylinder shape primitive, centered around the origin...
Definition: btCylinderShape.h:24
btConvexInternalShape::setLocalScaling
virtual void setLocalScaling(const btVector3 &scaling)
Definition: btConvexInternalShape.cpp:28
btCylinderShapeData::m_convexInternalShapeData
btConvexInternalShapeData m_convexInternalShapeData
Definition: btCylinderShape.h:186
btCylinderShapeX::getName
virtual const char * getName() const
Definition: btCylinderShape.h:148
btVector3::getX
const btScalar & getX() const
Return the x value.
Definition: btVector3.h:573
btCylinderShapeData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btCylinderShape.h:184
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
btCylinderShapeX
Definition: btCylinderShape.h:137
btCylinderShape::getName
virtual const char * getName() const
Definition: btCylinderShape.h:125
btCylinderShapeData::m_upAxis
int m_upAxis
Definition: btCylinderShape.h:188