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();
|
||||
newDot = vec.dot(vtx);
|
||||
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();
|
||||
newDot = vec.dot(vtx);
|
||||
if (newDot > maxDot)
|
||||
@@ -88,7 +92,8 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
|
||||
btVector3 vtx;
|
||||
btScalar newDot;
|
||||
{
|
||||
btVector3 pos(0,getHalfHeight(),0);
|
||||
btVector3 pos(0,0,0);
|
||||
pos[getUpAxis()] = getHalfHeight();
|
||||
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
||||
newDot = vec.dot(vtx);
|
||||
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();
|
||||
newDot = vec.dot(vtx);
|
||||
if (newDot > maxDot)
|
||||
@@ -122,7 +128,8 @@ void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia) con
|
||||
|
||||
btScalar radius = getRadius();
|
||||
|
||||
btVector3 halfExtents(radius,radius+getHalfHeight(),radius);
|
||||
btVector3 halfExtents(radius,radius,radius);
|
||||
halfExtents[getUpAxis()]+=getHalfHeight();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,60 +1,128 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_CAPSULE_SHAPE_H
|
||||
#define BT_CAPSULE_SHAPE_H
|
||||
|
||||
#include "btConvexInternalShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
|
||||
|
||||
|
||||
///btCapsuleShape represents a capsule around the Y axis
|
||||
///A more general solution that can represent capsules is the btMultiSphereShape
|
||||
class btCapsuleShape : public btConvexInternalShape
|
||||
{
|
||||
|
||||
public:
|
||||
btCapsuleShape(btScalar radius,btScalar height);
|
||||
|
||||
///CollisionShape Interface
|
||||
virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
|
||||
|
||||
/// btConvexShape Interface
|
||||
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
|
||||
|
||||
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
virtual int getShapeType() const { return CAPSULE_SHAPE_PROXYTYPE; }
|
||||
|
||||
virtual const char* getName()const
|
||||
{
|
||||
return "CapsuleShape";
|
||||
}
|
||||
|
||||
btScalar getRadius() const
|
||||
{
|
||||
return m_implicitShapeDimensions.getX();
|
||||
}
|
||||
|
||||
btScalar getHalfHeight() const
|
||||
{
|
||||
return m_implicitShapeDimensions.getY();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //BT_CAPSULE_SHAPE_H
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_CAPSULE_SHAPE_H
|
||||
#define BT_CAPSULE_SHAPE_H
|
||||
|
||||
#include "btConvexInternalShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
|
||||
|
||||
|
||||
///btCapsuleShape represents a capsule around the Y axis
|
||||
///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
|
||||
{
|
||||
protected:
|
||||
///only used for btCapsuleShapeZ and btCapsuleShapeX subclasses.
|
||||
btCapsuleShape() {};
|
||||
|
||||
public:
|
||||
btCapsuleShape(btScalar radius,btScalar height);
|
||||
|
||||
///CollisionShape Interface
|
||||
virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
|
||||
|
||||
/// btConvexShape Interface
|
||||
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
|
||||
|
||||
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
virtual int getShapeType() const { return CAPSULE_SHAPE_PROXYTYPE; }
|
||||
|
||||
virtual const char* getName()const
|
||||
{
|
||||
return "CapsuleShape";
|
||||
}
|
||||
|
||||
virtual int getUpAxis() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual btScalar getRadius() const
|
||||
{
|
||||
return m_implicitShapeDimensions.getX();
|
||||
}
|
||||
|
||||
virtual btScalar getHalfHeight() const
|
||||
{
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user