+ Internal improvements for collision shapes

1) add AabbCaching versions of btPolyhedralConvexShape and btMultiSphereShape (this speeds up btMultiSphereShape 'getAabb', and reduces size of btBoxShape)
2) btCylinderShape doesn't derive from btBoxShape anymore
+ Minor fixes in drawing for btMultiSphereShape, btBoxShape.
+ Don't re-generate btDebugFont every frame
+ Disabled velocity prediction for btDbvtBroadphase. Previous default can be restored using btDbvtBroadphase->setVelocityPrediction(1./2.);
This commit is contained in:
erwin.coumans
2009-05-22 01:03:45 +00:00
parent c680791ce9
commit 2f1014268b
25 changed files with 380 additions and 90 deletions

View File

@@ -440,6 +440,9 @@ int maxNumOutstandingTasks = 4;
btDiscreteDynamicsWorld* world = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
m_dynamicsWorld = world;
///SOLVER_RANDMIZE_ORDER makes cylinder stacking a bit more stable
world->getSolverInfo().m_solverMode |= SOLVER_RANDMIZE_ORDER;
#ifdef USER_DEFINED_FRICTION_MODEL
//user defined friction model is not supported in 'cache friendly' solver yet, so switch to old solver

View File

@@ -32,8 +32,8 @@ subject to the following restrictions:
#define OECAKE_LOADER 1
#ifdef _DEBUG
#define LARGE_DEMO 0
// #define LARGE_DEMO 1
// #define LARGE_DEMO 0
#define LARGE_DEMO 1
#else
#define LARGE_DEMO 1
#endif
@@ -323,10 +323,8 @@ void BasicDemo::initPhysics()
// Re-using the same collision is better for memory usage and performance
//btCollisionShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,0.1));//SCALING*1));
// btCollisionShape* colShape = new btBox2dShape(btVector3(SCALING*.7,SCALING*.7,0.1));//SCALING*1));
#if 0
#if 1
#define SPRADIUS btScalar(SCALING*0.1f)
#define SPRPOS btScalar(SCALING*0.05f)
static btVector3 sSphPos[8];

View File

@@ -66,6 +66,9 @@ class BasicDemo : public GlutDemoApplication
void exitPhysics();
///don't shoot a box in this demo ;-)
virtual void shootBox(const btVector3& dest) {}
virtual void clientMoveAndDisplay();
virtual void displayCallback();

View File

@@ -187,7 +187,7 @@ public:
///Demo functions
virtual void setShootBoxShape ();
void shootBox(const btVector3& destination);
virtual void shootBox(const btVector3& destination);
btVector3 getRayTo(int x,int y);

View File

@@ -20,13 +20,16 @@ subject to the following restrictions:
extern unsigned char sFontData[];
static GLuint sTexture = -1;
static int sScreenWidth = 0;
static int sScreenHeight = 0;
static int sScreenWidth = -1;
static int sScreenHeight = -1;
void GLDebugResetFont(int screenWidth,int screenHeight)
{
if ((sScreenWidth == screenWidth) && (sScreenHeight == screenHeight))
return;
sScreenWidth = screenWidth;
sScreenHeight = screenHeight;

View File

@@ -34,6 +34,9 @@ subject to the following restrictions:
#include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
#include "BulletCollision/CollisionShapes/btUniformScalingShape.h"
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
///
#include "BulletCollision/CollisionShapes/btShapeHull.h"
@@ -269,6 +272,34 @@ public:
}
};
void GL_ShapeDrawer::drawSphere(btScalar r, int lats, int longs)
{
int i, j;
for(i = 0; i <= lats; i++) {
btScalar lat0 = SIMD_PI * (-btScalar(0.5) + (btScalar) (i - 1) / lats);
btScalar z0 = sin(lat0);
btScalar zr0 = cos(lat0);
btScalar lat1 = SIMD_PI * (-btScalar(0.5) + (btScalar) i / lats);
btScalar z1 = sin(lat1);
btScalar zr1 = cos(lat1);
glBegin(GL_QUAD_STRIP);
for(j = 0; j <= longs; j++) {
btScalar lng = 2 * SIMD_PI * (btScalar) (j - 1) / longs;
btScalar x = cos(lng);
btScalar y = sin(lng);
glNormal3f(x * zr0, y * zr0, z0);
glVertex3f(x * zr0, y * zr0, z0);
glNormal3f(x * zr1, y * zr1, z1);
glVertex3f(x * zr1, y * zr1, z1);
}
glEnd();
}
}
void GL_ShapeDrawer::drawCylinder(float radius,float halfHeight, int upAxis)
{
@@ -538,30 +569,66 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
///you can comment out any of the specific cases, and use the default
///the benefit of 'default' is that it approximates the actual collision shape including collision margin
int shapetype=m_textureenabled?MAX_BROADPHASE_COLLISION_TYPES:shape->getShapeType();
//int shapetype=m_textureenabled?MAX_BROADPHASE_COLLISION_TYPES:shape->getShapeType();
int shapetype=shape->getShapeType();
switch (shapetype)
{
#if 0
case BOX_SHAPE_PROXYTYPE:
{
const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape);
btVector3 halfExtent = boxShape->getHalfExtentsWithMargin();
glScaled(2*halfExtent[0], 2*halfExtent[1], 2*halfExtent[2]);
glutSolidCube(1.0);
useWireframeFallback = false;
break;
}
case SPHERE_SHAPE_PROXYTYPE:
case SPHERE_SHAPE_PROXYTYPE:
{
const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape);
float radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin
glutSolidSphere(radius,10,10);
drawSphere(radius,10,10);
useWireframeFallback = false;
break;
}
case BOX_SHAPE_PROXYTYPE:
{
const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape);
btVector3 halfExtent = boxShape->getHalfExtentsWithMargin();
static int indices[36] = {
0,1,2,
3,2,1,
4,0,6,
6,0,2,
5,1,4,
4,1,0,
7,3,1,
7,1,5,
5,4,7,
7,4,6,
7,2,3,
7,6,2};
static btVector3 vertices[8]={ btVector3(1,1,1),btVector3(-1,1,1), btVector3(1,-1,1), btVector3(-1,-1,1), btVector3(1,1,-1), btVector3(-1,1,-1), btVector3(1,-1,-1), btVector3(-1,-1,-1)};
glBegin (GL_TRIANGLES);
int si=36;
for (int i=0;i<si;i+=3)
{
btVector3 v1 = vertices[indices[i]]*halfExtent;
btVector3 v2 = vertices[indices[i+1]]*halfExtent;
btVector3 v3 = vertices[indices[i+2]]*halfExtent;
btVector3 normal = (v3-v1).cross(v2-v1);
normal.normalize ();
glNormal3f(normal.getX(),normal.getY(),normal.getZ());
glVertex3f (v1.x(), v1.y(), v1.z());
glVertex3f (v2.x(), v2.y(), v2.z());
glVertex3f (v3.x(), v3.y(), v3.z());
}
glEnd();
useWireframeFallback = false;
break;
}
#if 0
case CONE_SHAPE_PROXYTYPE:
{
const btConeShape* coneShape = static_cast<const btConeShape*>(shape);
@@ -630,6 +697,26 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
break;
}
case MULTI_SPHERE_SHAPE_PROXYTYPE:
{
const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape);
btTransform childTransform;
childTransform.setIdentity();
for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--)
{
btSphereShape sc(multiSphereShape->getSphereRadius(i));
childTransform.setOrigin(multiSphereShape->getSpherePosition(i));
btScalar childMat[16];
childTransform.getOpenGLMatrix(childMat);
drawOpenGL(childMat,&sc,color,debugMode,worldBoundsMin,worldBoundsMax);
}
break;
}
default:
{

View File

@@ -58,6 +58,7 @@ public:
}
static void drawCylinder(float radius,float halfHeight, int upAxis);
void drawSphere(btScalar r, int lats, int longs);
static void drawCoordSystem();
};