diff --git a/Levels/ObjectSetups/Compositions.xml b/Levels/ObjectSetups/Compositions.xml index 1fa82eb..bfe11a5 100644 --- a/Levels/ObjectSetups/Compositions.xml +++ b/Levels/ObjectSetups/Compositions.xml @@ -162,9 +162,10 @@ 0.6 0.4 2.0 - TriangleMesh - 0.5 - 0.5 + Box + 0.5 + 0.5 + 0.5 diff --git a/level.cc b/level.cc index 13e82b8..264ecf9 100644 --- a/level.cc +++ b/level.cc @@ -149,7 +149,7 @@ void Level::load() { } std::string dataModelPath = charDataModelPath; //objectData found - if(dataModelPath == modelPath){ + if(dataModelPath.compare(modelPath) == 0){ //create the object float ambientFactor, diffuseFactor, specularFactor, shininess; errorCheck(objectData->FirstChildElement("ambientFactor")->QueryFloatText(&ambientFactor)); @@ -237,24 +237,24 @@ void Level::load() { }//iterating over all objects of the composition //iterate over all lights of the composition - XMLElement* light = composition->FirstChildElement("light"); - for(; light; light=light->NextSiblingElement("light")){ + XMLElement* xmlLight = composition->FirstChildElement("light"); + for(; xmlLight; xmlLight=xmlLight->NextSiblingElement("light")){ glm::vec3 compRot, lightOffset, lightColour; float compScale, compXPos, compYOffset, compZPos, lightIntensity; errorCheck(thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale)); - errorCheck(light->FirstChildElement("xOffset")->QueryFloatText(&lightOffset[0])); - errorCheck(light->FirstChildElement("yOffset")->QueryFloatText(&lightOffset[1])); - errorCheck(light->FirstChildElement("zOffset")->QueryFloatText(&lightOffset[2])); + errorCheck(xmlLight->FirstChildElement("xOffset")->QueryFloatText(&lightOffset[0])); + errorCheck(xmlLight->FirstChildElement("yOffset")->QueryFloatText(&lightOffset[1])); + errorCheck(xmlLight->FirstChildElement("zOffset")->QueryFloatText(&lightOffset[2])); errorCheck(thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos)); errorCheck(thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset)); errorCheck(thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos)); errorCheck(thisComposition->FirstChildElement("xRot")->QueryFloatText(&compRot[0])); errorCheck(thisComposition->FirstChildElement("yRot")->QueryFloatText(&compRot[1])); errorCheck(thisComposition->FirstChildElement("zRot")->QueryFloatText(&compRot[2])); - errorCheck(light->FirstChildElement("rColour")->QueryFloatText(&lightColour[0])); - errorCheck(light->FirstChildElement("gColour")->QueryFloatText(&lightColour[1])); - errorCheck(light->FirstChildElement("bColour")->QueryFloatText(&lightColour[2])); - errorCheck(light->FirstChildElement("intensity")->QueryFloatText(&lightIntensity)); + errorCheck(xmlLight->FirstChildElement("rColour")->QueryFloatText(&lightColour[0])); + errorCheck(xmlLight->FirstChildElement("gColour")->QueryFloatText(&lightColour[1])); + errorCheck(xmlLight->FirstChildElement("bColour")->QueryFloatText(&lightColour[2])); + errorCheck(xmlLight->FirstChildElement("intensity")->QueryFloatText(&lightIntensity)); 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())], @@ -273,15 +273,32 @@ void Level::load() { }//iterating over all compositions in Level.xml //load triggers - XMLElement* trigger = doc->FirstChildElement("trigger"); - for(; trigger; trigger=trigger->NextSiblingElement("trigger")){ - const char* charName = trigger->FirstChildElement("name")->GetText(); + XMLElement* xmlTrigger = doc->FirstChildElement("trigger"); + for(; xmlTrigger; xmlTrigger=xmlTrigger->NextSiblingElement("trigger")){ + const char* charName = xmlTrigger->FirstChildElement("name")->GetText(); if(charName == NULL){ printf("XMLError: No name found for a trigger.\n"); } std::string name = charName; if (name.compare("-") != 0){ - //TODO add triggers + float xPos, yPos, zPos, distance; + std::vector position; + bool isBigger; + int idGreen, idBlue, objectNum; + errorCheck(xmlTrigger->FirstChildElement("xPosition")->QueryFloatText(&xPos)); + errorCheck(xmlTrigger->FirstChildElement("yPosition")->QueryFloatText(&yPos)); + errorCheck(xmlTrigger->FirstChildElement("zPosition")->QueryFloatText(&zPos)); + errorCheck(xmlTrigger->FirstChildElement("distance")->QueryFloatText(&distance)); + position.push_back(xPos); + position.push_back(yPos); + position.push_back(zPos); + errorCheck(xmlTrigger->FirstChildElement("isBiggerThan")->QueryBoolText(&isBigger)); + errorCheck(xmlTrigger->FirstChildElement("idGreen")->QueryIntText(&idGreen)); + errorCheck(xmlTrigger->FirstChildElement("idBlue")->QueryIntText(&idBlue)); + errorCheck(xmlTrigger->FirstChildElement("objectNum")->QueryIntText(&objectNum)); + //TODO find the object + //Trigger trigger = Trigger::Trigger(position, distance, isBigger, Object* object, void (*functionPointer)()); + //triggers.push_back(trigger); } } diff --git a/level.hh b/level.hh index 364d392..75b3815 100644 --- a/level.hh +++ b/level.hh @@ -10,6 +10,7 @@ #include "camera.hh" #include "physics.hh" #include "tinyxml2.hh" +#include "trigger.hh" class Level { public: @@ -34,6 +35,7 @@ class Level { std::vector objects; std::vector physicObjects; std::vector lights; + std::vector triggers; glm::vec3 ambientLight; glm::vec4 fogColour; Light directionalLight; diff --git a/trigger.cc b/trigger.cc index ab0618a..5296efd 100644 --- a/trigger.cc +++ b/trigger.cc @@ -1,7 +1,11 @@ #include "trigger.hh" -Trigger::Trigger(std::vector position, float distance, bool isBigger, int objectIndex, int functionPointer) { - +Trigger::Trigger(std::vector position, float distance, bool isBigger, Object* object, void (*functionPointer)()) { + this->position=position; + this->distance=distance; + this->isBigger=isBigger; + this->object=object; + this->functionPointer=functionPointer; } Trigger::Trigger(){ @@ -9,3 +13,7 @@ Trigger::Trigger(){ Trigger::~Trigger(){ } + +void Trigger::triggerUpdate(){ + +} diff --git a/trigger.hh b/trigger.hh index 05f1c3b..04fbac1 100644 --- a/trigger.hh +++ b/trigger.hh @@ -2,14 +2,20 @@ #define TRIGGER_HH_INCLUDED #include +#include "object.hh" class Trigger { public: - Trigger(std::vector position, float distance, bool isBigger, int objectIndex, int functionPointer); + Trigger(std::vector position, float distance, bool isBigger, Object* object, void (*functionPointer)()); Trigger(); ~Trigger(); + void triggerUpdate(); private: - + std::vector position; + float distance; + bool isBigger; + Object* object; + void (*functionPointer)(); }; #endif