From 0060c42ae8aaee323522a30b8ed548f94e35760b Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 23 Jan 2017 19:38:14 -0800 Subject: [PATCH] more fixes for btCapsuleShape: its entire radius is collision margin, don't let the user override it (similar to a btSphereShape) --- .../CollisionShapes/btCapsuleShape.cpp | 19 ++++++++----------- .../CollisionShapes/btCapsuleShape.h | 9 +-------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp b/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp index 89522d7b8..283b0fb4e 100644 --- a/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp +++ b/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp @@ -19,10 +19,9 @@ subject to the following restrictions: #include "BulletCollision/CollisionShapes/btCollisionMargin.h" #include "LinearMath/btQuaternion.h" -btCapsuleShape::btCapsuleShape(btScalar orgRadius, btScalar height) : btConvexInternalShape () +btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInternalShape () { - m_collisionMargin = orgRadius; - btScalar radius = 0.f; + m_collisionMargin = radius; m_shapeType = CAPSULE_SHAPE_PROXYTYPE; m_upAxis = 1; m_implicitShapeDimensions.setValue(radius,0.5f*height,radius); @@ -98,7 +97,7 @@ btCapsuleShape::btCapsuleShape(btScalar orgRadius, btScalar height) : btConvexIn { btVector3 pos(0,0,0); pos[getUpAxis()] = getHalfHeight(); - vtx = pos +vec*(radius) - vec * getMargin(); + vtx = pos +vec*(radius); newDot = vec.dot(vtx); if (newDot > maxDot) { @@ -109,7 +108,7 @@ btCapsuleShape::btCapsuleShape(btScalar orgRadius, btScalar height) : btConvexIn { btVector3 pos(0,0,0); pos[getUpAxis()] = -getHalfHeight(); - vtx = pos +vec*(radius) - vec * getMargin(); + vtx = pos +vec*(radius); newDot = vec.dot(vtx); if (newDot > maxDot) { @@ -151,10 +150,9 @@ void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia) con } -btCapsuleShapeX::btCapsuleShapeX(btScalar orgRadius,btScalar height) +btCapsuleShapeX::btCapsuleShapeX(btScalar radius,btScalar height) { - m_collisionMargin = orgRadius; - btScalar radius = 0.f; + m_collisionMargin = radius; m_upAxis = 0; m_implicitShapeDimensions.setValue(0.5f*height, radius,radius); } @@ -164,10 +162,9 @@ btCapsuleShapeX::btCapsuleShapeX(btScalar orgRadius,btScalar height) -btCapsuleShapeZ::btCapsuleShapeZ(btScalar orgRadius,btScalar height) +btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius,btScalar height) { - m_collisionMargin = orgRadius; - btScalar radius = 0.f; + m_collisionMargin = radius; m_upAxis = 2; m_implicitShapeDimensions.setValue(radius,radius,0.5f*height); } diff --git a/src/BulletCollision/CollisionShapes/btCapsuleShape.h b/src/BulletCollision/CollisionShapes/btCapsuleShape.h index f8c55ace4..04d1c89e8 100644 --- a/src/BulletCollision/CollisionShapes/btCapsuleShape.h +++ b/src/BulletCollision/CollisionShapes/btCapsuleShape.h @@ -48,14 +48,7 @@ public: virtual void setMargin(btScalar collisionMargin) { - //correct the m_implicitShapeDimensions for the margin - btVector3 oldMargin(getMargin(),getMargin(),getMargin()); - btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin; - - btConvexInternalShape::setMargin(collisionMargin); - btVector3 newMargin(getMargin(),getMargin(),getMargin()); - m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin; - + //don't override the margin for capsules, their entire radius == margin } virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const