updated vehicle demo to load heightfield data from file
This commit is contained in:
@@ -130,7 +130,10 @@ void VehicleDemo::setupPhysics()
|
|||||||
m_dynamicsWorld->setDebugDrawer(&debugDrawer);
|
m_dynamicsWorld->setDebugDrawer(&debugDrawer);
|
||||||
|
|
||||||
//m_dynamicsWorld->setGravity(btVector3(0,0,0));
|
//m_dynamicsWorld->setGravity(btVector3(0,0,0));
|
||||||
|
btTransform tr;
|
||||||
|
tr.setIdentity();
|
||||||
|
|
||||||
|
//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;
|
||||||
@@ -199,28 +202,53 @@ const float TRIANGLE_SIZE=20.f;
|
|||||||
bool useQuantizedAabbCompression = true;
|
bool useQuantizedAabbCompression = true;
|
||||||
groundShape = new btBvhTriangleMeshShape(indexVertexArrays,useQuantizedAabbCompression);
|
groundShape = new btBvhTriangleMeshShape(indexVertexArrays,useQuantizedAabbCompression);
|
||||||
|
|
||||||
|
tr.setOrigin(btVector3(0,-4.5f,0));
|
||||||
|
|
||||||
#else
|
#else
|
||||||
//testing btHeightfieldTerrainShape
|
//testing btHeightfieldTerrainShape
|
||||||
int width=128;
|
int width=128;
|
||||||
int length=128;
|
int length=128;
|
||||||
unsigned char* heightfieldData = new unsigned char[width*length];
|
unsigned char* heightfieldData = new unsigned char[width*length];
|
||||||
|
{
|
||||||
|
for (int i=0;i<width*length;i++)
|
||||||
|
{
|
||||||
|
heightfieldData[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// mRawData = new unsigned char [mSize*mSize]; //allocate memory for data
|
char* filename="heightfield128x128.raw";
|
||||||
// loadFile(filename,mSize*mSize,mRawData);
|
FILE* heightfieldFile = fopen(filename,"r");
|
||||||
|
if (!heightfieldFile)
|
||||||
|
{
|
||||||
|
filename="../../heightfield128x128.raw";
|
||||||
|
heightfieldFile = fopen(filename,"r");
|
||||||
|
}
|
||||||
|
if (heightfieldFile)
|
||||||
|
{
|
||||||
|
int numBytes =fread(heightfieldData,1,width*length,heightfieldFile);
|
||||||
|
//btAssert(numBytes);
|
||||||
|
if (!numBytes)
|
||||||
|
{
|
||||||
|
printf("couldn't read heightfield at %s\n",filename);
|
||||||
|
}
|
||||||
|
fclose (heightfieldFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
btScalar maxHeight = 1.f;
|
btScalar maxHeight = 20000.f;
|
||||||
|
|
||||||
groundShape = new btHeightfieldTerrainShape(width,length,heightfieldData,maxHeight,upIndex);
|
groundShape = new btHeightfieldTerrainShape(width,length,heightfieldData,maxHeight,upIndex);
|
||||||
btVector3 localScaling(10,10,10);
|
btVector3 localScaling(20,20,20);
|
||||||
localScaling[upIndex]=1.f;
|
localScaling[upIndex]=1.f;
|
||||||
groundShape->setLocalScaling(localScaling);
|
groundShape->setLocalScaling(localScaling);
|
||||||
|
|
||||||
|
tr.setOrigin(btVector3(0,-64.5f,0));
|
||||||
|
|
||||||
#endif //
|
#endif //
|
||||||
|
|
||||||
btTransform tr;
|
|
||||||
tr.setIdentity();
|
|
||||||
|
|
||||||
tr.setOrigin(btVector3(0,-4.5f,0));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user