Moved loading of the terrain to the loader, now also reading parameters for it from xml.

This commit is contained in:
Steffen Fündgens 2015-02-06 12:51:53 +01:00
parent 5c2491557b
commit 320c1cb152
2 changed files with 22 additions and 15 deletions

View File

@ -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,

View File

@ -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();