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"
18 btConeShape::btConeShape(btScalar radius, btScalar height) : btConvexInternalShape(),
22 m_shapeType = CONE_SHAPE_PROXYTYPE;
24 btVector3 halfExtents;
25 m_sinAngle = (m_radius / btSqrt(m_radius * m_radius + m_height * m_height));
28 btConeShapeZ::btConeShapeZ(btScalar radius, btScalar height) : btConeShape(radius, height)
33 btConeShapeX::btConeShapeX(btScalar radius, btScalar height) : btConeShape(radius, height)
38 ///choose upAxis index
39 void btConeShape::setConeUpIndex(int upIndex)
62 m_implicitShapeDimensions[m_coneIndices[0]] = m_radius;
63 m_implicitShapeDimensions[m_coneIndices[1]] = m_height;
64 m_implicitShapeDimensions[m_coneIndices[2]] = m_radius;
67 btVector3 btConeShape::coneLocalSupport(const btVector3& v) const
69 btScalar halfHeight = m_height * btScalar(0.5);
71 if (v[m_coneIndices[1]] > v.length() * m_sinAngle)
75 tmp[m_coneIndices[0]] = btScalar(0.);
76 tmp[m_coneIndices[1]] = halfHeight;
77 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]]);
85 btScalar d = m_radius / s;
87 tmp[m_coneIndices[0]] = v[m_coneIndices[0]] * d;
88 tmp[m_coneIndices[1]] = -halfHeight;
89 tmp[m_coneIndices[2]] = v[m_coneIndices[2]] * d;
95 tmp[m_coneIndices[0]] = btScalar(0.);
96 tmp[m_coneIndices[1]] = -halfHeight;
97 tmp[m_coneIndices[2]] = btScalar(0.);
103 btVector3 btConeShape::localGetSupportingVertexWithoutMargin(const btVector3& vec) const
105 return coneLocalSupport(vec);
108 void btConeShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const
110 for (int i = 0; i < numVectors; i++)
112 const btVector3& vec = vectors[i];
113 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;
133 void btConeShape::setLocalScaling(const btVector3& scaling)
135 int axis = m_coneIndices[1];
136 int r1 = m_coneIndices[0];
137 int r2 = m_coneIndices[2];
138 m_height *= scaling[axis] / m_localScaling[axis];
139 m_radius *= (scaling[r1] / m_localScaling[r1] + scaling[r2] / m_localScaling[r2]) / 2;
140 m_sinAngle = (m_radius / btSqrt(m_radius * m_radius + m_height * m_height));
141 btConvexInternalShape::setLocalScaling(scaling);