Bullet Collision Detection & Physics Library
btCapsuleShape.cpp
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16
17#include "btCapsuleShape.h"
18
20
22{
23 m_collisionMargin = radius;
25 m_upAxis = 1;
26 m_implicitShapeDimensions.setValue(radius,0.5f*height,radius);
27}
28
29
31{
32
33 btVector3 supVec(0,0,0);
34
36
37 btVector3 vec = vec0;
38 btScalar lenSqr = vec.length2();
39 if (lenSqr < btScalar(0.0001))
40 {
41 vec.setValue(1,0,0);
42 } else
43 {
44 btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
45 vec *= rlen;
46 }
47
48 btVector3 vtx;
49 btScalar newDot;
50
51
52
53 {
54 btVector3 pos(0,0,0);
55 pos[getUpAxis()] = getHalfHeight();
56
57 vtx = pos;
58 newDot = vec.dot(vtx);
59 if (newDot > maxDot)
60 {
61 maxDot = newDot;
62 supVec = vtx;
63 }
64 }
65 {
66 btVector3 pos(0,0,0);
67 pos[getUpAxis()] = -getHalfHeight();
68
69 vtx = pos;
70 newDot = vec.dot(vtx);
71 if (newDot > maxDot)
72 {
73 maxDot = newDot;
74 supVec = vtx;
75 }
76 }
77
78 return supVec;
79
80}
81
82 void btCapsuleShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
83{
84
85
86
87 for (int j=0;j<numVectors;j++)
88 {
90 const btVector3& vec = vectors[j];
91
92 btVector3 vtx;
93 btScalar newDot;
94 {
95 btVector3 pos(0,0,0);
96 pos[getUpAxis()] = getHalfHeight();
97 vtx = pos;
98 newDot = vec.dot(vtx);
99 if (newDot > maxDot)
100 {
101 maxDot = newDot;
102 supportVerticesOut[j] = vtx;
103 }
104 }
105 {
106 btVector3 pos(0,0,0);
107 pos[getUpAxis()] = -getHalfHeight();
108 vtx = pos;
109 newDot = vec.dot(vtx);
110 if (newDot > maxDot)
111 {
112 maxDot = newDot;
113 supportVerticesOut[j] = vtx;
114 }
115 }
116
117 }
118}
119
120
122{
123 //as an approximation, take the inertia of the box that bounds the spheres
124
125 btTransform ident;
126 ident.setIdentity();
127
128
129 btScalar radius = getRadius();
130
131 btVector3 halfExtents(radius,radius,radius);
132 halfExtents[getUpAxis()]+=getHalfHeight();
133
134 btScalar lx=btScalar(2.)*(halfExtents[0]);
135 btScalar ly=btScalar(2.)*(halfExtents[1]);
136 btScalar lz=btScalar(2.)*(halfExtents[2]);
137 const btScalar x2 = lx*lx;
138 const btScalar y2 = ly*ly;
139 const btScalar z2 = lz*lz;
140 const btScalar scaledmass = mass * btScalar(.08333333);
141
142 inertia[0] = scaledmass * (y2+z2);
143 inertia[1] = scaledmass * (x2+z2);
144 inertia[2] = scaledmass * (x2+y2);
145
146}
147
149{
150 m_collisionMargin = radius;
151 m_upAxis = 0;
152 m_implicitShapeDimensions.setValue(0.5f*height, radius,radius);
153}
154
155
156
157
158
159
161{
162 m_collisionMargin = radius;
163 m_upAxis = 2;
164 m_implicitShapeDimensions.setValue(radius,radius,0.5f*height);
165}
166
167
168
169
@ CAPSULE_SHAPE_PROXYTYPE
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
#define BT_LARGE_FLOAT
Definition: btScalar.h:294
btScalar btSqrt(btScalar y)
Definition: btScalar.h:444
btCapsuleShapeX(btScalar radius, btScalar height)
btCapsuleShapeZ(btScalar radius, btScalar height)
btCapsuleShape()
only used for btCapsuleShapeZ and btCapsuleShapeX subclasses.
btScalar getRadius() const
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const
btConvexShape Interface
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
CollisionShape Interface.
int getUpAxis() const
btScalar getHalfHeight() const
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const
The btConvexInternalShape is an internal base class, shared by most convex shape implementations.
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:172
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:84
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition: btVector3.h:235
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:652
btScalar length2() const
Return the length of the vector squared.
Definition: btVector3.h:257