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

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btConeShape.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_CONE_MINKOWSKI_H
17 #define BT_CONE_MINKOWSKI_H
18
19 #include "btConvexInternalShape.h"
20 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
21
23 ATTRIBUTE_ALIGNED16(class) btConeShape : public btConvexInternalShape
24
25 {
26
27 btScalar m_sinAngle;
28 btScalar m_radius;
29 btScalar m_height;
30 int m_coneIndices[3];
31 btVector3 coneLocalSupport(const btVector3& v) const;
32
33
34 public:
35 BT_DECLARE_ALIGNED_ALLOCATOR();
36
37 btConeShape (btScalar radius,btScalar height);
38
39 virtual btVector3 localGetSupportingVertex(const btVector3& vec) const;
40 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const;
41 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
42
43 btScalar getRadius() const { return m_radius;}
44 btScalar getHeight() const { return m_height;}
45
46
47 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const
48 {
49 btTransform identity;
50 identity.setIdentity();
51 btVector3 aabbMin,aabbMax;
52 getAabb(identity,aabbMin,aabbMax);
53
54 btVector3 halfExtents = (aabbMax-aabbMin)*btScalar(0.5);
55
56 btScalar margin = getMargin();
57
58 btScalar lx=btScalar(2.)*(halfExtents.x()+margin);
59 btScalar ly=btScalar(2.)*(halfExtents.y()+margin);
60 btScalar lz=btScalar(2.)*(halfExtents.z()+margin);
61 const btScalar x2 = lx*lx;
62 const btScalar y2 = ly*ly;
63 const btScalar z2 = lz*lz;
64 const btScalar scaledmass = mass * btScalar(0.08333333);
65
66 inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
67
68 // inertia.x() = scaledmass * (y2+z2);
69 // inertia.y() = scaledmass * (x2+z2);
70 // inertia.z() = scaledmass * (x2+y2);
71 }
72
73
74 virtual const char* getName()const
75 {
76 return "Cone";
77 }
78
80 void setConeUpIndex(int upIndex);
81
82 int getConeUpIndex() const
83 {
84 return m_coneIndices[1];
85 }
86
87 virtual btVector3 getAnisotropicRollingFrictionDirection() const
88 {
89 return btVector3 (0,1,0);
90 }
91
92 virtual void setLocalScaling(const btVector3& scaling);
93
94
95 virtual int calculateSerializeBufferSize() const;
96
98 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
99
100
101 };
102
104 class btConeShapeX : public btConeShape
105 {
106 public:
107 btConeShapeX(btScalar radius,btScalar height);
108
109 virtual btVector3 getAnisotropicRollingFrictionDirection() const
110 {
111 return btVector3 (1,0,0);
112 }
113
114 //debugging
115 virtual const char* getName()const
116 {
117 return "ConeX";
118 }
119
120
121 };
122
124 class btConeShapeZ : public btConeShape
125 {
126 public:
127 btConeShapeZ(btScalar radius,btScalar height);
128
129 virtual btVector3 getAnisotropicRollingFrictionDirection() const
130 {
131 return btVector3 (0,0,1);
132 }
133
134 //debugging
135 virtual const char* getName()const
136 {
137 return "ConeZ";
138 }
139
140
141 };
142
144 struct btConeShapeData
145 {
146 btConvexInternalShapeData m_convexInternalShapeData;
147
148 int m_upIndex;
149
150 char m_padding[4];
151 };
152
153 SIMD_FORCE_INLINE int btConeShape::calculateSerializeBufferSize() const
154 {
155 return sizeof(btConeShapeData);
156 }
157
159 SIMD_FORCE_INLINE const char* btConeShape::serialize(void* dataBuffer, btSerializer* serializer) const
160 {
161 btConeShapeData* shapeData = (btConeShapeData*) dataBuffer;
162
163 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer);
164
165 shapeData->m_upIndex = m_coneIndices[1];
166
167 return "btConeShapeData";
168 }
169
170 #endif //BT_CONE_MINKOWSKI_H
171
btConeShape::calculateSerializeBufferSize
virtual int calculateSerializeBufferSize() const
Definition: btConeShape.h:153
btConeShapeX::getName
virtual const char * getName() const
Definition: btConeShape.h:115
btConeShape::getRadius
btScalar getRadius() const
Definition: btConeShape.h:43
btConvexInternalShape
The btConvexInternalShape is an internal base class, shared by most convex shape implementations.
Definition: btConvexInternalShape.h:29
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
btConeShape::m_coneIndices
int m_coneIndices[3]
Definition: btConeShape.h:30
btTransform::setIdentity
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:172
btConeShapeX::getAnisotropicRollingFrictionDirection
virtual btVector3 getAnisotropicRollingFrictionDirection() const
the getAnisotropicRollingFrictionDirection can be used in combination with setAnisotropicFriction See...
Definition: btConeShape.h:109
btConeShape::getAnisotropicRollingFrictionDirection
virtual btVector3 getAnisotropicRollingFrictionDirection() const
the getAnisotropicRollingFrictionDirection can be used in combination with setAnisotropicFriction See...
Definition: btConeShape.h:87
btConvexInternalShape::m_padding
btScalar m_padding
Definition: btConvexInternalShape.h:41
btConeShapeX
btConeShape implements a Cone shape, around the X axis
Definition: btConeShape.h:104
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:63
btConvexInternalShapeData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btConvexInternalShape.h:144
btConeShape::m_height
btScalar m_height
Definition: btConeShape.h:29
btConeShape::getConeUpIndex
int getConeUpIndex() const
Definition: btConeShape.h:82
btSerializer
Definition: btSerializer.h:68
btVector3::x
const btScalar & x() const
Return the x value.
Definition: btVector3.h:575
btConeShape::m_radius
btScalar m_radius
Definition: btConeShape.h:28
btConeShapeData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btConeShape.h:144
btConeShape
The btConeShape implements a cone shape primitive, centered around the origin and aligned with the Y ...
Definition: btConeShape.h:23
btConeShape::getHeight
btScalar getHeight() const
Definition: btConeShape.h:44
btConeShape::getName
virtual const char * getName() const
Definition: btConeShape.h:74
btConvexInternalShape.h
btBroadphaseProxy.h
btConeShapeZ::getAnisotropicRollingFrictionDirection
virtual btVector3 getAnisotropicRollingFrictionDirection() const
the getAnisotropicRollingFrictionDirection can be used in combination with setAnisotropicFriction See...
Definition: btConeShape.h:129
btConeShapeX::btConeShapeX
btConeShapeX(btScalar radius, btScalar height)
Definition: btConeShape.cpp:36
btVector3::y
const btScalar & y() const
Return the y value.
Definition: btVector3.h:577
btConeShapeData::m_convexInternalShapeData
btConvexInternalShapeData m_convexInternalShapeData
Definition: btConeShape.h:146
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:64
btConeShape::serialize
virtual const char * serialize(void *dataBuffer, btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
Definition: btConeShape.h:159
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btConeShapeZ
btConeShapeZ implements a Cone shape, around the Z axis
Definition: btConeShape.h:124
btConeShapeData::m_upIndex
int m_upIndex
Definition: btConeShape.h:148
BT_DECLARE_ALIGNED_ALLOCATOR
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:388
btConeShape::calculateLocalInertia
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
Definition: btConeShape.h:47
btConeShape::m_sinAngle
btScalar m_sinAngle
Definition: btConeShape.h:27
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:278
btConeShapeZ::getName
virtual const char * getName() const
Definition: btConeShape.h:135
btVector3::z
const btScalar & z() const
Return the z value.
Definition: btVector3.h:579