added btCapsuleShapeX and btCapsuleShapeZ, for X and Z upaxis capsules. The default btCapsuleShape stays Y-axis, for backwards compatibility.
This commit is contained in:
@@ -50,7 +50,9 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
btVector3 pos(0,getHalfHeight(),0);
|
btVector3 pos(0,0,0);
|
||||||
|
pos[getUpAxis()] = getHalfHeight();
|
||||||
|
|
||||||
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
||||||
newDot = vec.dot(vtx);
|
newDot = vec.dot(vtx);
|
||||||
if (newDot > maxDot)
|
if (newDot > maxDot)
|
||||||
@@ -60,7 +62,9 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
btVector3 pos(0,-getHalfHeight(),0);
|
btVector3 pos(0,0,0);
|
||||||
|
pos[getUpAxis()] = -getHalfHeight();
|
||||||
|
|
||||||
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
||||||
newDot = vec.dot(vtx);
|
newDot = vec.dot(vtx);
|
||||||
if (newDot > maxDot)
|
if (newDot > maxDot)
|
||||||
@@ -88,7 +92,8 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
|
|||||||
btVector3 vtx;
|
btVector3 vtx;
|
||||||
btScalar newDot;
|
btScalar newDot;
|
||||||
{
|
{
|
||||||
btVector3 pos(0,getHalfHeight(),0);
|
btVector3 pos(0,0,0);
|
||||||
|
pos[getUpAxis()] = getHalfHeight();
|
||||||
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
||||||
newDot = vec.dot(vtx);
|
newDot = vec.dot(vtx);
|
||||||
if (newDot > maxDot)
|
if (newDot > maxDot)
|
||||||
@@ -98,7 +103,8 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
btVector3 pos(0,-getHalfHeight(),0);
|
btVector3 pos(0,0,0);
|
||||||
|
pos[getUpAxis()] = -getHalfHeight();
|
||||||
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
||||||
newDot = vec.dot(vtx);
|
newDot = vec.dot(vtx);
|
||||||
if (newDot > maxDot)
|
if (newDot > maxDot)
|
||||||
@@ -122,7 +128,8 @@ void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia) con
|
|||||||
|
|
||||||
btScalar radius = getRadius();
|
btScalar radius = getRadius();
|
||||||
|
|
||||||
btVector3 halfExtents(radius,radius+getHalfHeight(),radius);
|
btVector3 halfExtents(radius,radius,radius);
|
||||||
|
halfExtents[getUpAxis()]+=getHalfHeight();
|
||||||
|
|
||||||
btScalar margin = CONVEX_DISTANCE_MARGIN;
|
btScalar margin = CONVEX_DISTANCE_MARGIN;
|
||||||
|
|
||||||
@@ -140,6 +147,20 @@ void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia) con
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btCapsuleShapeX::btCapsuleShapeX(btScalar radius,btScalar height)
|
||||||
|
{
|
||||||
|
m_implicitShapeDimensions.setValue(0.5f*height, radius,radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius,btScalar height)
|
||||||
|
{
|
||||||
|
m_implicitShapeDimensions.setValue(radius,radius,0.5f*height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,12 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
///btCapsuleShape represents a capsule around the Y axis
|
///btCapsuleShape represents a capsule around the Y axis
|
||||||
///A more general solution that can represent capsules is the btMultiSphereShape
|
///A more general solution that can represent capsules is the btMultiSphereShape
|
||||||
|
///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:
|
||||||
|
///only used for btCapsuleShapeZ and btCapsuleShapeX subclasses.
|
||||||
|
btCapsuleShape() {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
btCapsuleShape(btScalar radius,btScalar height);
|
btCapsuleShape(btScalar radius,btScalar height);
|
||||||
@@ -43,18 +47,82 @@ public:
|
|||||||
return "CapsuleShape";
|
return "CapsuleShape";
|
||||||
}
|
}
|
||||||
|
|
||||||
btScalar getRadius() const
|
virtual int getUpAxis() const
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual btScalar getRadius() const
|
||||||
{
|
{
|
||||||
return m_implicitShapeDimensions.getX();
|
return m_implicitShapeDimensions.getX();
|
||||||
}
|
}
|
||||||
|
|
||||||
btScalar getHalfHeight() const
|
virtual btScalar getHalfHeight() const
|
||||||
{
|
{
|
||||||
return m_implicitShapeDimensions.getY();
|
return m_implicitShapeDimensions.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///btCapsuleShapeX represents a capsule around the Z axis
|
||||||
|
///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 btCapsuleShapeX : public btCapsuleShape
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
btCapsuleShapeX(btScalar radius,btScalar height);
|
||||||
|
|
||||||
|
virtual int getUpAxis() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//debugging
|
||||||
|
virtual const char* getName()const
|
||||||
|
{
|
||||||
|
return "CapsuleX";
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual btScalar getRadius() const
|
||||||
|
{
|
||||||
|
return m_implicitShapeDimensions.getY();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual btScalar getHalfHeight() const
|
||||||
|
{
|
||||||
|
return m_implicitShapeDimensions.getX();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
///btCapsuleShapeZ represents a capsule around the Z axis
|
||||||
|
///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 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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif //BT_CAPSULE_SHAPE_H
|
#endif //BT_CAPSULE_SHAPE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user