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#include "btCapsuleShape.h"
17
19
21{
24 m_upAxis = 1;
26}
27
29{
30 btVector3 supVec(0, 0, 0);
31
33
36 if (lenSqr < btScalar(0.0001))
37 {
38 vec.setValue(1, 0, 0);
39 }
40 else
41 {
43 vec *= rlen;
44 }
45
48
49 {
50 btVector3 pos(0, 0, 0);
52
53 vtx = pos;
54 newDot = vec.dot(vtx);
55 if (newDot > maxDot)
56 {
57 maxDot = newDot;
58 supVec = vtx;
59 }
60 }
61 {
62 btVector3 pos(0, 0, 0);
64
65 vtx = pos;
66 newDot = vec.dot(vtx);
67 if (newDot > maxDot)
68 {
69 maxDot = newDot;
70 supVec = vtx;
71 }
72 }
73
74 return supVec;
75}
76
78{
79 for (int j = 0; j < numVectors; j++)
80 {
82 const btVector3& vec = vectors[j];
83
86 {
87 btVector3 pos(0, 0, 0);
89 vtx = pos;
90 newDot = vec.dot(vtx);
91 if (newDot > maxDot)
92 {
93 maxDot = newDot;
95 }
96 }
97 {
98 btVector3 pos(0, 0, 0);
100 vtx = pos;
101 newDot = vec.dot(vtx);
102 if (newDot > maxDot)
103 {
104 maxDot = newDot;
106 }
107 }
108 }
109}
110
112{
113 //as an approximation, take the inertia of the box that bounds the spheres
114
117
119
122
123 btScalar lx = btScalar(2.) * (halfExtents[0]);
124 btScalar ly = btScalar(2.) * (halfExtents[1]);
125 btScalar lz = btScalar(2.) * (halfExtents[2]);
126 const btScalar x2 = lx * lx;
127 const btScalar y2 = ly * ly;
128 const btScalar z2 = lz * lz;
129 const btScalar scaledmass = mass * btScalar(.08333333);
130
131 inertia[0] = scaledmass * (y2 + z2);
132 inertia[1] = scaledmass * (x2 + z2);
133 inertia[2] = scaledmass * (x2 + y2);
134}
135
137{
139 m_upAxis = 0;
141}
142
144{
146 m_upAxis = 2;
148}
@ CAPSULE_SHAPE_PROXYTYPE
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:27
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define BT_LARGE_FLOAT
Definition btScalar.h:316
btScalar btSqrt(btScalar y)
Definition btScalar.h:466
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:30
void setIdentity()
Set this transformation to the identity.
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition btVector3.h:640
btScalar length2() const
Return the length of the vector squared.
Definition btVector3.h:251