Enable btHeightfieldShape in VehicleDemo, so it is tested (using heightfield128x128)

(converted raw data to .cpp so it doesn't need to be loaded from disk)
Some optimizations for btHeightfieldShape, thanks to Danny Chapman
 Quick check on AABB (was not done) and reduce calls to 'getVertex'
This commit is contained in:
erwin.coumans@gmail.com
2013-09-10 00:57:00 +00:00
parent 197e17780a
commit 2bb26cbb7d
6 changed files with 1680 additions and 18 deletions

View File

@@ -20,6 +20,7 @@ LINK_LIBRARIES(
)
ADD_EXECUTABLE(AppVehicleDemo
heightfield128x128.cpp
VehicleDemo.cpp
main.cpp
)

View File

@@ -1,5 +1,5 @@
noinst_PROGRAMS=VehicleDemo
VehicleDemo_SOURCES=VehicleDemo.cpp VehicleDemo.h main.cpp
VehicleDemo_SOURCES=VehicleDemo.cpp VehicleDemo.h heightfield128x128.cpp main.cpp
VehicleDemo_CXXFLAGS=-I@top_builddir@/src -I@top_builddir@/Demos/OpenGL $(CXXFLAGS)
VehicleDemo_LDADD=-L../OpenGL -lbulletopenglsupport -L../../src -lBulletDynamics -lBulletCollision -lLinearMath @opengl_LIBS@

View File

@@ -20,7 +20,7 @@ subject to the following restrictions:
/// with gears etc.
#include "btBulletDynamicsCommon.h"
#include "BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h"
extern char MyHeightfield[];
//
// By default, Bullet Vehicle uses Y as up axis.
// You can override the up axis, for example Z-axis up. Enable this define to see how to:
@@ -174,7 +174,7 @@ btTransform tr;
tr.setIdentity();
//either use heightfield or triangle mesh
#define USE_TRIMESH_GROUND 1
//#define USE_TRIMESH_GROUND 1
#ifdef USE_TRIMESH_GROUND
int i;
@@ -248,6 +248,9 @@ const float TRIANGLE_SIZE=20.f;
//testing btHeightfieldTerrainShape
int width=128;
int length=128;
#ifdef LOAD_FROM_FILE
unsigned char* heightfieldData = new unsigned char[width*length];
{
for (int i=0;i<width*length;i++)
@@ -273,6 +276,9 @@ const float TRIANGLE_SIZE=20.f;
}
fclose (heightfieldFile);
}
#else
char* heightfieldData = MyHeightfield;
#endif
btScalar maxHeight = 20000.f;
@@ -281,15 +287,18 @@ const float TRIANGLE_SIZE=20.f;
bool flipQuadEdges=false;
btHeightfieldTerrainShape* heightFieldShape = new btHeightfieldTerrainShape(width,length,heightfieldData,maxHeight,upIndex,useFloatDatam,flipQuadEdges);;
btVector3 mmin,mmax;
heightFieldShape->getAabb(btTransform::getIdentity(),mmin,mmax);
groundShape = heightFieldShape;
heightFieldShape->setUseDiamondSubdivision(true);
btVector3 localScaling(20,20,20);
btVector3 localScaling(100,1,100);
localScaling[upIndex]=1.f;
groundShape->setLocalScaling(localScaling);
tr.setOrigin(btVector3(0,-64.5f,0));
tr.setOrigin(btVector3(0,9940,0));//-64.5f,0));
#endif //
@@ -297,6 +306,7 @@ const float TRIANGLE_SIZE=20.f;
//create ground object
localCreateRigidBody(0,tr,groundShape);
tr.setOrigin(btVector3(0,0,0));//-64.5f,0));
#ifdef FORCE_ZAXIS_UP
// indexRightAxis = 0;

File diff suppressed because it is too large Load Diff

View File

@@ -76,15 +76,25 @@ void btConvexTriangleCallback::clearCache()
}
void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, int triangleIndex)
void btConvexTriangleCallback::processTriangle(btVector3* triangle,int
partId, int triangleIndex)
{
//just for debugging purposes
//printf("triangle %d",m_triangleCount++);
const btCollisionObject* ob = const_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
//aabb filter is already applied!
//aabb filter NOT is already applied (thanks to Danny Chapman)
// Quick check on AABB
// const btTransform& tr = ob->getWorldTransform();
if ( triangle[0].getZ() < m_aabbMin.getZ() &&
triangle[1].getZ() < m_aabbMin.getZ() &&
triangle[2].getZ() < m_aabbMin.getZ() )
{
return;
}
btCollisionAlgorithmConstructionInfo ci;
ci.m_dispatcher1 = m_dispatcher;

View File

@@ -369,7 +369,7 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
getVertex(x+1,j+1,vertices[2]);
callback->processTriangle(vertices,x,j);
//second triangle
getVertex(x,j,vertices[0]);
// getVertex(x,j,vertices[0]);//already got this vertex before, thanks to Danny Chapman
getVertex(x+1,j+1,vertices[1]);
getVertex(x,j+1,vertices[2]);
callback->processTriangle(vertices,x,j);
@@ -382,7 +382,7 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
callback->processTriangle(vertices,x,j);
//second triangle
getVertex(x+1,j,vertices[0]);
getVertex(x,j+1,vertices[1]);
//getVertex(x,j+1,vertices[1]);
getVertex(x+1,j+1,vertices[2]);
callback->processTriangle(vertices,x,j);
}