From 2790bddd114242fbdc7543ed8d25d15d7f24407a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Mon, 8 Dec 2014 15:19:50 +0100 Subject: [PATCH] Added loading of lights, adjusted Compositions.xml and Level0.png to test it. --- Levels/ObjectSetups/Compositions.xml | 8 +-- Levels/ObjectSetups/Level0.png | Bin 146 -> 117 bytes Levels/ObjectSetups/Level0.xml | 70 --------------------------- level.cc | 57 +++++++++++++++++++--- 4 files changed, 53 insertions(+), 82 deletions(-) diff --git a/Levels/ObjectSetups/Compositions.xml b/Levels/ObjectSetups/Compositions.xml index bab4b2e..c5f1ef9 100644 --- a/Levels/ObjectSetups/Compositions.xml +++ b/Levels/ObjectSetups/Compositions.xml @@ -32,7 +32,7 @@ - 80 + 99 torch.obj 0.0 @@ -42,17 +42,17 @@ 0.0 - 1.0 + 3 0.0 1.0 1.0 1.0 - 5.0 + 4.0 - 99 + 100 column.obj 0.0 diff --git a/Levels/ObjectSetups/Level0.png b/Levels/ObjectSetups/Level0.png index 05eaad6501129948e8a28620b703e4e2c3af3ff3..0d36b6d3a02fc77e05c7c685e6a2b25241552e62 100644 GIT binary patch delta 87 zcmbQlSUN!^kUzjD#P$FG|H+KZ$&75tj2y{~oSQ6mSTZm$D0;d$hEy^>bP0l+XkKgp?XP delta 116 zcmV-)0E_>1k^zt;ZXQrfR7GO}0ssI1V*vtV0Rv+J1Y-dOV*v(Z0S99N2x9>WLBH(1 z0000lNklnW1} diff --git a/Levels/ObjectSetups/Level0.xml b/Levels/ObjectSetups/Level0.xml index 20a74a6..9f032f5 100644 --- a/Levels/ObjectSetups/Level0.xml +++ b/Levels/ObjectSetups/Level0.xml @@ -26,20 +26,6 @@ 99 - - 1.0 - 0.0 - 0.0 - 0.0 - false - 2.500000 - 0.0 - -2.500000 - 1 - 7 - 99 - - 1.0 0.0 @@ -54,34 +40,6 @@ 99 - - 1.0 - 0.0 - 0.0 - 0.0 - false - -0.500000 - 0.0 - 1.500000 - 1 - 5 - 99 - - - - 1.0 - 0.0 - 0.0 - 0.0 - false - -0.500000 - 0.0 - -1.500000 - 1 - 4 - 99 - - 1.0 0.0 @@ -95,31 +53,3 @@ 3 99 - - - 1.0 - 0.0 - 0.0 - 0.0 - false - -3.500000 - 0.0 - -3.500000 - 1 - 2 - 99 - - - - 1.0 - 0.0 - 0.0 - 0.0 - false - -4.500000 - 0.0 - -4.500000 - 1 - 1 - 99 - diff --git a/level.cc b/level.cc index 2494e2b..6bbb16e 100644 --- a/level.cc +++ b/level.cc @@ -100,8 +100,8 @@ void Level::load() { errorCheck(error); error = thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale); errorCheck(error); - //Model model = Model(modelPath, objectScale * compScale); - //Material material; + Model model = Model(modelPath, objectScale * compScale); + Material material; XMLElement* objectData = compositions->FirstChildElement("objectData"); for(; objectData; objectData=objectData->NextSiblingElement("objectData")){ const char* charDataModelPath = objectData->FirstChildElement("modelPath")->GetText(); @@ -124,7 +124,7 @@ void Level::load() { printf("XMLError: No texturePath found in objectData.\n"); } std::string texturePath = charTexturePath; - //material = Material(texturePath, ambientFactor, diffuseFactor, specularFactor, shininess); + material = Material(texturePath, ambientFactor, diffuseFactor, specularFactor, shininess); } } float compXPos, compYOffset, compZPos; @@ -157,8 +157,8 @@ void Level::load() { * glm::rotate(compRot.z, glm::vec3(0.0f, 0.0f, 1.0f)) * glm::vec4(objectOffset, 0); glm::vec3 objectPosition = compPos + glm::vec3(rotatedObjectOffset.x,rotatedObjectOffset.y,rotatedObjectOffset.z); - //Object* object = new Object(model, material, objectPosition, compRot); - //objects.push_back(object); + Object* object = new Object(model, material, objectPosition, compRot); + objects.push_back(object); //TODO if object has physics: physicObjects.push_back(object); //should not all objects have physics in the end? //TODO add object to physics //if(compositionType == 20){ @@ -168,7 +168,48 @@ void Level::load() { } XMLElement* light = composition->FirstChildElement("light"); for(; light; light=light->NextSiblingElement("light")){ - //TODO add lights + glm::vec3 compRot, lightOffset, lightColour; + float compScale, compXPos, compYOffset, compZPos, lightIntensity; + error = thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale); + errorCheck(error); + error = light->FirstChildElement("xOffset")->QueryFloatText(&lightOffset[0]); + errorCheck(error); + error = light->FirstChildElement("yOffset")->QueryFloatText(&lightOffset[1]); + errorCheck(error); + error = light->FirstChildElement("zOffset")->QueryFloatText(&lightOffset[2]); + errorCheck(error); + error = thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos); + errorCheck(error); + error = thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset); + errorCheck(error); + error = thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos); + errorCheck(error); + error = thisComposition->FirstChildElement("xRot")->QueryFloatText(&compRot[0]); + errorCheck(error); + error = thisComposition->FirstChildElement("yRot")->QueryFloatText(&compRot[1]); + errorCheck(error); + error = thisComposition->FirstChildElement("zRot")->QueryFloatText(&compRot[2]); + errorCheck(error); + error = light->FirstChildElement("rColour")->QueryFloatText(&lightColour[0]); + errorCheck(error); + error = light->FirstChildElement("gColour")->QueryFloatText(&lightColour[1]); + errorCheck(error); + error = light->FirstChildElement("bColour")->QueryFloatText(&lightColour[2]); + errorCheck(error); + error = light->FirstChildElement("intensity")->QueryFloatText(&lightIntensity); + errorCheck(error); + glm::vec3 compPos = glm::vec3(compXPos, + compYOffset+terrain.getHeightmap()[int(compXPos-0.5+0.5*terrain.getHeightmapHeight())] + [int(compZPos-0.5+0.5*terrain.getHeightmapWidth())], + compZPos); + lightOffset = lightOffset * compScale; + glm::vec4 rotatedLightOffset = glm::rotate(compRot.x, glm::vec3(1.0f, 0.0f, 0.0f)) + * glm::rotate(compRot.y, glm::vec3(0.0f, 1.0f, 0.0f)) + * glm::rotate(compRot.z, glm::vec3(0.0f, 0.0f, 1.0f)) + * glm::vec4(lightOffset, 0); + glm::vec3 lightPosition = compPos + glm::vec3(rotatedLightOffset.x,rotatedLightOffset.y,rotatedLightOffset.z); + Light light = Light(lightPosition, lightColour, lightIntensity); + lights.push_back(light); } } } @@ -227,9 +268,9 @@ void Level::load() { 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); + //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); + //lights.push_back(light2); }