diff options
Diffstat (limited to 'thirdparty/bullet/BulletCollision/CollisionShapes/btCapsuleShape.cpp')
-rw-r--r-- | thirdparty/bullet/BulletCollision/CollisionShapes/btCapsuleShape.cpp | 81 |
1 files changed, 30 insertions, 51 deletions
diff --git a/thirdparty/bullet/BulletCollision/CollisionShapes/btCapsuleShape.cpp b/thirdparty/bullet/BulletCollision/CollisionShapes/btCapsuleShape.cpp index 0345501ce2..7c33774284 100644 --- a/thirdparty/bullet/BulletCollision/CollisionShapes/btCapsuleShape.cpp +++ b/thirdparty/bullet/BulletCollision/CollisionShapes/btCapsuleShape.cpp @@ -13,24 +13,21 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ - #include "btCapsuleShape.h" #include "LinearMath/btQuaternion.h" -btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInternalShape () +btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInternalShape() { m_collisionMargin = radius; m_shapeType = CAPSULE_SHAPE_PROXYTYPE; m_upAxis = 1; - m_implicitShapeDimensions.setValue(radius,0.5f*height,radius); + m_implicitShapeDimensions.setValue(radius, 0.5f * height, radius); } - - btVector3 btCapsuleShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const +btVector3 btCapsuleShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0) const { - - btVector3 supVec(0,0,0); + btVector3 supVec(0, 0, 0); btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); @@ -38,20 +35,19 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter btScalar lenSqr = vec.length2(); if (lenSqr < btScalar(0.0001)) { - vec.setValue(1,0,0); - } else + vec.setValue(1, 0, 0); + } + else { - btScalar rlen = btScalar(1.) / btSqrt(lenSqr ); + btScalar rlen = btScalar(1.) / btSqrt(lenSqr); vec *= rlen; } btVector3 vtx; btScalar newDot; - - { - btVector3 pos(0,0,0); + btVector3 pos(0, 0, 0); pos[getUpAxis()] = getHalfHeight(); vtx = pos; @@ -63,7 +59,7 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter } } { - btVector3 pos(0,0,0); + btVector3 pos(0, 0, 0); pos[getUpAxis()] = -getHalfHeight(); vtx = pos; @@ -76,15 +72,11 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter } return supVec; - } - void btCapsuleShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const +void btCapsuleShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const { - - - - for (int j=0;j<numVectors;j++) + for (int j = 0; j < numVectors; j++) { btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); const btVector3& vec = vectors[j]; @@ -92,7 +84,7 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter btVector3 vtx; btScalar newDot; { - btVector3 pos(0,0,0); + btVector3 pos(0, 0, 0); pos[getUpAxis()] = getHalfHeight(); vtx = pos; newDot = vec.dot(vtx); @@ -103,7 +95,7 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter } } { - btVector3 pos(0,0,0); + btVector3 pos(0, 0, 0); pos[getUpAxis()] = -getHalfHeight(); vtx = pos; newDot = vec.dot(vtx); @@ -113,57 +105,44 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter supportVerticesOut[j] = vtx; } } - } } - -void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const +void btCapsuleShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const { //as an approximation, take the inertia of the box that bounds the spheres btTransform ident; ident.setIdentity(); - btScalar radius = getRadius(); - btVector3 halfExtents(radius,radius,radius); - halfExtents[getUpAxis()]+=getHalfHeight(); + btVector3 halfExtents(radius, radius, radius); + halfExtents[getUpAxis()] += getHalfHeight(); - btScalar lx=btScalar(2.)*(halfExtents[0]); - btScalar ly=btScalar(2.)*(halfExtents[1]); - btScalar lz=btScalar(2.)*(halfExtents[2]); - const btScalar x2 = lx*lx; - const btScalar y2 = ly*ly; - const btScalar z2 = lz*lz; + btScalar lx = btScalar(2.) * (halfExtents[0]); + btScalar ly = btScalar(2.) * (halfExtents[1]); + btScalar lz = btScalar(2.) * (halfExtents[2]); + const btScalar x2 = lx * lx; + const btScalar y2 = ly * ly; + const btScalar z2 = lz * lz; const btScalar scaledmass = mass * btScalar(.08333333); - inertia[0] = scaledmass * (y2+z2); - inertia[1] = scaledmass * (x2+z2); - inertia[2] = scaledmass * (x2+y2); - + inertia[0] = scaledmass * (y2 + z2); + inertia[1] = scaledmass * (x2 + z2); + inertia[2] = scaledmass * (x2 + y2); } -btCapsuleShapeX::btCapsuleShapeX(btScalar radius,btScalar height) +btCapsuleShapeX::btCapsuleShapeX(btScalar radius, btScalar height) { m_collisionMargin = radius; m_upAxis = 0; - m_implicitShapeDimensions.setValue(0.5f*height, radius,radius); + m_implicitShapeDimensions.setValue(0.5f * height, radius, radius); } - - - - - -btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius,btScalar height) +btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius, btScalar height) { m_collisionMargin = radius; m_upAxis = 2; - m_implicitShapeDimensions.setValue(radius,radius,0.5f*height); + m_implicitShapeDimensions.setValue(radius, radius, 0.5f * height); } - - - - |