Changed fogColor to fogColour. Moved some global Parameters to the xml.

This commit is contained in:
Steffen Fündgens 2014-12-12 15:41:17 +01:00
parent 7cb146dbbb
commit a1981ecbca
4 changed files with 91 additions and 25 deletions

View File

@ -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<XMLElement*> 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;

View File

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

View File

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

View File

@ -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<Object*> physicObjects;
std::vector<Light> lights;
glm::vec3 ambientLight;
glm::vec4 fogColor;
glm::vec4 fogColour;
Light directionalLight;
Object* cameraCenter;
Object* skydome;