From 704df860f870b86338250861902f80211f0bd906 Mon Sep 17 00:00:00 2001 From: Jasper Date: Fri, 21 Nov 2014 16:22:36 +0100 Subject: [PATCH] Put Box In Level --- level.cc | 29 ++++++++++++++++------------- physics.cc | 13 +++++++------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/level.cc b/level.cc index 82bd5b6..5327b8f 100644 --- a/level.cc +++ b/level.cc @@ -21,24 +21,20 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) { // currently hard coded should later read this stuff out of a file this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f); - // load the geometry of the stanford bunny and build a VAO: + + //add player Model model = Model("MarbleSmooth.obj", 0.75f); - // load a texture: Material material = Material("marbleTexture_small.png", 0.1f, 0.5f, 0.5f, 3.0f); - //Create object Object object = Object(model, material, glm::vec3(0.0f, 10.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), shader); - //add player to phy - this->physics.addPlayer(1.25f,object,1.0f,0); - objects.push_back(object); - + objects.push_back(object); + this->physics.addPlayer(1.25f,object,8.0f,1); + Model skyboxModel = Model("skybox.obj", skyboxSize); Material skyboxMaterial = Material("skybox.png", 0.7f, 0.0f, 0.0f, 0.0f); Object skyboxObject = Object(skyboxModel, skyboxMaterial, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), shader); objects.push_back(skyboxObject); - - //physics.addStaticGroundPlane(); Model torchModel = Model("torch.obj", 0.75f); Material torchMaterial = Material("torchTexture.png", 0.1f, 0.3f, 0.7f, 10.0f); @@ -52,6 +48,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) { Object blockObject = Object(blockModel, blockMaterial, glm::vec3(2.0f, 7.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), shader); objects.push_back(blockObject); + physics.addBox(1,1,1,blockObject,0,2); Model columnModel = Model("Column.obj", 1.0f); Material columnMaterial = Material("columnTexture_small.png", 0.1f, 0.6, 0.4f, 2.0f); @@ -59,6 +56,9 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) { glm::vec3(0.0f, 0.0f, 0.0f), shader); objects.push_back(columnObject); + //make non physics objects + + //set lighting parameters ambientLight = glm::vec3(1.0f, 1.0f, 1.0f); fogColor = glm::vec4(0.10f, 0.14f, 0.14f, 1.0f); @@ -104,23 +104,26 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre camera.updateRotation(mouseDelta/100.0f); } + float str = 20; + if(wPressed){ - physics.rollForward(camera.getVector(),1.0f); + physics.rollForward(camera.getVector(),str); } if(aPressed) { - physics.rollLeft(camera.getVector(),1.0f); + physics.rollLeft(camera.getVector(),str); } if(sPressed) { - physics.rollBack(camera.getVector(),1.0f); + physics.rollBack(camera.getVector(),str); } if(dPressed){ - physics.rollRight(camera.getVector(),1.0f); + physics.rollRight(camera.getVector(),str); } physics.takeUpdateStep(runTime); objects[0].setPosition(physics.getPos(0)); objects[0].setRotation(physics.getRotation(0)); + skybox->setPosition(glm::vec3(cameraCenter->getPosition().x, 0.0f, cameraCenter->getPosition().z)); } diff --git a/physics.cc b/physics.cc index 74429e9..b358098 100644 --- a/physics.cc +++ b/physics.cc @@ -77,7 +77,7 @@ void Physics::addStaticGroundPlane() void Physics::addPlayer(float rad, Entity entity, float mass, unsigned indice) { - if(bodies.size() != indice) + if(bodies.size() == indice) throw std::invalid_argument( "Bodies out of Sync" ); btSphereShape* sphere = new btSphereShape(rad); @@ -100,16 +100,17 @@ void Physics::addPlayer(float rad, Entity entity, float mass, unsigned indice) bodies.push_back(playerBall); playerBall->setSleepingThresholds(0,0); - if(bodies.size() == indice) + if(bodies.size() != indice) throw std::invalid_argument( "Bodies out of Sync" ); } void Physics::addBox(float width, float height, float length, Entity entity, float mass, unsigned indice) { - if(bodies.size() != indice) - throw std::invalid_argument( "Bodies out of Sync" ); + if(bodies.size() == indice) + throw std::invalid_argument( "Bodies out of Sync" ); + btBoxShape* box = new btBoxShape(btVector3(width/2,height/2,length/2)); btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(entity.getPosition().x,entity.getPosition().y,entity.getPosition().z))); @@ -140,7 +141,7 @@ void Physics::addBox(float width, float height, float length, Entity entity, flo void Physics::addSphere(float rad, Entity entity, float mass, unsigned indice) { - if(bodies.size() != indice) + if(bodies.size() == indice) throw std::invalid_argument( "Bodies out of Sync" ); btSphereShape* sphere = new btSphereShape(rad); @@ -165,7 +166,7 @@ void Physics::addSphere(float rad, Entity entity, float mass, unsigned indice) body->setSleepingThresholds(0,0); - if(bodies.size() == indice) + if(bodies.size() != indice) throw std::invalid_argument( "Bodies out of Sync" ); }