From bedf58b27ab56846f153f48f1a71d4f39d5e3034 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sun, 23 Nov 2014 00:59:54 +0100 Subject: [PATCH] Changing vector of objects to vector of pointer of objects for clearer construnction. --- level.cc | 30 +++++++++++++++--------------- level.hh | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/level.cc b/level.cc index cf273cc..d24359e 100644 --- a/level.cc +++ b/level.cc @@ -12,6 +12,9 @@ Level::Level() { } Level::~Level() { + for(unsigned int i = 0; iphysics.addPlayer(1.25f,object,8.0f,1); + this->physics.addPlayer(1.25f,*object,8.0f,1); + cameraCenter = object; Model skydomeModel = Model("skydome.obj", skydomeSize); Material skydomeMaterial = Material("skydome.png", 0.7f, 0.0f, 0.0f, 0.0f); - Object skydomeObject = Object(skydomeModel, skydomeMaterial, glm::vec3(0.0f, 0.0f, 0.0f), + Object* skydomeObject = new Object(skydomeModel, skydomeMaterial, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), shader); objects.push_back(skydomeObject); skydome = skydomeObject; @@ -40,20 +44,20 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) { Model torchModel = Model("torch.obj", 0.75f); Material torchMaterial = Material("torchTexture.png", 0.1f, 0.3f, 0.7f, 10.0f); //Create object - Object torchObject = Object(torchModel, torchMaterial, glm::vec3(-3.0f, 6.0f, 0.0f), + Object* torchObject = new Object(torchModel, torchMaterial, glm::vec3(-3.0f, 6.0f, 0.0f), glm::vec3(0.0f, 1.0472f, 0.0f), shader); objects.push_back(torchObject); Model blockModel = Model("Block.obj", 1.0f); Material blockMaterial = Material("blockTexture_small.png", 0.1f, 0.6, 0.4f, 2.0f); - Object blockObject = Object(blockModel, blockMaterial, glm::vec3(2.0f, 7.0f, 2.0f), + Object* blockObject = new 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); + 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); - Object columnObject = Object(columnModel, columnMaterial, glm::vec3(-2.0f, 7.0f, -2.0f), + Object* columnObject = new Object(columnModel, columnMaterial, glm::vec3(-2.0f, 7.0f, -2.0f), glm::vec3(0.0f, 0.0f, 0.0f), shader); objects.push_back(columnObject); @@ -75,12 +79,10 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) { // load a texture: Material terrainMaterial = Material("seamlessTerrain.png", 0.1f, 0.8f, 0.2f, 3.0f); //Create object - Object terrainObject = Object(terrainModel, terrainMaterial, + Object* terrainObject = new Object(terrainModel, terrainMaterial, glm::vec3(-0.5f*(float)this->terrain.getHeightmapHeight(), 0.0f, -0.5f*(float)this->terrain.getHeightmapWidth()), glm::vec3(0.0f, 0.0f, 0.0f), shader); objects.push_back(terrainObject); - cameraCenter = &objects[0]; - skybox = &objects[1]; //addTerrainPhysic physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap()); @@ -88,13 +90,11 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) { void Level::render() { for(unsigned int i = 0; irender(); } } void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPressed, bool sPressed, bool dPressed) { - // rotate bunny - //cameraCenter->setRotation(glm::vec3(0.0f, 1.0472f * runTime, 0.0f)); // Ignore first two mouse updates, because they are incorrect static int i = 0; if (i <2) { @@ -122,8 +122,8 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre physics.takeUpdateStep(runTime); - objects[0].setPosition(physics.getPos(0)); - objects[0].setRotation(physics.getRotation(0)); + cameraCenter->setPosition(physics.getPos(0)); + cameraCenter->setRotation(physics.getRotation(0)); skydome->setPosition(glm::vec3(cameraCenter->getPosition().x, 0.0f, cameraCenter->getPosition().z)); diff --git a/level.hh b/level.hh index 6aff398..920be96 100644 --- a/level.hh +++ b/level.hh @@ -28,7 +28,7 @@ class Level { void setSkydomeSize(float size); private: std::string filePath; - std::vector objects; + std::vector objects; std::vector lights; glm::vec3 ambientLight; glm::vec4 fogColor;