Code rework. Basically cleaned up a mess of tabs and whitespaces.
This commit is contained in:
parent
b2398ba643
commit
47fded52ce
@ -15,7 +15,6 @@ class Converter {
|
|||||||
std::vector<int> newComposition(int type, float posX, float posZ);//creates a new composition and returns its ID
|
std::vector<int> newComposition(int type, float posX, float posZ);//creates a new composition and returns its ID
|
||||||
void deleteComposition(int idG, int idB);
|
void deleteComposition(int idG, int idB);
|
||||||
void save(); //writes the xml to file
|
void save(); //writes the xml to file
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void errorCheck(XMLError error);
|
void errorCheck(XMLError error);
|
||||||
std::vector<int> nextID;
|
std::vector<int> nextID;
|
||||||
|
@ -217,7 +217,6 @@ glm::mat4 Graphics::buildViewMatrix(Level* level) {
|
|||||||
|
|
||||||
return glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()),
|
return glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()),
|
||||||
level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));
|
level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Graphics::getFarPlane() {
|
float Graphics::getFarPlane() {
|
||||||
|
1
main.cc
1
main.cc
@ -142,7 +142,6 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
double lastUpdate=0.0f;
|
double lastUpdate=0.0f;
|
||||||
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
double now = glfwGetTime()- startTimeInSeconds;
|
double now = glfwGetTime()- startTimeInSeconds;
|
||||||
|
38
physics.cc
38
physics.cc
@ -24,11 +24,10 @@ void Physics::init(std::string geometryPath) //prepares bullet by creating all i
|
|||||||
|
|
||||||
void Physics::takeUpdateStep(float timeDiff)
|
void Physics::takeUpdateStep(float timeDiff)
|
||||||
{
|
{
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
if(counter<1)
|
if(counter<1)
|
||||||
{
|
{
|
||||||
world->stepSimulation(timeDiff);//allows the world to be simmulated correctly indipendant of the timedifferences between frames
|
world->stepSimulation(timeDiff); //allows the world to be simmulated correctly indipendant of the timedifferences between frames
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,8 +52,8 @@ void Physics::takeUpdateStep(float timeDiff)
|
|||||||
position.setY(playerBall->getCenterOfMassPosition().getY() + 1);
|
position.setY(playerBall->getCenterOfMassPosition().getY() + 1);
|
||||||
|
|
||||||
btVector3 dir = cameraBody->getCenterOfMassPosition() - position;
|
btVector3 dir = cameraBody->getCenterOfMassPosition() - position;
|
||||||
float str = 50 * dir.length() / cameraBody->getInvMass();
|
float str = 50 * dir.length() / cameraBody->getInvMass(); //getInvMass() returns the inverted mass
|
||||||
cameraBody->applyCentralForce(-dir*str);//scale the force by camera mass
|
cameraBody->applyCentralForce(-dir*str); //scale the force by camera mass
|
||||||
counter=0;
|
counter=0;
|
||||||
float speed = cameraBody->getLinearVelocity().length();
|
float speed = cameraBody->getLinearVelocity().length();
|
||||||
if(speed>20.0f)
|
if(speed>20.0f)
|
||||||
@ -66,7 +65,7 @@ void Physics::takeUpdateStep(float timeDiff)
|
|||||||
}
|
}
|
||||||
world->stepSimulation(timeDiff);
|
world->stepSimulation(timeDiff);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
void Physics::removePositionConstraint(int bodyIndice) //remover function for deleting all pos constraints on one body
|
void Physics::removePositionConstraint(int bodyIndice) //remover function for deleting all pos constraints on one body
|
||||||
{
|
{
|
||||||
for(unsigned i = 0; i < allPositionConstraints.size(); i++)
|
for(unsigned i = 0; i < allPositionConstraints.size(); i++)
|
||||||
@ -128,7 +127,7 @@ void Physics::addPlayer(float friction, float rad, Entity entity, float mass, fl
|
|||||||
|
|
||||||
void Physics::addTerrain(int width, int length, float** heightData) //The terrain adding function
|
void Physics::addTerrain(int width, int length, float** heightData) //The terrain adding function
|
||||||
{
|
{
|
||||||
float* heightfield = new float[width * length];//bullet only accepts data in a one dimensional array, so parse data into appropriate format
|
float* heightfield = new float[width * length]; //bullet only accepts data in a one dimensional array, so parse data into appropriate format
|
||||||
int highest = -999999, j = 0, i = 0;
|
int highest = -999999, j = 0, i = 0;
|
||||||
for (i = 0; i < width; i++)
|
for (i = 0; i < width; i++)
|
||||||
{
|
{
|
||||||
@ -171,10 +170,10 @@ void Physics::addTriangleMeshBody(Entity entity, std::string path, float mass, f
|
|||||||
}
|
}
|
||||||
while( 1 ){
|
while( 1 ){
|
||||||
char lineHeader[128];
|
char lineHeader[128];
|
||||||
// read the first word of the line
|
//read the first word of the line
|
||||||
int res = fscanf(file, "%s", lineHeader);
|
int res = fscanf(file, "%s", lineHeader);
|
||||||
if (res == EOF)
|
if (res == EOF)
|
||||||
break; // while not at end do loop
|
break; //while not at end do loop
|
||||||
if ( strcmp( lineHeader, "v" ) == 0 ){ //if a vertex
|
if ( strcmp( lineHeader, "v" ) == 0 ){ //if a vertex
|
||||||
glm::vec3 vertex;
|
glm::vec3 vertex;
|
||||||
fscanf(file, "%f %f %f\n", &vertex.x, &vertex.y, &vertex.z );
|
fscanf(file, "%f %f %f\n", &vertex.x, &vertex.y, &vertex.z );
|
||||||
@ -183,7 +182,7 @@ void Physics::addTriangleMeshBody(Entity entity, std::string path, float mass, f
|
|||||||
else if ( strcmp( lineHeader, "f" ) == 0 ){ //if face (index for 3 vertexes for a triangle)
|
else if ( strcmp( lineHeader, "f" ) == 0 ){ //if face (index for 3 vertexes for a triangle)
|
||||||
std::string vertex1, vertex2, vertex3;
|
std::string vertex1, vertex2, vertex3;
|
||||||
unsigned int vertexIndex[3], uvIndex[3], normalIndex[3];
|
unsigned int vertexIndex[3], uvIndex[3], normalIndex[3];
|
||||||
int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIndex[0], &uvIndex[0], &normalIndex[0], &vertexIndex[1], &uvIndex[1], &normalIndex[1], &vertexIndex[2], &uvIndex[2], &normalIndex[2] );
|
int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIndex[0], &uvIndex[0], &normalIndex[0], &vertexIndex[1], &uvIndex[1], &normalIndex[1], &vertexIndex[2], &uvIndex[2], &normalIndex[2]);
|
||||||
vertexIndices.push_back(vertexIndex[0]);
|
vertexIndices.push_back(vertexIndex[0]);
|
||||||
vertexIndices.push_back(vertexIndex[1]);
|
vertexIndices.push_back(vertexIndex[1]);
|
||||||
vertexIndices.push_back(vertexIndex[2]); //save 3 indexes in array
|
vertexIndices.push_back(vertexIndex[2]); //save 3 indexes in array
|
||||||
@ -194,7 +193,7 @@ void Physics::addTriangleMeshBody(Entity entity, std::string path, float mass, f
|
|||||||
|
|
||||||
for(unsigned i = 2; i < vertexIndices.size();i+=3)
|
for(unsigned i = 2; i < vertexIndices.size();i+=3)
|
||||||
{
|
{
|
||||||
triMesh->addTriangle(temp_vertices[vertexIndices[i]],temp_vertices[vertexIndices[i-1]],temp_vertices[vertexIndices[i-2]]); // for every face (3 elements in vertexIndices) create triangle use the indices to find correct vertexes to make the triangle
|
triMesh->addTriangle(temp_vertices[vertexIndices[i]],temp_vertices[vertexIndices[i-1]],temp_vertices[vertexIndices[i-2]]); //for every face (3 elements in vertexIndices) create triangle use the indices to find correct vertexes to make the triangle
|
||||||
}
|
}
|
||||||
|
|
||||||
btBvhTriangleMeshShape* shape = new btBvhTriangleMeshShape(triMesh,true);
|
btBvhTriangleMeshShape* shape = new btBvhTriangleMeshShape(triMesh,true);
|
||||||
@ -273,7 +272,6 @@ void Physics::addBox(float width, float height, float length, Entity entity, flo
|
|||||||
box->calculateLocalInertia((btScalar)mass,inertia);
|
box->calculateLocalInertia((btScalar)mass,inertia);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,box,inertia);
|
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,box,inertia);
|
||||||
|
|
||||||
btRigidBody* body = new btRigidBody(info);
|
btRigidBody* body = new btRigidBody(info);
|
||||||
@ -306,7 +304,6 @@ void Physics::addSphere(float rad, Entity entity, float mass, float dampningL, f
|
|||||||
|
|
||||||
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia);
|
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia);
|
||||||
|
|
||||||
|
|
||||||
btRigidBody* body = new btRigidBody(info);
|
btRigidBody* body = new btRigidBody(info);
|
||||||
|
|
||||||
body->setDamping(dampningL, dampningA);
|
body->setDamping(dampningL, dampningA);
|
||||||
@ -319,12 +316,11 @@ void Physics::addSphere(float rad, Entity entity, float mass, float dampningL, f
|
|||||||
|
|
||||||
if(bodies.size() != indice)
|
if(bodies.size() != indice)
|
||||||
throw std::invalid_argument( "Bodies out of Sync" );
|
throw std::invalid_argument( "Bodies out of Sync" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physics::addCamera() //Camera Creator automatically called when player is created
|
void Physics::addCamera() //Camera Creator automatically called when player is created
|
||||||
{
|
{
|
||||||
btSphereShape* sphere = new btSphereShape(0.5f);//we use this to make a more interesting camera, that does not interpenetrate with the terrain/objects
|
btSphereShape* sphere = new btSphereShape(0.5f); //we use this to make a more interesting camera, that does not interpenetrate with the terrain/objects
|
||||||
|
|
||||||
btVector3 inertia(0,0,0); //rotation handled elsewhere (as it always has to look at the player)
|
btVector3 inertia(0,0,0); //rotation handled elsewhere (as it always has to look at the player)
|
||||||
|
|
||||||
@ -344,7 +340,6 @@ void Physics::addCamera() //Camera Creator automatically called when player is c
|
|||||||
cameraBody->setGravity(btVector3(0,0,0));
|
cameraBody->setGravity(btVector3(0,0,0));
|
||||||
|
|
||||||
cameraBody->setSleepingThresholds(0,0); //very important, otherwise camera may go to sleep, aka not move until next collision
|
cameraBody->setSleepingThresholds(0,0); //very important, otherwise camera may go to sleep, aka not move until next collision
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -356,7 +351,7 @@ glm::vec3 Physics::getCameraPosition()
|
|||||||
return save;
|
return save;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 Physics::getCameraToPlayer()//returns a glm::vec3 the goes from the camera to the player
|
glm::vec3 Physics::getCameraToPlayer() //returns a glm::vec3 the goes from the camera to the player
|
||||||
{
|
{
|
||||||
btVector3 origin = playerBall->getCenterOfMassPosition() - cameraBody->getCenterOfMassPosition();
|
btVector3 origin = playerBall->getCenterOfMassPosition() - cameraBody->getCenterOfMassPosition();
|
||||||
glm::vec3 save(origin.getX(),origin.getY(),origin.getZ());
|
glm::vec3 save(origin.getX(),origin.getY(),origin.getZ());
|
||||||
@ -388,13 +383,12 @@ void Physics::updateCameraPos(glm::vec2 mouseMovement, float strength)
|
|||||||
btVector3 change = playerBall->getCenterOfMassPosition()-cameraBody->getCenterOfMassPosition();
|
btVector3 change = playerBall->getCenterOfMassPosition()-cameraBody->getCenterOfMassPosition();
|
||||||
change.setY(0);
|
change.setY(0);
|
||||||
change.normalize(); //normalize so that the distance between camera and body does not matter
|
change.normalize(); //normalize so that the distance between camera and body does not matter
|
||||||
change *= (mouseMovement.y);//we start with left/right movement because this needs to be calculated via a crossproduct, and the up down value would alter that
|
change *= (mouseMovement.y); //we start with left/right movement because this needs to be calculated via a crossproduct, and the up down value would alter that
|
||||||
change = btCross(btVector3(0,1,0),change);
|
change = btCross(btVector3(0,1,0),change);
|
||||||
change.setY(mouseMovement.x/5);//scaleing because otherwise oup/down much stronger then left right
|
change.setY(mouseMovement.x/5); //scaleing because otherwise oup/down much stronger then left right
|
||||||
change *= strength / cameraBody->getInvMass();
|
change *= strength / cameraBody->getInvMass();
|
||||||
|
|
||||||
cameraBody->applyCentralForce(change);
|
cameraBody->applyCentralForce(change);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//use the crossproduct to correctly apply a torque to the palyer if function called
|
//use the crossproduct to correctly apply a torque to the palyer if function called
|
||||||
@ -447,10 +441,10 @@ void Physics::addStaticGroundPlane()
|
|||||||
staticGroundBody = new btRigidBody(groundRigidBodyCI);
|
staticGroundBody = new btRigidBody(groundRigidBodyCI);
|
||||||
|
|
||||||
world->addRigidBody(staticGroundBody);
|
world->addRigidBody(staticGroundBody);
|
||||||
}//not needed anymoer, but still good for debugging
|
} //not needed anymoer, but still good for debugging
|
||||||
|
|
||||||
|
|
||||||
void Physics::kill()//delete dynamically allocated memory
|
void Physics::kill() //delete dynamically allocated memory
|
||||||
{
|
{
|
||||||
if (world == NULL) {
|
if (world == NULL) {
|
||||||
return;
|
return;
|
||||||
@ -465,7 +459,7 @@ void Physics::kill()//delete dynamically allocated memory
|
|||||||
delete motionState;
|
delete motionState;
|
||||||
delete bodies[i];
|
delete bodies[i];
|
||||||
}
|
}
|
||||||
btMotionState* motionState = terrainBody->getMotionState();//delete the rest that are not in the array bodies
|
btMotionState* motionState = terrainBody->getMotionState(); //delete the rest that are not in the array bodies
|
||||||
btCollisionShape* shape = terrainBody->getCollisionShape();
|
btCollisionShape* shape = terrainBody->getCollisionShape();
|
||||||
delete shape;
|
delete shape;
|
||||||
delete motionState;
|
delete motionState;
|
||||||
|
@ -81,7 +81,7 @@ class Physics {
|
|||||||
void addCamera(); //Do NOT impliment before Player has been created;
|
void addCamera(); //Do NOT impliment before Player has been created;
|
||||||
|
|
||||||
btDynamicsWorld* world = NULL; //contains physical attributes of the world.
|
btDynamicsWorld* world = NULL; //contains physical attributes of the world.
|
||||||
btDispatcher* dispatcher; //
|
btDispatcher* dispatcher;
|
||||||
btCollisionConfiguration* colConfig; //defines the type of collision detection.
|
btCollisionConfiguration* colConfig; //defines the type of collision detection.
|
||||||
btBroadphaseInterface* broadphase; //defines how objects are culled from collision detection.
|
btBroadphaseInterface* broadphase; //defines how objects are culled from collision detection.
|
||||||
btConstraintSolver* solver; //solver for forces and impulses.
|
btConstraintSolver* solver; //solver for forces and impulses.
|
||||||
|
@ -27,7 +27,6 @@ void Terrain::load() {
|
|||||||
}
|
}
|
||||||
this->makeTriangleMesh();
|
this->makeTriangleMesh();
|
||||||
heightmapChanged = false; //no need to make a TriangleMesh again before rendering
|
heightmapChanged = false; //no need to make a TriangleMesh again before rendering
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terrain::makeTriangleMesh(){
|
void Terrain::makeTriangleMesh(){
|
||||||
|
Loading…
Reference in New Issue
Block a user