From 9764bc9d0ba9f23e4f0591c13b101af1a76cfdb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Fri, 12 Dec 2014 15:41:17 +0100 Subject: [PATCH] Changed fogColor to fogColour. Moved some global Parameters to the xml. --- converter/converter.cc | 54 ++++++++++++++++++++++++++++++++++++++++ graphics.cc | 2 +- level.cc | 56 +++++++++++++++++++++++++----------------- level.hh | 4 +-- 4 files changed, 91 insertions(+), 25 deletions(-) diff --git a/converter/converter.cc b/converter/converter.cc index 2323573..0394a73 100644 --- a/converter/converter.cc +++ b/converter/converter.cc @@ -39,7 +39,61 @@ Converter::Converter(std::string level){ doc->LoadFile(charXmlFile); if (doc->ErrorID()!=0){ printf("Could not open xml, creating new xml.\n"); + std::vector lightAttributes; + lightAttributes.push_back(doc->NewElement("xOffset")); + lightAttributes.push_back(doc->NewElement("yOffset")); + lightAttributes.push_back(doc->NewElement("zOffset")); + lightAttributes.push_back(doc->NewElement("rColour")); + lightAttributes.push_back(doc->NewElement("gColour")); + lightAttributes.push_back(doc->NewElement("bColour")); + lightAttributes.push_back(doc->NewElement("intensity")); + XMLElement* rColourAmbient = doc->NewElement("rColour"); + XMLElement* gColourAmbient = doc->NewElement("gColour"); + XMLElement* bColourAmbient = doc->NewElement("bColour"); + XMLElement* rColourFog = doc->NewElement("rColour"); + XMLElement* gColourFog = doc->NewElement("gColour"); + XMLElement* bColourFog = doc->NewElement("bColour"); + XMLElement* alphaFog = doc->NewElement("alpha"); + lightAttributes[0]->SetText("-1.0"); + lightAttributes[1]->SetText("1.5"); + lightAttributes[2]->SetText("1.0"); + lightAttributes[3]->SetText("1.0"); + lightAttributes[4]->SetText("1.0"); + lightAttributes[5]->SetText("0.9"); + lightAttributes[6]->SetText("0.2"); + rColourAmbient->SetText("1.0"); + gColourAmbient->SetText("1.0"); + bColourAmbient->SetText("1.0"); + rColourFog->SetText("0.10"); + gColourFog->SetText("0.14"); + bColourFog->SetText("0.14"); + alphaFog->SetText("1.0"); + + XMLElement* ambientLight = doc->NewElement("ambientLight"); + XMLElement* fogColour = doc->NewElement("fogColour"); + XMLElement* directionalLight = doc->NewElement("directionalLight"); + + ambientLight->InsertEndChild(rColourAmbient); + ambientLight->InsertEndChild(gColourAmbient); + ambientLight->InsertEndChild(bColourAmbient); + fogColour->InsertEndChild(rColourFog); + fogColour->InsertEndChild(gColourFog); + fogColour->InsertEndChild(bColourFog); + fogColour->InsertEndChild(alphaFog); + for(int i=0;i<7;i++){ + directionalLight->InsertEndChild(lightAttributes[i]); + } + + XMLElement* skydome = doc->NewElement("skydome"); + XMLElement* skydomeTexture = doc->NewElement("texture"); + skydomeTexture->SetText("skydome.png"); + skydome->InsertEndChild(skydomeTexture); + + doc->InsertEndChild(ambientLight); + doc->InsertEndChild(fogColour); + doc->InsertEndChild(directionalLight); + doc->InsertEndChild(skydome); }else{ XMLElement* thisComposition = doc->FirstChildElement("composition"); int idGreen, idBlue; diff --git a/graphics.cc b/graphics.cc index 28dc144..ce4b94e 100644 --- a/graphics.cc +++ b/graphics.cc @@ -180,7 +180,7 @@ void Graphics::render(Level* level) // set fog Parameters lightingShader->setUniform("fogEnd", (farPlane)-35.0f); - lightingShader->setUniform("fogColor", level->getFogColor()); + lightingShader->setUniform("fogColor", level->getFogColour()); lightingShader->setUniform("cameraCenter", level->getCameraCenter()->getPosition()); // set Material Parameters diff --git a/level.cc b/level.cc index fa0d9b3..89315d4 100644 --- a/level.cc +++ b/level.cc @@ -60,7 +60,7 @@ void Level::load() { //addTerrainPhysic physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap()); - //Loading Objects via xml + //Loading from xml: XMLDocument* doc = new XMLDocument(); const char* xmlFile = ("../Levels/ObjectSetups/Level" + levelNum + ".xml").c_str(); doc->LoadFile(xmlFile); @@ -68,6 +68,36 @@ void Level::load() { printf("Could not open ObjectSetupXml!\n"); exit(-1); } + //load the skydome + XMLElement* skydomeElement = doc->FirstChildElement("skydome"); + const char* charSkydomeTexture = skydomeElement->FirstChildElement("texture")->GetText(); + if(charSkydomeTexture == NULL){ + printf("XMLError: No skydomeTexture found.\n"); + } + std::string skydomeTexture = charSkydomeTexture; + Model skydomeModel = Model("skydome.obj", skydomeSize); + Material skydomeMaterial = Material(skydomeTexture, 0.7f, 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)); + objects.push_back(skydomeObject); + skydome = skydomeObject; + //load lighting parameters + float rColour, gColour, bColour, alpha, xOffset, yOffset, zOffset; + XMLElement* ambientElement = doc->FirstChildElement("ambientLight"); + errorCheck(ambientElement->FirstChildElement("rColour")->QueryFloatText(&rColour)); + errorCheck(ambientElement->FirstChildElement("gColour")->QueryFloatText(&gColour)); + errorCheck(ambientElement->FirstChildElement("bColour")->QueryFloatText(&bColour)); + ambientLight = glm::vec3(rColour,gColour,bColour); + XMLElement* fogElement = doc->FirstChildElement("ambientLight"); + errorCheck(fogElement->FirstChildElement("rColour")->QueryFloatText(&rColour)); + errorCheck(fogElement->FirstChildElement("gColour")->QueryFloatText(&gColour)); + errorCheck(fogElement->FirstChildElement("bColour")->QueryFloatText(&bColour)); + errorCheck(fogElement->FirstChildElement("alpha")->QueryFloatText(&alpha)); + fogColour = glm::vec4(rColour,gColour,bColour, alpha); + directionalLight = Light(glm::vec3(-1.0f, 1.5f, 1.0f), glm::vec3(1.0f, 1.0f, 0.9f), 0.2f); + + + //load Objects XMLDocument* compositions = new XMLDocument(); const char* compositionsFile = "../Levels/ObjectSetups/Compositions.xml"; compositions->LoadFile(compositionsFile); @@ -192,13 +222,6 @@ void Level::load() { physicObjects.push_back(object); this->physics.addPlayer(1.25f,*object,8.0f,physicObjects.size()); cameraCenter = object; - - Model skydomeModel = Model("skydome.obj", skydomeSize); - Material skydomeMaterial = Material("skydome.png", 0.7f, 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)); - objects.push_back(skydomeObject); - skydome = skydomeObject; Model torchModel = Model("torch.obj", 0.75f); Material torchMaterial = Material("torchTexture.png", 0.1f, 0.3f, 0.7f, 10.0f); @@ -227,18 +250,7 @@ void Level::load() { glm::vec3(0.0f, 0.0f, 0.0f)); 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); - directionalLight = Light(glm::vec3(-1.0f, 1.5f, 1.0f), glm::vec3(1.0f, 1.0f, 0.9f), 0.2f); - Light light = Light(glm::vec3(-3.0f, 7.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 5.0f); - //lights.push_back(light); - Light light2 = Light(glm::vec3(3.0f, 7.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 10.0f); - //lights.push_back(light2); - + } @@ -313,8 +325,8 @@ Light* Level::getDirectionalLight() { return &directionalLight; } -glm::vec4 Level::getFogColor() { - return fogColor; +glm::vec4 Level::getFogColour() { + return fogColour; } glm::vec3 Level::getCameraPosition() { diff --git a/level.hh b/level.hh index 3c08e77..dfe7a28 100644 --- a/level.hh +++ b/level.hh @@ -25,7 +25,7 @@ class Level { Object* getCameraCenter(); Camera* getCamera(); glm::vec3 getCameraPosition(); - glm::vec4 getFogColor(); + glm::vec4 getFogColour(); void setSkydomeSize(float size); private: void errorCheck(tinyxml2::XMLError error); @@ -34,7 +34,7 @@ class Level { std::vector physicObjects; std::vector lights; glm::vec3 ambientLight; - glm::vec4 fogColor; + glm::vec4 fogColour; Light directionalLight; Object* cameraCenter; Object* skydome;