Index: main.cpp
===================================================================
--- main.cpp (revision 2099)
+++ main.cpp (working copy)
@@ -11,7 +11,7 @@
InternalEdgeDemo* internalEdgeDemo = new InternalEdgeDemo();
internalEdgeDemo->initPhysics();
- internalEdgeDemo->setCameraDistance(30.f);
+ internalEdgeDemo->setCameraDistance(2.f);
return glutmain(argc, argv,640,480,"Internal Edge Demo",internalEdgeDemo);
Index: InternalEdgeDemo.cpp
===================================================================
--- InternalEdgeDemo.cpp (revision 2099)
+++ InternalEdgeDemo.cpp (working copy)
@@ -18,7 +18,7 @@
//#define SHIFT_INDICES 1
#define SWAP_WINDING 1
//#define ROTATE_GROUND 1
-bool enable=true;
+bool enable=false;
#if defined (SHIFT_INDICES) && !defined (SWAP_WINDING)
//#define TEST_INCONSISTENT_WINDING
@@ -113,28 +113,6 @@
extern ContactAddedCallback gContactAddedCallback;
- const int NUM_VERTS_X = 2;
- const int NUM_VERTS_Y = 2;
- const int totalVerts = NUM_VERTS_X*NUM_VERTS_Y;
-
-void InternalEdgeDemo::setVertexPositions(float waveheight, float offset)
-{
- int i;
- int j;
-
- for ( i=0;i<NUM_VERTS_X;i++)
- {
- for (j=0;j<NUM_VERTS_Y;j++)
- {
- gVertices[i+j*NUM_VERTS_X].setValue(
- (i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
- //0.f,
- waveheight*sinf((float)i+offset)*cosf((float)j+offset),
- (j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
- }
- }
-}
-
void InternalEdgeDemo::keyboardCallback(unsigned char key, int x, int y)
{
if (key=='n')
@@ -168,163 +146,53 @@
setTexturing(true);
setShadows(false);//true);
- #define TRISIZE 10.f
-
gContactAddedCallback = CustomMaterialCombinerCallback;
-#define USE_TRIMESH_SHAPE 1
-#ifdef USE_TRIMESH_SHAPE
-
int vertStride = sizeof(btVector3);
int indexStride = 3*sizeof(int);
- const int totalTriangles = 2*(NUM_VERTS_X-1)*(NUM_VERTS_Y-1);
+ const int totalVerts = 8;
gVertices = new btVector3[totalVerts];
- gIndices = new int[totalTriangles*3];
- int i;
+ float hw = 0.083/2;
+ gVertices[0].setValue(-hw, -1, -hw);
+ gVertices[1].setValue(-hw, -1, hw);
+ gVertices[2].setValue( hw, -1, -hw);
+ gVertices[3].setValue( hw, -1, hw);
+ gVertices[4].setValue(-hw, 1, -hw);
+ gVertices[5].setValue(-hw, 1, hw);
+ gVertices[6].setValue( hw, 1, -hw);
+ gVertices[7].setValue( hw, 1, hw);
+ int quads[] = {
+ 0,1,4,5,
+ 3,2,7,6,
+ 0,2,4,6,
+ 3,1,7,5,
+ 4,5,6,7,
+ };
+ unsigned num_quads = sizeof(quads)/sizeof(quads[0])/4;
- setVertexPositions(waveheight,0.f);
-
-
- //gVertices[1].setY(21.1);
- //gVertices[1].setY(121.1);
- gVertices[1].setY(.1f);
+ const int totalTriangles = num_quads*2;
+ gIndices = new int[totalTriangles*3];
-#ifdef ROTATE_GROUND
- //gVertices[1].setY(-1.1);
-#else
- //gVertices[1].setY(0.1);
- //gVertices[1].setY(-0.1);
- //gVertices[1].setY(-20.1);
- //gVertices[1].setY(-20);
-#endif
-
- int index=0;
- for ( i=0;i<NUM_VERTS_X-1;i++)
- {
- for (int j=0;j<NUM_VERTS_Y-1;j++)
- {
+ for (unsigned i=0 ; i<num_quads ; ++i) {
+ gIndices[6*i+0]=quads[4*i+0]; gIndices[6*i+1]=quads[4*i+1]; gIndices[6*i+2]=quads[4*i+2];
+ gIndices[6*i+3]=quads[4*i+1]; gIndices[6*i+4]=quads[4*i+3]; gIndices[6*i+5]=quads[4*i+2];
+ }
-#ifdef SWAP_WINDING
-#ifdef SHIFT_INDICES
- gIndices[index++] = j*NUM_VERTS_X+i;
- gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
- gIndices[index++] = j*NUM_VERTS_X+i+1;
-
- gIndices[index++] = j*NUM_VERTS_X+i;
- gIndices[index++] = (j+1)*NUM_VERTS_X+i;
- gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
-
-#else
- gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
- gIndices[index++] = j*NUM_VERTS_X+i+1;
- gIndices[index++] = j*NUM_VERTS_X+i;
+ m_indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles, gIndices, indexStride, totalVerts,(btScalar*) &gVertices[0].x(),vertStride);
- gIndices[index++] = (j+1)*NUM_VERTS_X+i;
- gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
- gIndices[index++] = j*NUM_VERTS_X+i;
-#endif //SHIFT_INDICES
-#else //SWAP_WINDING
-
-#ifdef SHIFT_INDICES
- gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
- gIndices[index++] = j*NUM_VERTS_X+i;
- gIndices[index++] = j*NUM_VERTS_X+i+1;
-
-#ifdef TEST_INCONSISTENT_WINDING
- gIndices[index++] = j*NUM_VERTS_X+i;
- gIndices[index++] = (j+1)*NUM_VERTS_X+i;
- gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
-
-#else //TEST_INCONSISTENT_WINDING
- gIndices[index++] = (j+1)*NUM_VERTS_X+i;
- gIndices[index++] = j*NUM_VERTS_X+i;
- gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
-#endif //TEST_INCONSISTENT_WINDING
-
-
-
-#else //SHIFT_INDICES
- 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;
-#endif //SHIFT_INDICES
-
-#endif //SWAP_WINDING
-
-
- }
- }
-
- m_indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles,
- gIndices,
- indexStride,
- totalVerts,(btScalar*) &gVertices[0].x(),vertStride);
-
bool useQuantizedAabbCompression = true;
-//comment out the next line to read the BVH from disk (first run the demo once to create the BVH)
-#define SERIALIZE_TO_DISK 1
-#ifdef SERIALIZE_TO_DISK
btVector3 aabbMin(-1000,-1000,-1000),aabbMax(1000,1000,1000);
trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,aabbMin,aabbMax);
m_collisionShapes.push_back(trimeshShape);
-
- ///we can serialize the BVH data
- void* buffer = 0;
- int numBytes = trimeshShape->getOptimizedBvh()->calculateSerializeBufferSize();
- buffer = btAlignedAlloc(numBytes,16);
- bool swapEndian = false;
- trimeshShape->getOptimizedBvh()->serialize(buffer,numBytes,swapEndian);
- FILE* file = fopen("bvh.bin","wb");
- fwrite(buffer,1,numBytes,file);
- fclose(file);
- btAlignedFree(buffer);
-
-
-
-#else
-
- trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,false);
-
- char* fileName = "bvh.bin";
-
- FILE* file = fopen(fileName,"rb");
- int size=0;
- btOptimizedBvh* bvh = 0;
-
- if (fseek(file, 0, SEEK_END) || (size = ftell(file)) == EOF || fseek(file, 0, SEEK_SET)) { /* File operations denied? ok, just close and return failure */
- printf("Error: cannot get filesize from %s\n", fileName);
- exit(0);
- } else
- {
-
- fseek(file, 0, SEEK_SET);
-
- int buffersize = size+btOptimizedBvh::getAlignmentSerializationPadding();
-
- void* buffer = btAlignedAlloc(buffersize,16);
- int read = fread(buffer,1,size,file);
- fclose(file);
- bool swapEndian = false;
- bvh = btOptimizedBvh::deSerializeInPlace(buffer,buffersize,swapEndian);
- }
-
- trimeshShape->setOptimizedBvh(bvh);
-
-#endif
-
btCollisionShape* groundShape = trimeshShape;
btTriangleInfoMap* triangleInfoMap = new btTriangleInfoMap();
@@ -334,13 +202,7 @@
-#else
- btCollisionShape* groundShape = new btBoxShape(btVector3(50,3,50));
- m_collisionShapes.push_back(groundShape);
-
-#endif //USE_TRIMESH_SHAPE
-
m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_collisionConfiguration->setConvexConvexMultipointIterations(10,5);
@@ -364,32 +226,21 @@
float mass = 0.f;
btTransform startTransform;
- startTransform.setIdentity();
- startTransform.setOrigin(btVector3(0,-2,0));
- btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
+ btCollisionShape* colShape = new btBoxShape(btVector3(0.15,0.15,0.15));
//colShape->setMargin(0.f);
colShape->setMargin(0.1f);
m_collisionShapes.push_back(colShape);
- {
- for (int i=0;i<1;i++)
- {
- startTransform.setOrigin(btVector3(-10.f+i*3.f,1.f+btScalar(i)*0.1f,-1.3f));
- btRigidBody* body = localCreateRigidBody(100, startTransform,colShape);
- body->setActivationState(DISABLE_DEACTIVATION);
- body->setLinearVelocity(btVector3(0,0,-1));
- }
- }
+ startTransform.setIdentity();
+ startTransform.setOrigin(btVector3(0,1.15,0));
+ btRigidBody* body = localCreateRigidBody(100, startTransform,colShape);
+ body->setActivationState(DISABLE_DEACTIVATION);
+ //body->setLinearVelocity(btVector3(0,0,-1));
startTransform.setIdentity();
-#ifdef ROTATE_GROUND
- btQuaternion orn(btVector3(0,0,1),SIMD_PI);
- startTransform.setOrigin(btVector3(-20,0,0));
- startTransform.setRotation(orn);
-#endif //ROTATE_GROUND
staticBody = localCreateRigidBody(mass, startTransform,groundShape);
//staticBody->setContactProcessingThreshold(-0.031f);
@@ -418,7 +269,7 @@
if (body && body->getInvMass() != 0.f)
{
- body->setLinearVelocity(btVector3(0,0,-1));
+ //body->setLinearVelocity(btVector3(0,0,-1));
}
}
@@ -474,7 +325,7 @@
- m_dynamicsWorld->stepSimulation(dt);
+ m_dynamicsWorld->stepSimulation(dt/10,10,0.001);
///enable one of the following to debug (render debug lines each frame)
//m_dynamicsWorld->stepSimulation(1./800.,0);
//m_dynamicsWorld->stepSimulation(1./60.,100,1./800.);