Bullet Collision Detection & Physics Library
btConeShape.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 "btConeShape.h"
17
18
19
21m_radius (radius),
22m_height(height)
23{
26 btVector3 halfExtents;
28}
29
31btConeShape(radius,height)
32{
34}
35
37btConeShape(radius,height)
38{
40}
41
44{
45 switch (upIndex)
46 {
47 case 0:
48 m_coneIndices[0] = 1;
49 m_coneIndices[1] = 0;
50 m_coneIndices[2] = 2;
51 break;
52 case 1:
53 m_coneIndices[0] = 0;
54 m_coneIndices[1] = 1;
55 m_coneIndices[2] = 2;
56 break;
57 case 2:
58 m_coneIndices[0] = 0;
59 m_coneIndices[1] = 2;
60 m_coneIndices[2] = 1;
61 break;
62 default:
63 btAssert(0);
64 };
65
69}
70
72{
73
74 btScalar halfHeight = m_height * btScalar(0.5);
75
76 if (v[m_coneIndices[1]] > v.length() * m_sinAngle)
77 {
78 btVector3 tmp;
79
80 tmp[m_coneIndices[0]] = btScalar(0.);
81 tmp[m_coneIndices[1]] = halfHeight;
82 tmp[m_coneIndices[2]] = btScalar(0.);
83 return tmp;
84 }
85 else {
86 btScalar s = btSqrt(v[m_coneIndices[0]] * v[m_coneIndices[0]] + v[m_coneIndices[2]] * v[m_coneIndices[2]]);
87 if (s > SIMD_EPSILON) {
88 btScalar d = m_radius / s;
89 btVector3 tmp;
90 tmp[m_coneIndices[0]] = v[m_coneIndices[0]] * d;
91 tmp[m_coneIndices[1]] = -halfHeight;
92 tmp[m_coneIndices[2]] = v[m_coneIndices[2]] * d;
93 return tmp;
94 }
95 else {
96 btVector3 tmp;
97 tmp[m_coneIndices[0]] = btScalar(0.);
98 tmp[m_coneIndices[1]] = -halfHeight;
99 tmp[m_coneIndices[2]] = btScalar(0.);
100 return tmp;
101 }
102 }
103
104}
105
107{
108 return coneLocalSupport(vec);
109}
110
111void btConeShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
112{
113 for (int i=0;i<numVectors;i++)
114 {
115 const btVector3& vec = vectors[i];
116 supportVerticesOut[i] = coneLocalSupport(vec);
117 }
118}
119
120
122{
123 btVector3 supVertex = coneLocalSupport(vec);
124 if ( getMargin()!=btScalar(0.) )
125 {
126 btVector3 vecnorm = vec;
127 if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
128 {
129 vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
130 }
131 vecnorm.normalize();
132 supVertex+= getMargin() * vecnorm;
133 }
134 return supVertex;
135}
136
137
139{
140 int axis = m_coneIndices[1];
141 int r1 = m_coneIndices[0];
142 int r2 = m_coneIndices[2];
143 m_height *= scaling[axis] / m_localScaling[axis];
144 m_radius *= (scaling[r1] / m_localScaling[r1] + scaling[r2] / m_localScaling[r2]) / 2;
147}
@ CONE_SHAPE_PROXYTYPE
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
btScalar btSqrt(btScalar y)
Definition: btScalar.h:444
#define SIMD_EPSILON
Definition: btScalar.h:521
#define btAssert(x)
Definition: btScalar.h:131
btConeShapeX(btScalar radius, btScalar height)
Definition: btConeShape.cpp:36
btConeShapeZ(btScalar radius, btScalar height)
Definition: btConeShape.cpp:30
The btConeShape implements a cone shape primitive, centered around the origin and aligned with the Y ...
Definition: btConeShape.h:25
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const
btConeShape(btScalar radius, btScalar height)
Definition: btConeShape.cpp:20
btScalar m_height
Definition: btConeShape.h:29
btScalar m_radius
Definition: btConeShape.h:28
btScalar m_sinAngle
Definition: btConeShape.h:27
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const
virtual void setLocalScaling(const btVector3 &scaling)
int m_coneIndices[3]
Definition: btConeShape.h:30
btVector3 coneLocalSupport(const btVector3 &v) const
Definition: btConeShape.cpp:71
void setConeUpIndex(int upIndex)
choose upAxis index
Definition: btConeShape.cpp:43
virtual btVector3 localGetSupportingVertex(const btVector3 &vec) const
The btConvexInternalShape is an internal base class, shared by most convex shape implementations.
virtual void setLocalScaling(const btVector3 &scaling)
virtual btScalar getMargin() const
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:84
btScalar length() const
Return the length of the vector.
Definition: btVector3.h:263
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:652
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition: btVector3.h:309