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_CONE_MINKOWSKI_H
17 #define BT_CONE_MINKOWSKI_H
19 #include "btConvexInternalShape.h"
20 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
22 ///The btConeShape implements a cone shape primitive, centered around the origin and aligned with the Y axis. The btConeShapeX is aligned around the X axis and btConeShapeZ around the Z axis.
23 ATTRIBUTE_ALIGNED16(class)
24 btConeShape : public btConvexInternalShape
31 btVector3 coneLocalSupport(const btVector3& v) const;
34 BT_DECLARE_ALIGNED_ALLOCATOR();
36 btConeShape(btScalar radius, btScalar height);
38 virtual btVector3 localGetSupportingVertex(const btVector3& vec) const;
39 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const;
40 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const;
42 btScalar getRadius() const { return m_radius; }
43 btScalar getHeight() const { return m_height; }
45 void setRadius(const btScalar radius)
49 void setHeight(const btScalar height)
54 virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const
57 identity.setIdentity();
58 btVector3 aabbMin, aabbMax;
59 getAabb(identity, aabbMin, aabbMax);
61 btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5);
63 btScalar margin = getMargin();
65 btScalar lx = btScalar(2.) * (halfExtents.x() + margin);
66 btScalar ly = btScalar(2.) * (halfExtents.y() + margin);
67 btScalar lz = btScalar(2.) * (halfExtents.z() + margin);
68 const btScalar x2 = lx * lx;
69 const btScalar y2 = ly * ly;
70 const btScalar z2 = lz * lz;
71 const btScalar scaledmass = mass * btScalar(0.08333333);
73 inertia = scaledmass * (btVector3(y2 + z2, x2 + z2, x2 + y2));
75 // inertia.x() = scaledmass * (y2+z2);
76 // inertia.y() = scaledmass * (x2+z2);
77 // inertia.z() = scaledmass * (x2+y2);
80 virtual const char* getName() const
85 ///choose upAxis index
86 void setConeUpIndex(int upIndex);
88 int getConeUpIndex() const
90 return m_coneIndices[1];
93 virtual btVector3 getAnisotropicRollingFrictionDirection() const
95 return btVector3(0, 1, 0);
98 virtual void setLocalScaling(const btVector3& scaling);
100 virtual int calculateSerializeBufferSize() const;
102 ///fills the dataBuffer and returns the struct name (and 0 on failure)
103 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
106 ///btConeShape implements a Cone shape, around the X axis
107 class btConeShapeX : public btConeShape
110 btConeShapeX(btScalar radius, btScalar height);
112 virtual btVector3 getAnisotropicRollingFrictionDirection() const
114 return btVector3(1, 0, 0);
118 virtual const char* getName() const
124 ///btConeShapeZ implements a Cone shape, around the Z axis
125 class btConeShapeZ : public btConeShape
128 btConeShapeZ(btScalar radius, btScalar height);
130 virtual btVector3 getAnisotropicRollingFrictionDirection() const
132 return btVector3(0, 0, 1);
136 virtual const char* getName() const
142 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
143 struct btConeShapeData
145 btConvexInternalShapeData m_convexInternalShapeData;
152 SIMD_FORCE_INLINE int btConeShape::calculateSerializeBufferSize() const
154 return sizeof(btConeShapeData);
157 ///fills the dataBuffer and returns the struct name (and 0 on failure)
158 SIMD_FORCE_INLINE const char* btConeShape::serialize(void* dataBuffer, btSerializer* serializer) const
160 btConeShapeData* shapeData = (btConeShapeData*)dataBuffer;
162 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData, serializer);
164 shapeData->m_upIndex = m_coneIndices[1];
166 // Fill padding with zeros to appease msan.
167 shapeData->m_padding[0] = 0;
168 shapeData->m_padding[1] = 0;
169 shapeData->m_padding[2] = 0;
170 shapeData->m_padding[3] = 0;
172 return "btConeShapeData";
175 #endif //BT_CONE_MINKOWSKI_H