From df7c5ffe3dcfc5439255b0e961d552a48a1ba149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Fri, 6 Feb 2015 12:51:53 +0100 Subject: [PATCH] Moved loading of the terrain to the loader, now also reading parameters for it from xml. --- level.cc | 15 --------------- loader.cc | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/level.cc b/level.cc index 7c8328b..0f9ef84 100644 --- a/level.cc +++ b/level.cc @@ -45,22 +45,7 @@ void Level::load() { this->physics = Physics(); this->physics.init(); - // currently hard coded should later read this stuff out of a file this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f); - - // load terrain - this->terrain.load(); - Model terrainModel = Model(this->terrain.getModel()); - // load a texture: - Material terrainMaterial = Material("seamlessTerrain.png", 0.1f, 0.8f, 0.2f, 3.0f); - //Create object - Object* terrainObject = new Object(terrainModel, terrainMaterial, - glm::vec3(-0.5*(float)this->terrain.getHeightmapHeight(), 0.0f, -0.5f*(float)this->terrain.getHeightmapWidth()), - glm::vec3(0.0f, 0.0f, 0.0f)); - objects.push_back(terrainObject); - - //addTerrainPhysic - physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap()); } void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, diff --git a/loader.cc b/loader.cc index 6d6897f..061c9f2 100644 --- a/loader.cc +++ b/loader.cc @@ -21,6 +21,28 @@ void Loader::load(std::string filePath, Level* level) { errorCheck(physicsElement->FirstChildElement("friction")->QueryFloatText(&friction)); level->setStrength(strength); + // load the terrain + level->getTerrain()->load(); + Model terrainModel = Model(level->getTerrain()->getModel()); + XMLElement* terrainElement = doc->FirstChildElement("terrain"); + const char* charTerrainTexture = terrainElement->FirstChildElement("texture")->GetText(); + if(charTerrainTexture == NULL){ + printf("XMLError: No terrainTexture found.\n"); + exit(-1); + } + std::string terrainTexture = charTerrainTexture; + float terrainAmbientFactor, terrainDiffuseFactor, terrainSpecularFactor, terrainShininess; + errorCheck(terrainElement->FirstChildElement("ambientFactor")->QueryFloatText(&terrainAmbientFactor)); + errorCheck(terrainElement->FirstChildElement("diffuseFactor")->QueryFloatText(&terrainDiffuseFactor)); + errorCheck(terrainElement->FirstChildElement("specularFactor")->QueryFloatText(&terrainSpecularFactor)); + errorCheck(terrainElement->FirstChildElement("shininess")->QueryFloatText(&terrainShininess)); + Material terrainMaterial = Material(terrainTexture, terrainAmbientFactor, terrainDiffuseFactor, terrainSpecularFactor, terrainShininess); + Object* terrainObject = new Object(terrainModel, terrainMaterial, + glm::vec3(-0.5*(float)level->getTerrain()->getHeightmapHeight(), 0.0f, -0.5f*(float)level->getTerrain()->getHeightmapWidth()), + glm::vec3(0.0f, 0.0f, 0.0f)); + level->addObject(terrainObject); + level->getPhysics()->addTerrain(level->getTerrain()->getHeightmapWidth(), level->getTerrain()->getHeightmapHeight(), level->getTerrain()->getHeightmap()); + //load the skydome XMLElement* skydomeElement = doc->FirstChildElement("skydome"); const char* charSkydomeTexture = skydomeElement->FirstChildElement("texture")->GetText();