diff --git a/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp b/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp index 75679dbac..1c464772c 100644 --- a/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp +++ b/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp @@ -21,6 +21,7 @@ subject to the following restrictions: btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) { + m_upAxis = 1; m_implicitShapeDimensions.setValue(radius,0.5f*height,radius); } @@ -147,20 +148,22 @@ void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia) con } -btCapsuleShapeX::btCapsuleShapeX(btScalar radius,btScalar height) -{ - m_implicitShapeDimensions.setValue(0.5f*height, radius,radius); -} +btCapsuleShapeX::btCapsuleShapeX(btScalar radius,btScalar height) +{ + m_upAxis = 0; + m_implicitShapeDimensions.setValue(0.5f*height, radius,radius); +} -btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius,btScalar height) -{ - m_implicitShapeDimensions.setValue(radius,radius,0.5f*height); -} +btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius,btScalar height) +{ + 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 a830ec036..06fd2b7be 100644 --- a/src/BulletCollision/CollisionShapes/btCapsuleShape.h +++ b/src/BulletCollision/CollisionShapes/btCapsuleShape.h @@ -25,6 +25,9 @@ subject to the following restrictions: ///the total height is height+2*radius, so the height is just the height between the center of each 'sphere' of the capsule caps. class btCapsuleShape : public btConvexInternalShape { +protected: + int m_upAxis; + protected: ///only used for btCapsuleShapeZ and btCapsuleShapeX subclasses. btCapsuleShape() {}; @@ -47,19 +50,20 @@ public: return "CapsuleShape"; } - virtual int getUpAxis() const + int getUpAxis() const { - return 1; + return m_upAxis; } - virtual btScalar getRadius() const + btScalar getRadius() const { - return m_implicitShapeDimensions.getX(); + int radiusAxis = (m_upAxis+2)%3; + return m_implicitShapeDimensions[radiusAxis]; } - virtual btScalar getHalfHeight() const + btScalar getHalfHeight() const { - return m_implicitShapeDimensions.getY(); + return m_implicitShapeDimensions[m_upAxis]; } }; @@ -71,27 +75,14 @@ class btCapsuleShapeX : public btCapsuleShape public: btCapsuleShapeX(btScalar radius,btScalar height); - - virtual int getUpAxis() const - { - return 0; - } - - //debugging + + //debugging virtual const char* getName()const { return "CapsuleX"; } - virtual btScalar getRadius() const - { - return m_implicitShapeDimensions.getY(); - } - - virtual btScalar getHalfHeight() const - { - return m_implicitShapeDimensions.getX(); - } + }; @@ -102,25 +93,13 @@ class btCapsuleShapeZ : public btCapsuleShape public: btCapsuleShapeZ(btScalar radius,btScalar height); - virtual int getUpAxis() const - { - return 2; - } //debugging virtual const char* getName()const { return "CapsuleZ"; } - virtual btScalar getRadius() const - { - return m_implicitShapeDimensions.getX(); - } - - virtual btScalar getHalfHeight() const - { - return m_implicitShapeDimensions.getZ(); - } + };