Added btCapsuleShape. This could already be simulated by simply adding 2 spheres to the btMultiSphereShape, but this was bad documented/unknown.
For tapered capsules, you can still use btMultiSphereShape, just pass 2 spheres with different radius.
This commit is contained in:
@@ -91,6 +91,7 @@ btCollisionShape* shapePtr[numShapes] =
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
new btCylinderShape (btVector3(CUBE_HALF_EXTENTS-gCollisionMargin,CUBE_HALF_EXTENTS-gCollisionMargin,CUBE_HALF_EXTENTS-gCollisionMargin)),
|
new btCylinderShape (btVector3(CUBE_HALF_EXTENTS-gCollisionMargin,CUBE_HALF_EXTENTS-gCollisionMargin,CUBE_HALF_EXTENTS-gCollisionMargin)),
|
||||||
|
//new btCapsuleShape(0.5*CUBE_HALF_EXTENTS-gCollisionMargin,CUBE_HALF_EXTENTS-gCollisionMargin),
|
||||||
//new btCylinderShape (btVector3(1-gCollisionMargin,CUBE_HALF_EXTENTS-gCollisionMargin,1-gCollisionMargin)),
|
//new btCylinderShape (btVector3(1-gCollisionMargin,CUBE_HALF_EXTENTS-gCollisionMargin,1-gCollisionMargin)),
|
||||||
//new btBoxShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)),
|
//new btBoxShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)),
|
||||||
//new btConeShape(CUBE_HALF_EXTENTS-gCollisionMargin,2.f*CUBE_HALF_EXTENTS-gCollisionMargin),
|
//new btConeShape(CUBE_HALF_EXTENTS-gCollisionMargin,2.f*CUBE_HALF_EXTENTS-gCollisionMargin),
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ subject to the following restrictions:
|
|||||||
#include "BulletCollision/CollisionShapes/btCylinderShape.h"
|
#include "BulletCollision/CollisionShapes/btCylinderShape.h"
|
||||||
#include "BulletCollision/CollisionShapes/btTetrahedronShape.h"
|
#include "BulletCollision/CollisionShapes/btTetrahedronShape.h"
|
||||||
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
||||||
|
#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
|
||||||
#include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
|
#include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -257,6 +257,46 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void GL_ShapeDrawer::drawCylinder(float radius,float halfHeight, int upAxis)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
switch (upAxis)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
glRotatef(-90.0, 0.0, 1.0, 0.0);
|
||||||
|
glTranslatef(0.0, 0.0, -halfHeight);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
glRotatef(-90.0, 1.0, 0.0, 0.0);
|
||||||
|
glTranslatef(0.0, 0.0, -halfHeight);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
|
||||||
|
glTranslatef(0.0, 0.0, -halfHeight);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
GLUquadricObj *quadObj = gluNewQuadric();
|
||||||
|
|
||||||
|
//The gluCylinder subroutine draws a cylinder that is oriented along the z axis.
|
||||||
|
//The base of the cylinder is placed at z = 0; the top of the cylinder is placed at z=height.
|
||||||
|
//Like a sphere, the cylinder is subdivided around the z axis into slices and along the z axis into stacks.
|
||||||
|
|
||||||
|
gluQuadricDrawStyle(quadObj, (GLenum)GLU_FILL);
|
||||||
|
gluQuadricNormals(quadObj, (GLenum)GLU_SMOOTH);
|
||||||
|
|
||||||
|
|
||||||
|
gluCylinder(quadObj, radius, radius, 2.f*halfHeight, 15, 10);
|
||||||
|
glPopMatrix();
|
||||||
|
gluDeleteQuadric(quadObj);
|
||||||
|
}
|
||||||
|
|
||||||
void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode)
|
void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode)
|
||||||
{
|
{
|
||||||
@@ -319,7 +359,29 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
|
|||||||
useWireframeFallback = false;
|
useWireframeFallback = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CAPSULE_SHAPE_PROXYTYPE:
|
||||||
|
{
|
||||||
|
const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape);
|
||||||
|
float radius = capsuleShape->getRadius();
|
||||||
|
float halfHeight = capsuleShape->getHalfHeight();
|
||||||
|
int upAxis = 1;
|
||||||
|
|
||||||
|
drawCylinder(radius,halfHeight,upAxis);
|
||||||
|
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(0.0, -halfHeight,0.0);
|
||||||
|
glutSolidSphere(radius,10,10);
|
||||||
|
glTranslatef(0.0, 2*halfHeight,0.0);
|
||||||
|
glutSolidSphere(radius,10,10);
|
||||||
|
glPopMatrix();
|
||||||
|
useWireframeFallback = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case MULTI_SPHERE_SHAPE_PROXYTYPE:
|
case MULTI_SPHERE_SHAPE_PROXYTYPE:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
case CONE_SHAPE_PROXYTYPE:
|
case CONE_SHAPE_PROXYTYPE:
|
||||||
{
|
{
|
||||||
const btConeShape* coneShape = static_cast<const btConeShape*>(shape);
|
const btConeShape* coneShape = static_cast<const btConeShape*>(shape);
|
||||||
@@ -344,43 +406,11 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
|
|||||||
const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape);
|
const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape);
|
||||||
int upAxis = cylinder->getUpAxis();
|
int upAxis = cylinder->getUpAxis();
|
||||||
|
|
||||||
GLUquadricObj *quadObj = gluNewQuadric();
|
|
||||||
float radius = cylinder->getRadius();
|
float radius = cylinder->getRadius();
|
||||||
float halfHeight = cylinder->getHalfExtents()[upAxis];
|
float halfHeight = cylinder->getHalfExtents()[upAxis];
|
||||||
|
|
||||||
glPushMatrix();
|
drawCylinder(radius,halfHeight,upAxis);
|
||||||
switch (upAxis)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
glRotatef(-90.0, 0.0, 1.0, 0.0);
|
|
||||||
glTranslatef(0.0, 0.0, -halfHeight);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
glRotatef(-90.0, 1.0, 0.0, 0.0);
|
|
||||||
glTranslatef(0.0, 0.0, -halfHeight);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
|
|
||||||
glTranslatef(0.0, 0.0, -halfHeight);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//The gluCylinder subroutine draws a cylinder that is oriented along the z axis.
|
|
||||||
//The base of the cylinder is placed at z = 0; the top of the cylinder is placed at z=height.
|
|
||||||
//Like a sphere, the cylinder is subdivided around the z axis into slices and along the z axis into stacks.
|
|
||||||
|
|
||||||
gluQuadricDrawStyle(quadObj, (GLenum)GLU_FILL);
|
|
||||||
gluQuadricNormals(quadObj, (GLenum)GLU_SMOOTH);
|
|
||||||
|
|
||||||
|
|
||||||
gluCylinder(quadObj, radius, radius, 2.f*halfHeight, 15, 10);
|
|
||||||
glPopMatrix();
|
|
||||||
gluDeleteQuadric(quadObj);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class GL_ShapeDrawer
|
|||||||
|
|
||||||
static void drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode);
|
static void drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode);
|
||||||
static void drawCoordSystem();
|
static void drawCoordSystem();
|
||||||
|
static void drawCylinder(float radius,float halfHeight, int upAxis);
|
||||||
};
|
};
|
||||||
|
|
||||||
void OGL_displaylist_register_shape(btCollisionShape * shape);
|
void OGL_displaylist_register_shape(btCollisionShape * shape);
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ enum BroadphaseNativeTypes
|
|||||||
IMPLICIT_CONVEX_SHAPES_START_HERE,
|
IMPLICIT_CONVEX_SHAPES_START_HERE,
|
||||||
SPHERE_SHAPE_PROXYTYPE,
|
SPHERE_SHAPE_PROXYTYPE,
|
||||||
MULTI_SPHERE_SHAPE_PROXYTYPE,
|
MULTI_SPHERE_SHAPE_PROXYTYPE,
|
||||||
|
CAPSULE_SHAPE_PROXYTYPE,
|
||||||
CONE_SHAPE_PROXYTYPE,
|
CONE_SHAPE_PROXYTYPE,
|
||||||
CONVEX_SHAPE_PROXYTYPE,
|
CONVEX_SHAPE_PROXYTYPE,
|
||||||
CYLINDER_SHAPE_PROXYTYPE,
|
CYLINDER_SHAPE_PROXYTYPE,
|
||||||
|
|||||||
146
src/BulletCollision/CollisionShapes/btCapsuleShape.cpp
Normal file
146
src/BulletCollision/CollisionShapes/btCapsuleShape.cpp
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "btCapsuleShape.h"
|
||||||
|
|
||||||
|
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
|
||||||
|
#include "LinearMath/btQuaternion.h"
|
||||||
|
|
||||||
|
btCapsuleShape::btCapsuleShape(float radius, float height)
|
||||||
|
{
|
||||||
|
m_implicitShapeDimensions.setValue(radius,0.5f*height,radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
btVector3 btCapsuleShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
|
||||||
|
{
|
||||||
|
|
||||||
|
btVector3 supVec(0,0,0);
|
||||||
|
|
||||||
|
btScalar maxDot(btScalar(-1e30));
|
||||||
|
|
||||||
|
btVector3 vec = vec0;
|
||||||
|
btScalar lenSqr = vec.length2();
|
||||||
|
if (lenSqr < btScalar(0.0001))
|
||||||
|
{
|
||||||
|
vec.setValue(1,0,0);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
|
||||||
|
vec *= rlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
btVector3 vtx;
|
||||||
|
btScalar newDot;
|
||||||
|
|
||||||
|
float radius = getRadius();
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
btVector3 pos(0,getHalfHeight(),0);
|
||||||
|
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
||||||
|
newDot = vec.dot(vtx);
|
||||||
|
if (newDot > maxDot)
|
||||||
|
{
|
||||||
|
maxDot = newDot;
|
||||||
|
supVec = vtx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
btVector3 pos(0,-getHalfHeight(),0);
|
||||||
|
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
||||||
|
newDot = vec.dot(vtx);
|
||||||
|
if (newDot > maxDot)
|
||||||
|
{
|
||||||
|
maxDot = newDot;
|
||||||
|
supVec = vtx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return supVec;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void btCapsuleShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
float radius = getRadius();
|
||||||
|
|
||||||
|
for (int j=0;j<numVectors;j++)
|
||||||
|
{
|
||||||
|
btScalar maxDot(btScalar(-1e30));
|
||||||
|
const btVector3& vec = vectors[j];
|
||||||
|
|
||||||
|
btVector3 vtx;
|
||||||
|
btScalar newDot;
|
||||||
|
{
|
||||||
|
btVector3 pos(0,getHalfHeight(),0);
|
||||||
|
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
||||||
|
newDot = vec.dot(vtx);
|
||||||
|
if (newDot > maxDot)
|
||||||
|
{
|
||||||
|
maxDot = newDot;
|
||||||
|
supportVerticesOut[j] = vtx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
btVector3 pos(0,-getHalfHeight(),0);
|
||||||
|
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
|
||||||
|
newDot = vec.dot(vtx);
|
||||||
|
if (newDot > maxDot)
|
||||||
|
{
|
||||||
|
maxDot = newDot;
|
||||||
|
supportVerticesOut[j] = vtx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
|
||||||
|
{
|
||||||
|
//as an approximation, take the inertia of the box that bounds the spheres
|
||||||
|
|
||||||
|
btTransform ident;
|
||||||
|
ident.setIdentity();
|
||||||
|
|
||||||
|
|
||||||
|
float radius = getRadius();
|
||||||
|
|
||||||
|
btVector3 halfExtents(radius,radius+getHalfHeight(),radius);
|
||||||
|
|
||||||
|
btScalar margin = CONVEX_DISTANCE_MARGIN;
|
||||||
|
|
||||||
|
btScalar lx=btScalar(2.)*(halfExtents[0]+margin);
|
||||||
|
btScalar ly=btScalar(2.)*(halfExtents[1]+margin);
|
||||||
|
btScalar lz=btScalar(2.)*(halfExtents[2]+margin);
|
||||||
|
const btScalar x2 = lx*lx;
|
||||||
|
const btScalar y2 = ly*ly;
|
||||||
|
const btScalar z2 = lz*lz;
|
||||||
|
const btScalar scaledmass = mass * btScalar(.08333333);
|
||||||
|
|
||||||
|
inertia[0] = scaledmass * (y2+z2);
|
||||||
|
inertia[1] = scaledmass * (x2+z2);
|
||||||
|
inertia[2] = scaledmass * (x2+y2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
60
src/BulletCollision/CollisionShapes/btCapsuleShape.h
Normal file
60
src/BulletCollision/CollisionShapes/btCapsuleShape.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
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 "btConvexShape.h"
|
||||||
|
#include "../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 btConvexShape
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
btCapsuleShape(float radius,float height);
|
||||||
|
|
||||||
|
///CollisionShape Interface
|
||||||
|
virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
|
||||||
|
|
||||||
|
/// 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 char* getName()const
|
||||||
|
{
|
||||||
|
return "CapsuleShape";
|
||||||
|
}
|
||||||
|
|
||||||
|
float getRadius() const
|
||||||
|
{
|
||||||
|
return m_implicitShapeDimensions.getX();
|
||||||
|
}
|
||||||
|
|
||||||
|
float getHalfHeight() const
|
||||||
|
{
|
||||||
|
return m_implicitShapeDimensions.getY();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //BT_CAPSULE_SHAPE_H
|
||||||
@@ -25,6 +25,7 @@ subject to the following restrictions:
|
|||||||
///Collision Shapes
|
///Collision Shapes
|
||||||
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
||||||
#include "BulletCollision/CollisionShapes/btSphereShape.h"
|
#include "BulletCollision/CollisionShapes/btSphereShape.h"
|
||||||
|
#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
|
||||||
#include "BulletCollision/CollisionShapes/btCylinderShape.h"
|
#include "BulletCollision/CollisionShapes/btCylinderShape.h"
|
||||||
#include "BulletCollision/CollisionShapes/btConeShape.h"
|
#include "BulletCollision/CollisionShapes/btConeShape.h"
|
||||||
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
|
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user