free memory for btShapeHulls, keep track of it in GL_ShapeDrawer.

move btShapeHull and btConvexHull into its own library in Extras/ConvexHull (it allocates memory using mem/delete and refactoring into using btAlignedAlloc/Free takes too much time)
fix heightfield / btOptimizedBvh for quantization, so that raycast can use quantized aabb (clamp up for maxima and down for minima)

work-in-progress (update projectfiles etc)
This commit is contained in:
ejcoumans
2008-02-13 07:14:19 +00:00
parent 98006e5607
commit eeb78b8d45
31 changed files with 188 additions and 117 deletions

View File

@@ -28,7 +28,6 @@
#include "GLDebugDrawer.h"
static GLDebugDrawer gDebugDrawer;
#include "LinearMath/btQuickprof.h"
@@ -80,7 +79,7 @@ DemoApplication* CreatDemo(btDemoEntry* entry)
btAssert(demo);
if (demo->getDynamicsWorld())
{
demo->getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
demo->getDynamicsWorld()->setDebugDrawer(new GLDebugDrawer());
}
#ifndef BT_NO_PROFILE
@@ -168,6 +167,8 @@ void SimulationLoop()
if (testSelection != testIndex)
{
testIndex = testSelection;
if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getDebugDrawer())
delete demo->getDynamicsWorld()->getDebugDrawer();
delete demo;
entry = g_demoEntries + testIndex;
demo = CreatDemo(entry);
@@ -192,6 +193,8 @@ void Keyboard(unsigned char key, int x, int y)
// Press 'r' to reset.
case 'r':
if (demo->getDynamicsWorld()->getDebugDrawer())
delete demo->getDynamicsWorld()->getDebugDrawer();
delete demo;
demo = CreatDemo(entry);
Resize(width,height);

View File

@@ -232,7 +232,7 @@ void CollisionDemo::displayCallback(void) {
tr[i].getOpenGLMatrix( m );
GL_ShapeDrawer::drawOpenGL(m,shapePtr[i],btVector3(1,1,1),getDebugMode());
m_shapeDrawer.drawOpenGL(m,shapePtr[i],btVector3(1,1,1),getDebugMode());
}
@@ -248,7 +248,7 @@ void CollisionDemo::displayCallback(void) {
btTransform ident;
ident.setIdentity();
ident.getOpenGLMatrix(m);
GL_ShapeDrawer::drawOpenGL(m,&simplex,btVector3(1,1,1),getDebugMode());
m_shapeDrawer.drawOpenGL(m,&simplex,btVector3(1,1,1),getDebugMode());
btQuaternion orn;

View File

@@ -164,7 +164,7 @@ void CollisionInterfaceDemo::displayCallback(void) {
{
objects[i].getWorldTransform().getOpenGLMatrix( m );
GL_ShapeDrawer::drawOpenGL(m,objects[i].getCollisionShape(),btVector3(1,1,1),getDebugMode());
m_shapeDrawer.drawOpenGL(m,objects[i].getCollisionShape(),btVector3(1,1,1),getDebugMode());
}

View File

@@ -152,7 +152,7 @@ void btContinuousConvexCollisionDemo::displayCallback(void) {
/*for (i=0;i<numObjects;i++)
{
fromTrans[i].getOpenGLMatrix( m );
GL_ShapeDrawer::drawOpenGL(m,shapePtr[i]);
m_shapeDrawer.drawOpenGL(m,shapePtr[i]);
}
*/
@@ -171,13 +171,13 @@ void btContinuousConvexCollisionDemo::displayCallback(void) {
btTransformUtil::integrateTransform(fromTrans[i],linVels[i],angVels[i],subStep,interpolatedTrans);
//fromTrans[i].getOpenGLMatrix(m);
//GL_ShapeDrawer::drawOpenGL(m,shapePtr[i]);
//m_shapeDrawer.drawOpenGL(m,shapePtr[i]);
//toTrans[i].getOpenGLMatrix(m);
//GL_ShapeDrawer::drawOpenGL(m,shapePtr[i]);
//m_shapeDrawer.drawOpenGL(m,shapePtr[i]);
interpolatedTrans.getOpenGLMatrix( m );
GL_ShapeDrawer::drawOpenGL(m,shapePtr[i],btVector3(1,0,1),getDebugMode());
m_shapeDrawer.drawOpenGL(m,shapePtr[i],btVector3(1,0,1),getDebugMode());
}
}
}
@@ -229,10 +229,10 @@ void btContinuousConvexCollisionDemo::displayCallback(void) {
for (i=0;i<numObjects;i++)
{
fromTrans[i].getOpenGLMatrix(m);
GL_ShapeDrawer::drawOpenGL(m,shapePtr[i],btVector3(1,1,1),getDebugMode());
m_shapeDrawer.drawOpenGL(m,shapePtr[i],btVector3(1,1,1),getDebugMode());
}
btDebugCastResult rayResult1(fromTrans[0],shapePtr[0],linVels[0],angVels[0]);
btDebugCastResult rayResult1(fromTrans[0],shapePtr[0],linVels[0],angVels[0],&m_shapeDrawer);
for (i=1;i<numObjects;i++)
@@ -267,12 +267,12 @@ void btContinuousConvexCollisionDemo::displayCallback(void) {
btTransformUtil::integrateTransform(fromTrans[0],linVels[0],angVels[0],rayResultPtr->m_fraction,hitTrans);
hitTrans.getOpenGLMatrix(m);
GL_ShapeDrawer::drawOpenGL(m,shapePtr[0],btVector3(0,1,0),getDebugMode());
m_shapeDrawer.drawOpenGL(m,shapePtr[0],btVector3(0,1,0),getDebugMode());
btTransformUtil::integrateTransform(fromTrans[i],linVels[i],angVels[i],rayResultPtr->m_fraction,hitTrans);
hitTrans.getOpenGLMatrix(m);
GL_ShapeDrawer::drawOpenGL(m,shapePtr[i],btVector3(0,1,1),getDebugMode());
m_shapeDrawer.drawOpenGL(m,shapePtr[i],btVector3(0,1,1),getDebugMode());
}

View File

@@ -21,7 +21,7 @@ subject to the following restrictions:
#include "LinearMath/btQuickprof.h"
#include "LinearMath/btIDebugDraw.h"
#include "LinearMath/btGeometryUtil.h"
#include "BulletCollision/CollisionShapes/btShapeHull.h"
#include "btShapeHull.h"
//#define USE_PARALLEL_DISPATCHER 1
#ifdef USE_PARALLEL_DISPATCHER

View File

@@ -1,28 +1,28 @@
#include "ConvexDecompositionDemo.h"
#include "GlutStuff.h"
#include "ConvexDecompositionDemo.h"
#include "GlutStuff.h"
#include "GLDebugDrawer.h"
#include "btBulletDynamicsCommon.h"
GLDebugDrawer gDebugDrawer;
int main(int argc,char** argv)
{
const char* filename = "file.obj";
ConvexDecompositionDemo* convexDecompDemo = new ConvexDecompositionDemo();
convexDecompDemo->initPhysics(filename);
convexDecompDemo->getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
convexDecompDemo->clientResetScene();
return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://www.continuousphysics.com/Bullet/phpBB2/",convexDecompDemo);
}
#include "btBulletDynamicsCommon.h"
GLDebugDrawer gDebugDrawer;
int main(int argc,char** argv)
{
const char* filename = "file.obj";
ConvexDecompositionDemo* convexDecompDemo = new ConvexDecompositionDemo();
convexDecompDemo->initPhysics(filename);
convexDecompDemo->getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
convexDecompDemo->clientResetScene();
return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://www.continuousphysics.com/Bullet/phpBB2/",convexDecompDemo);
}

View File

@@ -169,7 +169,7 @@ void DoublePrecisionDemo::displayCallback(void)
temp = objects[i].getWorldTransform();
temp.setOrigin(temp.getOrigin() - m_cameraPosition);
temp.getOpenGLMatrix( m );
GL_ShapeDrawer::drawOpenGL(m,objects[i].getCollisionShape(),color,getDebugMode());
m_shapeDrawer.drawOpenGL(m,objects[i].getCollisionShape(),color,getDebugMode());
}
objects[1].getWorldTransform().setOrigin(objects[1].getWorldTransform().getOrigin()+btVector3(-VERY_SMALL_INCREMENT,-VERY_SMALL_INCREMENT,0));

View File

@@ -152,7 +152,7 @@ void GimpactConcaveDemo::renderme()
}
}
GL_ShapeDrawer::drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode());
m_shapeDrawer.drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode());
}

View File

@@ -137,8 +137,8 @@ void LinearConvexCastDemo::displayCallback(void)
tr[ 0 ].getOpenGLMatrix( m1 );
tr[ 1 ].getOpenGLMatrix( m2 );
GL_ShapeDrawer::drawOpenGL( m1, shapePtr[ 0 ], btVector3( 1, 0, 0 ), getDebugMode() );
GL_ShapeDrawer::drawOpenGL( m2, shapePtr[ 1 ], btVector3( 1, 0, 0 ), getDebugMode() );
m_shapeDrawer.drawOpenGL( m1, shapePtr[ 0 ], btVector3( 1, 0, 0 ), getDebugMode() );
m_shapeDrawer.drawOpenGL( m2, shapePtr[ 1 ], btVector3( 1, 0, 0 ), getDebugMode() );
btVector3 originA, originB;
originA.setInterpolate3( tr[ 0 ].getOrigin(), toA.getOrigin(), result.m_fraction );
@@ -153,8 +153,8 @@ void LinearConvexCastDemo::displayCallback(void)
A.getOpenGLMatrix( m1 );
B.getOpenGLMatrix( m2 );
GL_ShapeDrawer::drawOpenGL( m1, shapePtr[ 0 ], btVector3( 1, 1, 0 ), getDebugMode() );
GL_ShapeDrawer::drawOpenGL( m2, shapePtr[ 1 ], btVector3( 1, 1, 0 ), getDebugMode() );
m_shapeDrawer.drawOpenGL( m1, shapePtr[ 0 ], btVector3( 1, 1, 0 ), getDebugMode() );
m_shapeDrawer.drawOpenGL( m2, shapePtr[ 1 ], btVector3( 1, 1, 0 ), getDebugMode() );
glFlush();
glutSwapBuffers();

View File

@@ -1535,7 +1535,7 @@ void ConcaveDemo::renderme()
}
}
GL_ShapeDrawer::drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode());
m_shapeDrawer.drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode());
}

View File

@@ -37,9 +37,10 @@ struct btDebugCastResult : public btConvexCast::CastResult
const btPolyhedralConvexShape* m_shape;
btVector3 m_linVel;
btVector3 m_angVel;
GL_ShapeDrawer* m_shapeDrawer;
btDebugCastResult(const btTransform& fromTrans,const btPolyhedralConvexShape* shape,
const btVector3& linVel,const btVector3& angVel)
const btVector3& linVel,const btVector3& angVel,GL_ShapeDrawer* drawer)
:m_fromTrans(fromTrans),
m_shape(shape),
m_linVel(linVel),
@@ -74,8 +75,7 @@ struct btDebugCastResult : public btConvexCast::CastResult
btTransform hitTrans;
btTransformUtil::integrateTransform(m_fromTrans,m_linVel,m_angVel,fraction,hitTrans);
hitTrans.getOpenGLMatrix(m);
GL_ShapeDrawer::drawOpenGL(m,m_shape,btVector3(1,0,0),btIDebugDraw::DBG_NoDebug);
m_shapeDrawer->drawOpenGL(m,m_shape,btVector3(1,0,0),btIDebugDraw::DBG_NoDebug);
}
};

View File

@@ -927,7 +927,7 @@ void DemoApplication::renderme()
}
}
GL_ShapeDrawer::drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode());
m_shapeDrawer.drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode());
}

View File

@@ -18,6 +18,7 @@ subject to the following restrictions:
#include "GlutStuff.h"
#include "GL_ShapeDrawer.h"
#include <stdlib.h>
#include <stdio.h>
@@ -37,7 +38,6 @@ class btTypedConstraint;
class DemoApplication
{
void displayProfileString(int xOffset,int yStart,char* message);
@@ -81,6 +81,7 @@ class DemoApplication
void showProfileInfo(float& xOffset,float& yStart, float yIncr);
GL_ShapeDrawer m_shapeDrawer;
public:

View File

@@ -40,7 +40,8 @@ subject to the following restrictions:
#include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
#include "BulletCollision/CollisionShapes/btUniformScalingShape.h"
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
#include "BulletCollision/CollisionShapes/btShapeHull.h"
///
#include "btShapeHull.h"
#include "LinearMath/btTransformUtil.h"
@@ -470,7 +471,12 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
if (!shape->getUserPointer())
{
//create a hull approximation
btShapeHull* hull = new btShapeHull(convexShape);
void* mem = btAlignedAlloc(sizeof(btShapeHull),16);
btShapeHull* hull = new(mem) btShapeHull(convexShape);
///cleanup memory
m_shapeHulls.push_back(hull);
btScalar margin = shape->getMargin();
hull->buildHull(margin);
convexShape->setUserPointer(hull);
@@ -655,3 +661,22 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
glPopMatrix();
}
GL_ShapeDrawer::GL_ShapeDrawer()
{
}
GL_ShapeDrawer::~GL_ShapeDrawer()
{
int i;
for (i=0;i<m_shapeHulls.size();i++)
{
btShapeHull* hull = m_shapeHulls[i];
hull->~btShapeHull();
btAlignedFree(hull);
m_shapeHulls[i] = 0;
}
m_shapeHulls.clear();
}

View File

@@ -16,16 +16,26 @@ subject to the following restrictions:
#define GL_SHAPE_DRAWER_H
class btCollisionShape;
class btShapeHull;
#include "LinearMath/btAlignedObjectArray.h"
#include "LinearMath/btVector3.h"
/// OpenGL shape drawing
class GL_ShapeDrawer
{
public:
//clean-up memory of dynamically created shape hulls
btAlignedObjectArray<btShapeHull*> m_shapeHulls;
static void drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode);
static void drawCoordSystem();
public:
GL_ShapeDrawer();
virtual ~GL_ShapeDrawer();
///drawOpenGL might allocate temporary memoty, stores pointer in shape userpointer
void drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode);
static void drawCylinder(float radius,float halfHeight, int upAxis);
static void drawCoordSystem();
};
void OGL_displaylist_register_shape(btCollisionShape * shape);

View File

@@ -88,7 +88,7 @@ void SimplexDemo::displayCallback()
transA.getOpenGLMatrix( m );
/// draw the simplex
GL_ShapeDrawer::drawOpenGL(m,shapePtr[i],btVector3(1,1,1),getDebugMode());
m_shapeDrawer.drawOpenGL(m,shapePtr[i],btVector3(1,1,1),getDebugMode());
/// calculate closest point from simplex to the origin, and draw this vector
simplex.calcClosest(m);

View File

@@ -409,7 +409,7 @@ void VehicleDemo::renderme()
m_vehicle->updateWheelTransform(i,true);
//draw wheels (cylinders)
m_vehicle->getWheelInfo(i).m_worldTransform.getOpenGLMatrix(m);
GL_ShapeDrawer::drawOpenGL(m,&wheelShape,wheelColor,getDebugMode());
m_shapeDrawer.drawOpenGL(m,&wheelShape,wheelColor,getDebugMode());
}