Added new files to CMakeLists.txt for CharacterDemo

Use relative path, #include "../BspDemo/BspLoader.h"
This commit is contained in:
erwin.coumans
2008-07-03 23:47:38 +00:00
parent b6af86bd98
commit 76bac83937
2 changed files with 54 additions and 50 deletions

View File

@@ -25,6 +25,10 @@ ADD_EXECUTABLE(CharacterDemo
CharacterControllerInterface.h CharacterControllerInterface.h
CharacterDemo.cpp CharacterDemo.cpp
CharacterDemo.h CharacterDemo.h
../BspDemo/BspConverter.cpp
../BspDemo/BspConverter.h
../BspDemo/BspLoader.cpp
../BspDemo/BspLoader.h
main.cpp main.cpp
) )

View File

@@ -4,8 +4,8 @@ Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty. This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions: subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
@@ -46,9 +46,9 @@ static int gJump = 0;
#define QUAKE_BSP_IMPORTING 1 #define QUAKE_BSP_IMPORTING 1
#ifdef QUAKE_BSP_IMPORTING #ifdef QUAKE_BSP_IMPORTING
#include "Demos/BspDemo/BspLoader.h" #include "../BspDemo/BspLoader.h"
#include "Demos/BspDemo/BspConverter.h" #include "../BspDemo/BspConverter.h"
#endif //QUAKE_BSP_IMPORTING
class BspToBulletConverter : public BspConverter class BspToBulletConverter : public BspConverter
@@ -66,7 +66,7 @@ public:
{ {
///perhaps we can do something special with entities (isEntity) ///perhaps we can do something special with entities (isEntity)
///like adding a collision Triggering (as example) ///like adding a collision Triggering (as example)
if (vertices.size() > 0) if (vertices.size() > 0)
{ {
float mass = 0.f; float mass = 0.f;
@@ -91,7 +91,7 @@ public:
} }
} }
}; };
#endif //QUAKE_BSP_IMPORTING
CharacterDemo::CharacterDemo() CharacterDemo::CharacterDemo()
: :
m_cameraHeight(4.f), m_cameraHeight(4.f),
@@ -177,7 +177,7 @@ public:
m_hashPairCache = new btHashedOverlappingPairCache(); m_hashPairCache = new btHashedOverlappingPairCache();
m_hashPairCache->setOverlapFilterCallback (&myCustomOverlapFilterCallback); m_hashPairCache->setOverlapFilterCallback (&myCustomOverlapFilterCallback);
} }
virtual ~MyCustomOverlappingPairCallback() virtual ~MyCustomOverlappingPairCallback()
{ {
delete m_hashPairCache; delete m_hashPairCache;
@@ -211,7 +211,7 @@ public:
m_hashPairCache->removeOverlappingPairsContainingProxy(proxy0,dispatcher); m_hashPairCache->removeOverlappingPairsContainingProxy(proxy0,dispatcher);
} }
} }
btBroadphasePairArray& getOverlappingPairArray() btBroadphasePairArray& getOverlappingPairArray()
{ {
return m_hashPairCache->getOverlappingPairArray(); return m_hashPairCache->getOverlappingPairArray();
@@ -234,7 +234,7 @@ void CharacterDemo::initPhysics()
btVector3 worldMax(1000,1000,1000); btVector3 worldMax(1000,1000,1000);
btAxisSweep3* sweepBP = new btAxisSweep3(worldMin,worldMax); btAxisSweep3* sweepBP = new btAxisSweep3(worldMin,worldMax);
m_overlappingPairCache = sweepBP; m_overlappingPairCache = sweepBP;
m_constraintSolver = new btSequentialImpulseConstraintSolver(); m_constraintSolver = new btSequentialImpulseConstraintSolver();
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_constraintSolver,m_collisionConfiguration); m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_constraintSolver,m_collisionConfiguration);
//m_dynamicsWorld->setGravity(btVector3(0,0,0)); //m_dynamicsWorld->setGravity(btVector3(0,0,0));
@@ -246,11 +246,11 @@ void CharacterDemo::initPhysics()
#ifdef QUAKE_BSP_IMPORTING #ifdef QUAKE_BSP_IMPORTING
char* bspfilename = "BspDemo.bsp"; char* bspfilename = "BspDemo.bsp";
void* memoryBuffer = 0; void* memoryBuffer = 0;
FILE* file = fopen(bspfilename,"r"); FILE* file = fopen(bspfilename,"r");
if (!file) if (!file)
{ {
//try again other path, //try again other path,
//sight... visual studio leaves the current working directory in the projectfiles folder //sight... visual studio leaves the current working directory in the projectfiles folder
//instead of executable folder. who wants this default behaviour?!? //instead of executable folder. who wants this default behaviour?!?
bspfilename = "../../BspDemo.bsp"; bspfilename = "../../BspDemo.bsp";
@@ -258,7 +258,7 @@ void CharacterDemo::initPhysics()
} }
if (!file) if (!file)
{ {
//try again other path, //try again other path,
//sight... visual studio leaves the current working directory in the projectfiles folder //sight... visual studio leaves the current working directory in the projectfiles folder
//instead of executable folder. who wants this default behaviour?!? //instead of executable folder. who wants this default behaviour?!?
bspfilename = "BspDemo.bsp"; bspfilename = "BspDemo.bsp";
@@ -301,13 +301,13 @@ const float TRIANGLE_SIZE=20.f;
const int NUM_VERTS_X = 20; const int NUM_VERTS_X = 20;
const int NUM_VERTS_Y = 20; const int NUM_VERTS_Y = 20;
const int totalVerts = NUM_VERTS_X*NUM_VERTS_Y; const int totalVerts = NUM_VERTS_X*NUM_VERTS_Y;
const int totalTriangles = 2*(NUM_VERTS_X-1)*(NUM_VERTS_Y-1); const int totalTriangles = 2*(NUM_VERTS_X-1)*(NUM_VERTS_Y-1);
m_vertices = new btVector3[totalVerts]; m_vertices = new btVector3[totalVerts];
int* gIndices = new int[totalTriangles*3]; int* gIndices = new int[totalTriangles*3];
for ( i=0;i<NUM_VERTS_X;i++) for ( i=0;i<NUM_VERTS_X;i++)
{ {
@@ -347,7 +347,7 @@ const float TRIANGLE_SIZE=20.f;
gIndices[index++] = (j+1)*NUM_VERTS_X+i; gIndices[index++] = (j+1)*NUM_VERTS_X+i;
} }
} }
m_indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles, m_indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles,
gIndices, gIndices,
indexStride, indexStride,
@@ -355,7 +355,7 @@ const float TRIANGLE_SIZE=20.f;
bool useQuantizedAabbCompression = true; bool useQuantizedAabbCompression = true;
groundShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression); groundShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression);
tr.setOrigin(btVector3(0,-4.5f,0)); tr.setOrigin(btVector3(0,-4.5f,0));
#else #else
@@ -387,16 +387,16 @@ const float TRIANGLE_SIZE=20.f;
} }
fclose (heightfieldFile); fclose (heightfieldFile);
} }
btScalar maxHeight = 20000.f; btScalar maxHeight = 20000.f;
bool useFloatDatam=false; bool useFloatDatam=false;
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);;
groundShape = heightFieldShape; groundShape = heightFieldShape;
heightFieldShape->setUseDiamondSubdivision(true); heightFieldShape->setUseDiamondSubdivision(true);
btVector3 localScaling(20,20,20); btVector3 localScaling(20,20,20);
@@ -428,7 +428,7 @@ const float TRIANGLE_SIZE=20.f;
btTransform trans; btTransform trans;
trans.setIdentity(); trans.setIdentity();
if (i>0) if (i>0)
{ {
//stack them //stack them
@@ -457,7 +457,7 @@ const float TRIANGLE_SIZE=20.f;
if (!isDyna) if (!isDyna)
mass = 0.f; mass = 0.f;
btRigidBody* body = localCreateRigidBody(mass,trans,shape); btRigidBody* body = localCreateRigidBody(mass,trans,shape);
#ifdef USE_KINEMATIC_GROUND #ifdef USE_KINEMATIC_GROUND
if (mass == 0.f) if (mass == 0.f)
@@ -466,7 +466,7 @@ const float TRIANGLE_SIZE=20.f;
body->setActivationState(DISABLE_DEACTIVATION); body->setActivationState(DISABLE_DEACTIVATION);
} }
#endif //USE_KINEMATIC_GROUND #endif //USE_KINEMATIC_GROUND
} }
#endif #endif
@@ -484,7 +484,7 @@ const float TRIANGLE_SIZE=20.f;
sweepBP->setOverlappingPairUserCallback(m_customPairCallback); sweepBP->setOverlappingPairUserCallback(m_customPairCallback);
m_character->registerPairCache (m_customPairCallback->getOverlappingPairCache()); m_character->registerPairCache (m_customPairCallback->getOverlappingPairCache());
clientResetScene(); clientResetScene();
setCameraDistance(26.f); setCameraDistance(26.f);
} }
@@ -501,13 +501,13 @@ void CharacterDemo::renderme()
void CharacterDemo::clientMoveAndDisplay() void CharacterDemo::clientMoveAndDisplay()
{ {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float dt = getDeltaTimeMicroseconds() * 0.000001f; float dt = getDeltaTimeMicroseconds() * 0.000001f;
/* Character stuff &*/ /* Character stuff &*/
if (m_character) if (m_character)
{ {
m_character->preStep (m_dynamicsWorld); m_character->preStep (m_dynamicsWorld);
m_character->playerStep (m_dynamicsWorld, dt, gForward, gBackward, gLeft, gRight, gJump); m_character->playerStep (m_dynamicsWorld, dt, gForward, gBackward, gLeft, gRight, gJump);
} }
@@ -519,7 +519,7 @@ void CharacterDemo::clientMoveAndDisplay()
for (int i=0;i<m_customPairCallback->getOverlappingPairArray().size();i++) for (int i=0;i<m_customPairCallback->getOverlappingPairArray().size();i++)
{ {
manifoldArray.clear(); manifoldArray.clear();
const btBroadphasePair& pair = m_customPairCallback->getOverlappingPairArray()[i]; const btBroadphasePair& pair = m_customPairCallback->getOverlappingPairArray()[i];
btBroadphasePair* collisionPair = m_overlappingPairCache->getOverlappingPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1); btBroadphasePair* collisionPair = m_overlappingPairCache->getOverlappingPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1);
@@ -544,7 +544,7 @@ void CharacterDemo::clientMoveAndDisplay()
#endif #endif
if (m_dynamicsWorld) if (m_dynamicsWorld)
{ {
//during idle mode, just run 1 simulation step maximum //during idle mode, just run 1 simulation step maximum
@@ -553,7 +553,7 @@ void CharacterDemo::clientMoveAndDisplay()
dt = 1.0/420.f; dt = 1.0/420.f;
int numSimSteps = m_dynamicsWorld->stepSimulation(dt,maxSimSubSteps); int numSimSteps = m_dynamicsWorld->stepSimulation(dt,maxSimSubSteps);
//optional but useful: debug drawing //optional but useful: debug drawing
if (m_dynamicsWorld) if (m_dynamicsWorld)
m_dynamicsWorld->debugDrawWorld(); m_dynamicsWorld->debugDrawWorld();
@@ -577,23 +577,23 @@ void CharacterDemo::clientMoveAndDisplay()
} }
#ifdef USE_QUICKPROF
btProfiler::beginBlock("render");
#endif //USE_QUICKPROF
renderme(); #ifdef USE_QUICKPROF
btProfiler::beginBlock("render");
#endif //USE_QUICKPROF
renderme();
#ifdef USE_QUICKPROF
btProfiler::endBlock("render");
#endif
#ifdef USE_QUICKPROF
btProfiler::endBlock("render");
#endif
glFlush(); glFlush();
glutSwapBuffers(); glutSwapBuffers();
@@ -602,9 +602,9 @@ void CharacterDemo::clientMoveAndDisplay()
void CharacterDemo::displayCallback(void) void CharacterDemo::displayCallback(void)
{ {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderme(); renderme();
@@ -618,16 +618,16 @@ void CharacterDemo::displayCallback(void)
} }
void CharacterDemo::clientResetScene() void CharacterDemo::clientResetScene()
{ {
m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(m_character->getCollisionObject()->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher()); m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(m_character->getCollisionObject()->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher());
m_character->reset (); m_character->reset ();
m_character->warp (btVector3(0.0, 1.75, 0.0)); m_character->warp (btVector3(0.0, 1.75, 0.0));
} }
void CharacterDemo::specialKeyboardUp(int key, int x, int y) void CharacterDemo::specialKeyboardUp(int key, int x, int y)
{ {
switch (key) switch (key)
{ {
case GLUT_KEY_UP: case GLUT_KEY_UP:
{ {
@@ -635,7 +635,7 @@ void CharacterDemo::specialKeyboardUp(int key, int x, int y)
} }
break; break;
case GLUT_KEY_DOWN: case GLUT_KEY_DOWN:
{ {
gBackward = 0; gBackward = 0;
} }
break; break;
@@ -661,7 +661,7 @@ void CharacterDemo::specialKeyboard(int key, int x, int y)
// printf("key = %i x=%i y=%i\n",key,x,y); // printf("key = %i x=%i y=%i\n",key,x,y);
switch (key) switch (key)
{ {
case GLUT_KEY_UP: case GLUT_KEY_UP:
{ {
@@ -669,7 +669,7 @@ void CharacterDemo::specialKeyboard(int key, int x, int y)
} }
break; break;
case GLUT_KEY_DOWN: case GLUT_KEY_DOWN:
{ {
gBackward = 1; gBackward = 1;
} }
break; break;
@@ -701,7 +701,7 @@ void CharacterDemo::specialKeyboard(int key, int x, int y)
void CharacterDemo::updateCamera() void CharacterDemo::updateCamera()
{ {
//#define DISABLE_CAMERA 1 //#define DISABLE_CAMERA 1
#ifdef DISABLE_CAMERA #ifdef DISABLE_CAMERA
DemoApplication::updateCamera(); DemoApplication::updateCamera();
@@ -722,7 +722,7 @@ void CharacterDemo::updateCamera()
m_cameraTargetPosition = characterWorldTrans.getOrigin(); m_cameraTargetPosition = characterWorldTrans.getOrigin();
m_cameraPosition = m_cameraTargetPosition + up * 2.0 + backward * 2.0; m_cameraPosition = m_cameraTargetPosition + up * 2.0 + backward * 2.0;
//update OpenGL camera settings //update OpenGL camera settings
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10000.0); glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10000.0);
@@ -732,7 +732,7 @@ void CharacterDemo::updateCamera()
gluLookAt(m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2], gluLookAt(m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2],
m_cameraTargetPosition[0],m_cameraTargetPosition[1], m_cameraTargetPosition[2], m_cameraTargetPosition[0],m_cameraTargetPosition[1], m_cameraTargetPosition[2],
m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ()); m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ());
} }