Moved loading of the terrain to the loader, now also reading parameters for it from xml.
This commit is contained in:
parent
5c2491557b
commit
320c1cb152
15
level.cc
15
level.cc
@ -45,22 +45,7 @@ void Level::load() {
|
|||||||
this->physics = Physics();
|
this->physics = Physics();
|
||||||
this->physics.init();
|
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);
|
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,
|
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
||||||
|
22
loader.cc
22
loader.cc
@ -21,6 +21,28 @@ void Loader::load(std::string filePath, Level* level) {
|
|||||||
errorCheck(physicsElement->FirstChildElement("friction")->QueryFloatText(&friction));
|
errorCheck(physicsElement->FirstChildElement("friction")->QueryFloatText(&friction));
|
||||||
level->setStrength(strength);
|
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
|
//load the skydome
|
||||||
XMLElement* skydomeElement = doc->FirstChildElement("skydome");
|
XMLElement* skydomeElement = doc->FirstChildElement("skydome");
|
||||||
const char* charSkydomeTexture = skydomeElement->FirstChildElement("texture")->GetText();
|
const char* charSkydomeTexture = skydomeElement->FirstChildElement("texture")->GetText();
|
||||||
|
Loading…
Reference in New Issue
Block a user