minor tweaks to the demos

This commit is contained in:
erwin.coumans
2008-11-13 08:32:47 +00:00
parent 352aed528e
commit 1f66cd15a7
3 changed files with 4 additions and 121 deletions

View File

@@ -180,6 +180,7 @@ void Timer(int)
void SimulationLoop()
{
Resize(width, height);
@@ -461,7 +462,7 @@ int main(int argc, char** argv)
glui->add_button("Toggle Pause", 0,(GLUI_Update_CB)TogglePause);
glui->add_button("Single Step", 0,(GLUI_Update_CB)SingleSimulationStep);
// glui->add_button("Reset Scene", 0,(GLUI_Update_CB)ResetScene);
glui->add_button("Reset Scene", 0,(GLUI_Update_CB)ResetScene);
glui->add_button("Restart Scene", 0,(GLUI_Update_CB)RestartScene);
glui->add_separator();

View File

@@ -140,7 +140,7 @@ void ConcaveDemo::initPhysics()
{
setTexturing(true);
setShadows(true);
setShadows(false);//true);
#define TRISIZE 10.f

View File

@@ -209,128 +209,10 @@ void ForkLiftDemo::initPhysics()
//m_dynamicsWorld->setGravity(btVector3(0,0,0));
btTransform tr;
tr.setIdentity();
tr.setOrigin(btVector3(0,-10,0));
//either use heightfield or triangle mesh
#define USE_TRIMESH_GROUND 1
#ifdef USE_TRIMESH_GROUND
int i;
const float TRIANGLE_SIZE=20.f;
//create a triangle-mesh ground
int vertStride = sizeof(btVector3);
int indexStride = 3*sizeof(int);
const int NUM_VERTS_X = 20;
const int NUM_VERTS_Y = 20;
const int totalVerts = NUM_VERTS_X*NUM_VERTS_Y;
const int totalTriangles = 2*(NUM_VERTS_X-1)*(NUM_VERTS_Y-1);
m_vertices = new btVector3[totalVerts];
int* gIndices = new int[totalTriangles*3];
for ( i=0;i<NUM_VERTS_X;i++)
{
for (int j=0;j<NUM_VERTS_Y;j++)
{
float wl = .2f;
//height set to zero, but can also use curved landscape, just uncomment out the code
float height = 0.f;//20.f*sinf(float(i)*wl)*cosf(float(j)*wl);
#ifdef FORCE_ZAXIS_UP
m_vertices[i+j*NUM_VERTS_X].setValue(
(i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE,
height
);
#else
m_vertices[i+j*NUM_VERTS_X].setValue(
(i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
height,
(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
#endif
}
}
int index=0;
for ( i=0;i<NUM_VERTS_X-1;i++)
{
for (int j=0;j<NUM_VERTS_Y-1;j++)
{
gIndices[index++] = j*NUM_VERTS_X+i;
gIndices[index++] = j*NUM_VERTS_X+i+1;
gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
gIndices[index++] = j*NUM_VERTS_X+i;
gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
gIndices[index++] = (j+1)*NUM_VERTS_X+i;
}
}
m_indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles,
gIndices,
indexStride,
totalVerts,(btScalar*) &m_vertices[0].x(),vertStride);
bool useQuantizedAabbCompression = true;
groundShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression);
tr.setOrigin(btVector3(0,-4.5f,0));
#else
//testing btHeightfieldTerrainShape
int width=128;
int length=128;
unsigned char* heightfieldData = new unsigned char[width*length];
{
for (int i=0;i<width*length;i++)
{
heightfieldData[i]=0;
}
}
char* filename="heightfield128x128.raw";
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 = 20000.f;
bool useFloatDatam=false;
bool flipQuadEdges=false;
btHeightfieldTerrainShape* heightFieldShape = new btHeightfieldTerrainShape(width,length,heightfieldData,maxHeight,upIndex,useFloatDatam,flipQuadEdges);;
groundShape = heightFieldShape;
heightFieldShape->setUseDiamondSubdivision(true);
btVector3 localScaling(20,20,20);
localScaling[upIndex]=1.f;
groundShape->setLocalScaling(localScaling);
tr.setOrigin(btVector3(0,-64.5f,0));
#endif //
m_collisionShapes.push_back(groundShape);
//create ground object
localCreateRigidBody(0,tr,groundShape);