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,12 +20,13 @@ LINK_LIBRARIES(
) )
ADD_EXECUTABLE(AppVehicleDemo ADD_EXECUTABLE(AppVehicleDemo
heightfield128x128.cpp
VehicleDemo.cpp VehicleDemo.cpp
main.cpp main.cpp
) )
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(AppVehicleDemo PROPERTIES DEBUG_POSTFIX "_Debug") SET_TARGET_PROPERTIES(AppVehicleDemo PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(AppVehicleDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel") SET_TARGET_PROPERTIES(AppVehicleDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(AppVehicleDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo") SET_TARGET_PROPERTIES(AppVehicleDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)

View File

@@ -1,5 +1,5 @@
noinst_PROGRAMS=VehicleDemo 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_CXXFLAGS=-I@top_builddir@/src -I@top_builddir@/Demos/OpenGL $(CXXFLAGS)
VehicleDemo_LDADD=-L../OpenGL -lbulletopenglsupport -L../../src -lBulletDynamics -lBulletCollision -lLinearMath @opengl_LIBS@ 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. /// with gears etc.
#include "btBulletDynamicsCommon.h" #include "btBulletDynamicsCommon.h"
#include "BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h" #include "BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h"
extern char MyHeightfield[];
// //
// By default, Bullet Vehicle uses Y as up axis. // 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: // 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(); tr.setIdentity();
//either use heightfield or triangle mesh //either use heightfield or triangle mesh
#define USE_TRIMESH_GROUND 1 //#define USE_TRIMESH_GROUND 1
#ifdef USE_TRIMESH_GROUND #ifdef USE_TRIMESH_GROUND
int i; int i;
@@ -248,6 +248,9 @@ const float TRIANGLE_SIZE=20.f;
//testing btHeightfieldTerrainShape //testing btHeightfieldTerrainShape
int width=128; int width=128;
int length=128; int length=128;
#ifdef LOAD_FROM_FILE
unsigned char* heightfieldData = new unsigned char[width*length]; unsigned char* heightfieldData = new unsigned char[width*length];
{ {
for (int i=0;i<width*length;i++) for (int i=0;i<width*length;i++)
@@ -273,7 +276,10 @@ const float TRIANGLE_SIZE=20.f;
} }
fclose (heightfieldFile); fclose (heightfieldFile);
} }
#else
char* heightfieldData = MyHeightfield;
#endif
btScalar maxHeight = 20000.f; btScalar maxHeight = 20000.f;
@@ -281,15 +287,18 @@ const float TRIANGLE_SIZE=20.f;
bool flipQuadEdges=false; bool flipQuadEdges=false;
btHeightfieldTerrainShape* heightFieldShape = new btHeightfieldTerrainShape(width,length,heightfieldData,maxHeight,upIndex,useFloatDatam,flipQuadEdges);; btHeightfieldTerrainShape* heightFieldShape = new btHeightfieldTerrainShape(width,length,heightfieldData,maxHeight,upIndex,useFloatDatam,flipQuadEdges);;
btVector3 mmin,mmax;
heightFieldShape->getAabb(btTransform::getIdentity(),mmin,mmax);
groundShape = heightFieldShape; groundShape = heightFieldShape;
heightFieldShape->setUseDiamondSubdivision(true); heightFieldShape->setUseDiamondSubdivision(true);
btVector3 localScaling(20,20,20); btVector3 localScaling(100,1,100);
localScaling[upIndex]=1.f; localScaling[upIndex]=1.f;
groundShape->setLocalScaling(localScaling); groundShape->setLocalScaling(localScaling);
tr.setOrigin(btVector3(0,-64.5f,0)); tr.setOrigin(btVector3(0,9940,0));//-64.5f,0));
#endif // #endif //
@@ -297,6 +306,7 @@ const float TRIANGLE_SIZE=20.f;
//create ground object //create ground object
localCreateRigidBody(0,tr,groundShape); localCreateRigidBody(0,tr,groundShape);
tr.setOrigin(btVector3(0,0,0));//-64.5f,0));
#ifdef FORCE_ZAXIS_UP #ifdef FORCE_ZAXIS_UP
// indexRightAxis = 0; // 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
void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, int triangleIndex) partId, int triangleIndex)
{ {
//just for debugging purposes
//printf("triangle %d",m_triangleCount++);
//just for debugging purposes
//printf("triangle %d",m_triangleCount++);
//aabb filter is already applied! const btCollisionObject* ob = const_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
//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; btCollisionAlgorithmConstructionInfo ci;
ci.m_dispatcher1 = m_dispatcher; ci.m_dispatcher1 = m_dispatcher;

View File

@@ -369,7 +369,7 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
getVertex(x+1,j+1,vertices[2]); getVertex(x+1,j+1,vertices[2]);
callback->processTriangle(vertices,x,j); callback->processTriangle(vertices,x,j);
//second triangle //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+1,j+1,vertices[1]);
getVertex(x,j+1,vertices[2]); getVertex(x,j+1,vertices[2]);
callback->processTriangle(vertices,x,j); callback->processTriangle(vertices,x,j);
@@ -382,7 +382,7 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
callback->processTriangle(vertices,x,j); callback->processTriangle(vertices,x,j);
//second triangle //second triangle
getVertex(x+1,j,vertices[0]); 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]); getVertex(x+1,j+1,vertices[2]);
callback->processTriangle(vertices,x,j); callback->processTriangle(vertices,x,j);
} }