add support for X,Z axis aligned capsules

This commit is contained in:
ejcoumans
2008-02-08 01:11:05 +00:00
parent 71b58309cf
commit 618263163c
2 changed files with 25 additions and 43 deletions

View File

@@ -21,6 +21,7 @@ subject to the following restrictions:
btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
{ {
m_upAxis = 1;
m_implicitShapeDimensions.setValue(radius,0.5f*height,radius); 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) btCapsuleShapeX::btCapsuleShapeX(btScalar radius,btScalar height)
{ {
m_implicitShapeDimensions.setValue(0.5f*height, radius,radius); m_upAxis = 0;
} m_implicitShapeDimensions.setValue(0.5f*height, radius,radius);
}
btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius,btScalar height) btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius,btScalar height)
{ {
m_implicitShapeDimensions.setValue(radius,radius,0.5f*height); m_upAxis = 2;
} m_implicitShapeDimensions.setValue(radius,radius,0.5f*height);
}

View File

@@ -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. ///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 class btCapsuleShape : public btConvexInternalShape
{ {
protected:
int m_upAxis;
protected: protected:
///only used for btCapsuleShapeZ and btCapsuleShapeX subclasses. ///only used for btCapsuleShapeZ and btCapsuleShapeX subclasses.
btCapsuleShape() {}; btCapsuleShape() {};
@@ -47,19 +50,20 @@ public:
return "CapsuleShape"; 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: public:
btCapsuleShapeX(btScalar radius,btScalar height); btCapsuleShapeX(btScalar radius,btScalar height);
virtual int getUpAxis() const //debugging
{
return 0;
}
//debugging
virtual const char* getName()const virtual const char* getName()const
{ {
return "CapsuleX"; 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: public:
btCapsuleShapeZ(btScalar radius,btScalar height); btCapsuleShapeZ(btScalar radius,btScalar height);
virtual int getUpAxis() const
{
return 2;
}
//debugging //debugging
virtual const char* getName()const virtual const char* getName()const
{ {
return "CapsuleZ"; return "CapsuleZ";
} }
virtual btScalar getRadius() const
{
return m_implicitShapeDimensions.getX();
}
virtual btScalar getHalfHeight() const
{
return m_implicitShapeDimensions.getZ();
}
}; };