diff --git a/level.cc b/level.cc index 45497cc..dc2f808 100644 --- a/level.cc +++ b/level.cc @@ -28,10 +28,11 @@ void Level::load() { //add player Model model = Model("MarbleSmooth.obj", 0.75f); Material material = Material("marbleTexture_small.png", 0.1f, 0.5f, 0.5f, 3.0f); - Object* object = new Object(model, material, glm::vec3(0.0f, 10.0f, 0.0f), + Object* object = new Object(model, material, glm::vec3(2.0f, 10.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f)); objects.push_back(object); - this->physics.addPlayer(1.25f,*object,8.0f,1); + physicObjects.push_back(object); + this->physics.addPlayer(1.25f,*object,8.0f,physicObjects.size()); cameraCenter = object; Model skydomeModel = Model("skydome.obj", skydomeSize); @@ -50,10 +51,17 @@ void Level::load() { Model blockModel = Model("Block.obj", 1.0f); Material blockMaterial = Material("blockTexture_small.png", 0.1f, 0.6, 0.4f, 2.0f); - Object* blockObject = new Object(blockModel, blockMaterial, glm::vec3(2.0f, 7.0f, 2.0f), + Object* blockObject = new Object(blockModel, blockMaterial, glm::vec3(0.0f, 10.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f)); objects.push_back(blockObject); - physics.addBox(1,1,1,*blockObject,0,2); + physicObjects.push_back(blockObject); + physics.addBox(1,3.0f,1,*blockObject,2,physicObjects.size()); + + Object* blockObject2 = new Object(blockModel, blockMaterial, glm::vec3(5.0f, 10.0f, 5.0f), + glm::vec3(0.0f, 0.0f, 0.0f)); + objects.push_back(blockObject2); + physicObjects.push_back(blockObject2); + physics.addBox(1,3.0f,1,*blockObject2,2,physicObjects.size()); Model columnModel = Model("Column.obj", 1.0f); Material columnMaterial = Material("columnTexture_small.png", 0.1f, 0.6, 0.4f, 2.0f); @@ -126,6 +134,12 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre cameraCenter->setPosition(physics.getPos(0)); cameraCenter->setRotation(physics.getRotation(0)); + for(unsigned i = 0; i < physicObjects.size();i++) + { + physicObjects[i]->setPosition(physics.getPos(i)); + physicObjects[i]->setRotation(physics.getRotation(i)); + } + skydome->setPosition(glm::vec3(cameraCenter->getPosition().x, 0.0f, cameraCenter->getPosition().z)); } diff --git a/level.hh b/level.hh index 7a7f6a6..89d1bfb 100644 --- a/level.hh +++ b/level.hh @@ -29,6 +29,7 @@ class Level { private: std::string filePath; std::vector objects; + std::vector physicObjects; std::vector lights; glm::vec3 ambientLight; glm::vec4 fogColor; diff --git a/physics.hh b/physics.hh index 24f5afb..a9cca30 100644 --- a/physics.hh +++ b/physics.hh @@ -38,23 +38,22 @@ class Physics { Physics(); ~Physics(); void init(); - void takeUpdateStep(float timeDiff); - void rollForward(glm::vec3 camPos, float strength); + void takeUpdateStep(float timeDiff); //must be used in level.update to proagate the physics + void rollForward(glm::vec3 camPos, float strength); //self explainitory void rollLeft(glm::vec3 camPos, float strength); void rollRight(glm::vec3 camPos, float strength); void rollBack(glm::vec3 camPos, float strength); glm::vec3 getPos(int i); glm::mat4 getRotation(int i); - void rollForward(glm::vec3 camPos); void addStaticGroundPlane(); void addTerrain(int width, int length, float** heightData); - void addPlayer(float rad, Entity entity, float mass, unsigned indice); - void addSphere(float rad, Entity entity, float mass, unsigned indice); - void addBox(float width, float height, float length, Entity entity, float mass, unsigned indice); + void addPlayer(float rad, Entity entity, float mass, unsigned indice); //use these AFTER physicObjects.push_back(object)! if mass == 0 then the object is unmoveable + void addSphere(float rad, Entity entity, float mass, unsigned indice); //The Indice should be set to physicObjects.size() + void addBox(float width, float height, float length, Entity entity, float mass, unsigned indice); //this is used to ensuer that the system is synchronized private: - btRigidBody* playerBall; - btRigidBody* terrainBody; + btRigidBody* playerBall; //allows for quicker access to the ball + btRigidBody* terrainBody; //duh std::vector bodies; //list of all bodies. bodies are also in world, but save again to ease cleaning up process. btRigidBody* staticGroundBody;