//#ifdef FORCE_ZAXIS_UP
//dynamicsWorld.setGravity(new Vector3f(0, 0, -10));
//#endif
//m_dynamicsWorld->setGravity(btVector3(0,0,0));
Transform tr = new Transform();
tr.setIdentity();
// either use heightfield or triangle mesh
//#define USE_TRIMESH_GROUND 1
//#ifdef USE_TRIMESH_GROUND
final float TRIANGLE_SIZE = 20f;
// create a triangle-mesh ground
int vertStride = 4 * 3 /* sizeof(btVector3) */;
int indexStride = 3 * 4 /* 3*sizeof(int) */;
final int NUM_VERTS_X = 20;
final int NUM_VERTS_Y = 20;
final int totalVerts = NUM_VERTS_X * NUM_VERTS_Y;
final int totalTriangles = 2 * (NUM_VERTS_X - 1) * (NUM_VERTS_Y - 1);
vertices = ByteBuffer.allocateDirect(totalVerts * vertStride).order(ByteOrder.nativeOrder());
ByteBuffer gIndices = ByteBuffer.allocateDirect(totalTriangles * 3 * 4).order(ByteOrder.nativeOrder());
Vector3f tmp = new Vector3f();
for (int i = 0; i < NUM_VERTS_X; i++) {
for (int j = 0; j < NUM_VERTS_Y; j++) {
float wl = 0.2f;
// height set to zero, but can also use curved landscape, just uncomment out the code
float height = 0f; // 20f * (float)Math.sin(i * wl) * (float)Math.cos(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
tmp.set(
(i - NUM_VERTS_X * 0.5f) * TRIANGLE_SIZE,
height,
(j - NUM_VERTS_Y * 0.5f) * TRIANGLE_SIZE);
int index = i + j * NUM_VERTS_X;
vertices.putFloat((index * 3 + 0) * 4, tmp.x);
vertices.putFloat((index * 3 + 1) * 4, tmp.y);
vertices.putFloat((index * 3 + 2) * 4, tmp.z);
//#endif
}
}
//int index=0;
gIndices.clear();
for (int i = 0; i < NUM_VERTS_X - 1; i++) {
for (int j = 0; j < NUM_VERTS_Y - 1; j++) {
gIndices.putInt(j * NUM_VERTS_X + i);
gIndices.putInt(j * NUM_VERTS_X + i + 1);
gIndices.putInt((j + 1) * NUM_VERTS_X + i + 1);
gIndices.putInt(j * NUM_VERTS_X + i);
gIndices.putInt((j + 1) * NUM_VERTS_X + i + 1);
gIndices.putInt((j + 1) * NUM_VERTS_X + i);
}
}
gIndices.flip();
indexVertexArrays = new TriangleIndexVertexArray(totalTriangles,
gIndices,
indexStride,
totalVerts, vertices, vertStride);
boolean useQuantizedAabbCompression = true;
groundShape = new BvhTriangleMeshShape(indexVertexArrays, useQuantizedAabbCompression);
tr.origin.set(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
collisionShapes.add(groundShape);
// create ground object
localCreateRigidBody(0, tr, groundShape);
//#ifdef FORCE_ZAXIS_UP
// // indexRightAxis = 0;
// // indexUpAxis = 2;
// // indexForwardAxis = 1;
//btCollisionShape* chassisShape = new btBoxShape(btVector3(1.f,2.f, 0.5f));
//btCompoundShape* compound = new btCompoundShape();
//btTransform localTrans;
//localTrans.setIdentity();
// //localTrans effectively shifts the center of mass with respect to the chassis
//localTrans.setOrigin(btVector3(0,0,1));
//#else
CollisionShape chassisShape = new BoxShape(new Vector3f(1.0f, 0.5f, 2.0f));
collisionShapes.add(chassisShape);
CompoundShape compound = new CompoundShape();
collisionShapes.add(compound);
Transform localTrans = new Transform();
localTrans.setIdentity();
// localTrans effectively shifts the center of mass with respect to the chassis
localTrans.origin.set(0, 1, 0);
//#endif
compound.addChildShape(localTrans, chassisShape);