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 #include "btConeShape.h"
20 btConeShape::btConeShape (btScalar radius,btScalar height): btConvexInternalShape (),
24 m_shapeType = CONE_SHAPE_PROXYTYPE;
26 btVector3 halfExtents;
27 m_sinAngle = (m_radius / btSqrt(m_radius * m_radius + m_height * m_height));
30 btConeShapeZ::btConeShapeZ (btScalar radius,btScalar height):
31 btConeShape(radius,height)
36 btConeShapeX::btConeShapeX (btScalar radius,btScalar height):
37 btConeShape(radius,height)
42 ///choose upAxis index
43 void btConeShape::setConeUpIndex(int upIndex)
67 btVector3 btConeShape::coneLocalSupport(const btVector3& v) const
70 btScalar halfHeight = m_height * btScalar(0.5);
72 if (v[m_coneIndices[1]] > v.length() * m_sinAngle)
76 tmp[m_coneIndices[0]] = btScalar(0.);
77 tmp[m_coneIndices[1]] = halfHeight;
78 tmp[m_coneIndices[2]] = btScalar(0.);
82 btScalar s = btSqrt(v[m_coneIndices[0]] * v[m_coneIndices[0]] + v[m_coneIndices[2]] * v[m_coneIndices[2]]);
83 if (s > SIMD_EPSILON) {
84 btScalar d = m_radius / s;
86 tmp[m_coneIndices[0]] = v[m_coneIndices[0]] * d;
87 tmp[m_coneIndices[1]] = -halfHeight;
88 tmp[m_coneIndices[2]] = v[m_coneIndices[2]] * d;
93 tmp[m_coneIndices[0]] = btScalar(0.);
94 tmp[m_coneIndices[1]] = -halfHeight;
95 tmp[m_coneIndices[2]] = btScalar(0.);
102 btVector3 btConeShape::localGetSupportingVertexWithoutMargin(const btVector3& vec) const
104 return coneLocalSupport(vec);
107 void btConeShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
109 for (int i=0;i<numVectors;i++)
111 const btVector3& vec = vectors[i];
112 supportVerticesOut[i] = coneLocalSupport(vec);
117 btVector3 btConeShape::localGetSupportingVertex(const btVector3& vec) const
119 btVector3 supVertex = coneLocalSupport(vec);
120 if ( getMargin()!=btScalar(0.) )
122 btVector3 vecnorm = vec;
123 if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
125 vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
128 supVertex+= getMargin() * vecnorm;
134 void btConeShape::setLocalScaling(const btVector3& scaling)
136 int axis = m_coneIndices[1];
137 int r1 = m_coneIndices[0];
138 int r2 = m_coneIndices[2];
139 m_height *= scaling[axis] / m_localScaling[axis];
140 m_radius *= (scaling[r1] / m_localScaling[r1] + scaling[r2] / m_localScaling[r2]) / 2;
141 m_sinAngle = (m_radius / btSqrt(m_radius * m_radius + m_height * m_height));
142 btConvexInternalShape::setLocalScaling(scaling);