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

@@ -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);