2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
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:
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.
16 #ifndef BT_CYLINDER_MINKOWSKI_H
17 #define BT_CYLINDER_MINKOWSKI_H
19 #include "btBoxShape.h"
20 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
21 #include "LinearMath/btVector3.h"
23 /// The btCylinderShape class implements a cylinder shape primitive, centered around the origin. Its central axis aligned with the Y axis. btCylinderShapeX is aligned with the X axis and btCylinderShapeZ around the Z axis.
24 ATTRIBUTE_ALIGNED16(class)
25 btCylinderShape : public btConvexInternalShape
32 BT_DECLARE_ALIGNED_ALLOCATOR();
34 btVector3 getHalfExtentsWithMargin() const
36 btVector3 halfExtents = getHalfExtentsWithoutMargin();
37 btVector3 margin(getMargin(), getMargin(), getMargin());
38 halfExtents += margin;
42 const btVector3& getHalfExtentsWithoutMargin() const
44 return m_implicitShapeDimensions; //changed in Bullet 2.63: assume the scaling and margin are included
47 btCylinderShape(const btVector3& halfExtents);
49 void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
51 virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const;
53 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const;
55 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const;
57 virtual void setMargin(btScalar collisionMargin)
59 //correct the m_implicitShapeDimensions for the margin
60 btVector3 oldMargin(getMargin(), getMargin(), getMargin());
61 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions + oldMargin;
63 btConvexInternalShape::setMargin(collisionMargin);
64 btVector3 newMargin(getMargin(), getMargin(), getMargin());
65 m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
68 virtual btVector3 localGetSupportingVertex(const btVector3& vec) const
71 supVertex = localGetSupportingVertexWithoutMargin(vec);
73 if (getMargin() != btScalar(0.))
75 btVector3 vecnorm = vec;
76 if (vecnorm.length2() < (SIMD_EPSILON * SIMD_EPSILON))
78 vecnorm.setValue(btScalar(-1.), btScalar(-1.), btScalar(-1.));
81 supVertex += getMargin() * vecnorm;
87 // virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
94 virtual btVector3 getAnisotropicRollingFrictionDirection() const
96 btVector3 aniDir(0, 0, 0);
97 aniDir[getUpAxis()] = 1;
101 virtual btScalar getRadius() const
103 return getHalfExtentsWithMargin().getX();
106 virtual void setLocalScaling(const btVector3& scaling)
108 btVector3 oldMargin(getMargin(), getMargin(), getMargin());
109 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions + oldMargin;
110 btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
112 btConvexInternalShape::setLocalScaling(scaling);
114 m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
118 virtual const char* getName() const
123 virtual int calculateSerializeBufferSize() const;
125 ///fills the dataBuffer and returns the struct name (and 0 on failure)
126 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
129 class btCylinderShapeX : public btCylinderShape
132 BT_DECLARE_ALIGNED_ALLOCATOR();
134 btCylinderShapeX(const btVector3& halfExtents);
136 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const;
137 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const;
140 virtual const char* getName() const
145 virtual btScalar getRadius() const
147 return getHalfExtentsWithMargin().getY();
151 class btCylinderShapeZ : public btCylinderShape
154 BT_DECLARE_ALIGNED_ALLOCATOR();
156 btCylinderShapeZ(const btVector3& halfExtents);
158 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const;
159 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const;
162 virtual const char* getName() const
167 virtual btScalar getRadius() const
169 return getHalfExtentsWithMargin().getX();
173 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
174 struct btCylinderShapeData
176 btConvexInternalShapeData m_convexInternalShapeData;
183 SIMD_FORCE_INLINE int btCylinderShape::calculateSerializeBufferSize() const
185 return sizeof(btCylinderShapeData);
188 ///fills the dataBuffer and returns the struct name (and 0 on failure)
189 SIMD_FORCE_INLINE const char* btCylinderShape::serialize(void* dataBuffer, btSerializer* serializer) const
191 btCylinderShapeData* shapeData = (btCylinderShapeData*)dataBuffer;
193 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData, serializer);
195 shapeData->m_upAxis = m_upAxis;
197 // Fill padding with zeros to appease msan.
198 shapeData->m_padding[0] = 0;
199 shapeData->m_padding[1] = 0;
200 shapeData->m_padding[2] = 0;
201 shapeData->m_padding[3] = 0;
203 return "btCylinderShapeData";
206 #endif //BT_CYLINDER_MINKOWSKI_H