From f3cbfe6133d0cd1ece2688aa7feac11ca43bc11b Mon Sep 17 00:00:00 2001 From: Faerbit Date: Wed, 4 Mar 2015 21:28:46 +0100 Subject: [PATCH] Gave the skydome it's own class which contains the nightTexture and changed the loader and the level XML. --- data/levels/Level1.xml | 1 + level.cc | 8 ++++---- level.hh | 7 ++++--- loader.cc | 12 +++++++++--- skydome.cc | 13 +++++++++++++ skydome.hh | 11 +++++++++++ 6 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 skydome.cc create mode 100644 skydome.hh diff --git a/data/levels/Level1.xml b/data/levels/Level1.xml index 019539a..2192918 100644 --- a/data/levels/Level1.xml +++ b/data/levels/Level1.xml @@ -12117,6 +12117,7 @@ skydome.obj skydomeNew.png + nightskydome.png diff --git a/level.cc b/level.cc index cb34369..edd58a2 100644 --- a/level.cc +++ b/level.cc @@ -115,7 +115,7 @@ void Level::update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseD physicsObjects[i]->setRotation(physics.getRotation(i)); } - skydome->setPosition(glm::vec3(cameraCenter->getPosition().x, + skydome.setPosition(glm::vec3(cameraCenter->getPosition().x, 0.0f, cameraCenter->getPosition().z)); if (runTime > 2.0f) { @@ -205,7 +205,7 @@ void Level::setStrength(float strength) { this->strength = strength; } -void Level::setSkydomeObject(Object* object){ +void Level::setSkydomeObject(Skydome object){ this->skydome = object; } @@ -261,6 +261,6 @@ Terrain* Level::getTerrain() { return &terrain; } -Object* Level::getSkydome() { - return skydome; +Skydome* Level::getSkydome() { + return &skydome; } diff --git a/level.hh b/level.hh index 43e9157..197c6e6 100644 --- a/level.hh +++ b/level.hh @@ -10,6 +10,7 @@ #include "camera.hh" #include "physics.hh" #include "trigger.hh" +#include "skydome.hh" extern "C" { #include "extern/lua/src/lua.h" @@ -36,13 +37,13 @@ class Level { glm::vec4 getFogColour(); void setSkydomeSize(float size); float getSkydomeSize(); - Object* getSkydome(); + Skydome* getSkydome(); std::vector* getObjects(); std::vector* getPhysicsObjects(); void deleteObject(int objectIndex); void moveObject(int objectIndex, float strength, float xPos, float yPos, float zPos); void setStrength(float strength); - void setSkydomeObject(Object* object); + void setSkydomeObject(Skydome object); void addObject(Object* object); void addPhysicsObject(Object* object); void setAmbientLight(glm::vec3 colour); @@ -70,7 +71,7 @@ class Level { Light directionalLight; Object* cameraCenter; int playerIndex; - Object* skydome; + Skydome skydome; Physics physics; Camera camera; Terrain terrain; diff --git a/loader.cc b/loader.cc index 9fb62cf..25e5728 100644 --- a/loader.cc +++ b/loader.cc @@ -70,7 +70,6 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa //load the skydome XMLElement* skydomeElement = doc->FirstChildElement("skydome"); - std::string skydomeTexture = queryString(skydomeElement, "texture"); std::string skydomeModelFileName = queryString(skydomeElement, "model"); std::string skydomePath = "../" + globalGeometryPath + skydomeModelFileName; if(stat(skydomePath.c_str(), &buf) != 0){ @@ -78,14 +77,21 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa exit(-1); } Model skydomeModel = Model(skydomeModelFileName, level->getSkydomeSize()); + std::string skydomeTexture = queryString(skydomeElement, "texture"); std::string skydomeTexturePath = "../" + globalTexturePath + skydomeTexture; if(stat(skydomeTexturePath.c_str(), &buf) != 0){ std::cout << "The texture file " << skydomeTexturePath << " does not exist." << std::endl; exit(-1); } Material skydomeMaterial = Material(skydomeTexture, 1.0f, 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), true); + std::string nightTexture = queryString(skydomeElement, "nightTexture"); + std::string nightTexturePath = "../" + globalTexturePath + nightTexture; + if(stat(nightTexturePath.c_str(), &buf) != 0){ + std::cout << "The texture file " << nightTexturePath << " does not exist." << std::endl; + exit(-1); + } + Material nightMaterial = Material(nightTexture, 1.0f, 0.0f, 0.0f, 0.0f); + Skydome skydomeObject = Skydome(skydomeModel, skydomeMaterial, nightMaterial); level->setSkydomeObject(skydomeObject); //load lighting parameters diff --git a/skydome.cc b/skydome.cc new file mode 100644 index 0000000..b1fc220 --- /dev/null +++ b/skydome.cc @@ -0,0 +1,13 @@ +#include "skydome.hh" + +Skydome::Skydome(Model model, Material material, Material nightTexture) : + Object(model, material, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), true){ + this->nightTexture = nightTexture; +} + +Skydome::Skydome() { +} + +Material* Skydome::getNightTexture() { + return &nightTexture; +} diff --git a/skydome.hh b/skydome.hh new file mode 100644 index 0000000..3cd82b2 --- /dev/null +++ b/skydome.hh @@ -0,0 +1,11 @@ +#pragma once +#include "object.hh" + +class Skydome : public Object { + public: + Skydome(Model model, Material material, Material nightTexture); + Skydome(); + Material* getNightTexture(); + private: + Material nightTexture; +};