Added indexing of the created objects for use in triggers. Added some comments to the loading.
This commit is contained in:
parent
c406bd4b62
commit
85c6132c3e
23
level.cc
23
level.cc
@ -105,6 +105,7 @@ void Level::load() {
|
|||||||
errorCheck(directionalElement->FirstChildElement("intensity")->QueryFloatText(&intensity));
|
errorCheck(directionalElement->FirstChildElement("intensity")->QueryFloatText(&intensity));
|
||||||
directionalLight = Light(glm::vec3(xOffset,yOffset,zOffset), glm::vec3(rColour,gColour,bColour), intensity);
|
directionalLight = Light(glm::vec3(xOffset,yOffset,zOffset), glm::vec3(rColour,gColour,bColour), intensity);
|
||||||
//load Objects
|
//load Objects
|
||||||
|
std::vector<int*> objectIdentifiers; //The first entry is the index in objects, the others are idGreen, idBlue and objectNum.
|
||||||
XMLDocument* compositions = new XMLDocument();
|
XMLDocument* compositions = new XMLDocument();
|
||||||
const char* compositionsFile = "../Levels/ObjectSetups/Compositions.xml";
|
const char* compositionsFile = "../Levels/ObjectSetups/Compositions.xml";
|
||||||
compositions->LoadFile(compositionsFile);
|
compositions->LoadFile(compositionsFile);
|
||||||
@ -112,16 +113,21 @@ void Level::load() {
|
|||||||
printf("Could not open Compositions!\n");
|
printf("Could not open Compositions!\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
//iterate over all compositions in Level.xml
|
||||||
XMLElement* thisComposition = doc->FirstChildElement("composition");
|
XMLElement* thisComposition = doc->FirstChildElement("composition");
|
||||||
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
|
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
|
||||||
int thisType = 0;
|
int thisType = 0;
|
||||||
errorCheck(thisComposition->FirstChildElement("typeID")->QueryIntText(&thisType));
|
errorCheck(thisComposition->FirstChildElement("typeID")->QueryIntText(&thisType));
|
||||||
|
//iterate over all compositions in Compositions.xml to find the one corresponding to the current composition
|
||||||
XMLElement* composition = compositions->FirstChildElement("composition");
|
XMLElement* composition = compositions->FirstChildElement("composition");
|
||||||
for(; composition; composition=composition->NextSiblingElement("composition")){
|
for(; composition; composition=composition->NextSiblingElement("composition")){
|
||||||
int compositionType = 0;
|
int compositionType = 0;
|
||||||
errorCheck(composition->FirstChildElement("typeID")->QueryIntText(&compositionType));
|
errorCheck(composition->FirstChildElement("typeID")->QueryIntText(&compositionType));
|
||||||
|
//corect composition found
|
||||||
if(thisType == compositionType){
|
if(thisType == compositionType){
|
||||||
|
//iterate over all objects of the composition
|
||||||
XMLElement* object = composition->FirstChildElement("object");
|
XMLElement* object = composition->FirstChildElement("object");
|
||||||
|
int objectNum = 0;
|
||||||
for(; object; object=object->NextSiblingElement("object")){
|
for(; object; object=object->NextSiblingElement("object")){
|
||||||
const char* charModelPath = object->FirstChildElement("modelPath")->GetText();
|
const char* charModelPath = object->FirstChildElement("modelPath")->GetText();
|
||||||
if(charModelPath == NULL){
|
if(charModelPath == NULL){
|
||||||
@ -132,6 +138,7 @@ void Level::load() {
|
|||||||
errorCheck(object->FirstChildElement("scale")->QueryFloatText(&objectScale));
|
errorCheck(object->FirstChildElement("scale")->QueryFloatText(&objectScale));
|
||||||
errorCheck(thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale));
|
errorCheck(thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale));
|
||||||
Model model = Model(modelPath, objectScale * compScale);
|
Model model = Model(modelPath, objectScale * compScale);
|
||||||
|
//find the objectData for the current object
|
||||||
XMLElement* objectData = compositions->FirstChildElement("objectData");
|
XMLElement* objectData = compositions->FirstChildElement("objectData");
|
||||||
for(; objectData; objectData=objectData->NextSiblingElement("objectData")){
|
for(; objectData; objectData=objectData->NextSiblingElement("objectData")){
|
||||||
const char* charDataModelPath = objectData->FirstChildElement("modelPath")->GetText();
|
const char* charDataModelPath = objectData->FirstChildElement("modelPath")->GetText();
|
||||||
@ -139,7 +146,9 @@ void Level::load() {
|
|||||||
printf("XMLError: No modelPath found in objectData.\n");
|
printf("XMLError: No modelPath found in objectData.\n");
|
||||||
}
|
}
|
||||||
std::string dataModelPath = charDataModelPath;
|
std::string dataModelPath = charDataModelPath;
|
||||||
|
//objectData found
|
||||||
if(dataModelPath == modelPath){
|
if(dataModelPath == modelPath){
|
||||||
|
//create the object
|
||||||
float ambientFactor, diffuseFactor, specularFactor, shininess;
|
float ambientFactor, diffuseFactor, specularFactor, shininess;
|
||||||
errorCheck(objectData->FirstChildElement("ambientFactor")->QueryFloatText(&ambientFactor));
|
errorCheck(objectData->FirstChildElement("ambientFactor")->QueryFloatText(&ambientFactor));
|
||||||
errorCheck(objectData->FirstChildElement("diffuseFactor")->QueryFloatText(&diffuseFactor));
|
errorCheck(objectData->FirstChildElement("diffuseFactor")->QueryFloatText(&diffuseFactor));
|
||||||
@ -174,13 +183,24 @@ void Level::load() {
|
|||||||
glm::vec3 objectPosition = compPos + glm::vec3(rotatedObjectOffset.x,rotatedObjectOffset.y,rotatedObjectOffset.z);
|
glm::vec3 objectPosition = compPos + glm::vec3(rotatedObjectOffset.x,rotatedObjectOffset.y,rotatedObjectOffset.z);
|
||||||
Object* object = new Object(model, material, objectPosition, compRot);
|
Object* object = new Object(model, material, objectPosition, compRot);
|
||||||
objects.push_back(object);
|
objects.push_back(object);
|
||||||
|
//create an identifier for this object
|
||||||
|
int* objectIdentifier = new int[4];
|
||||||
|
objectIdentifier[0] = objects.size()-1;
|
||||||
|
int idGreen, idBlue;
|
||||||
|
errorCheck(thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen));
|
||||||
|
errorCheck(thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue));
|
||||||
|
objectIdentifier[1] = idGreen;
|
||||||
|
objectIdentifier[2] = idBlue;
|
||||||
|
objectIdentifier[3] = objectNum;
|
||||||
|
objectIdentifiers.push_back(objectIdentifier);
|
||||||
|
//
|
||||||
physicObjects.push_back(object);
|
physicObjects.push_back(object);
|
||||||
const char* charPhysicType = objectData->FirstChildElement("physicType")->GetText();
|
const char* charPhysicType = objectData->FirstChildElement("physicType")->GetText();
|
||||||
if(charPhysicType == NULL){
|
if(charPhysicType == NULL){
|
||||||
printf("XMLError: No physicType found.\n");
|
printf("XMLError: No physicType found.\n");
|
||||||
}
|
}
|
||||||
std::string physicType = charPhysicType;
|
std::string physicType = charPhysicType;
|
||||||
//add Object to physics
|
//add object to physics
|
||||||
if (physicType.compare("Player") == 0){
|
if (physicType.compare("Player") == 0){
|
||||||
float radius, mass;
|
float radius, mass;
|
||||||
errorCheck(objectData->FirstChildElement("radius")->QueryFloatText(&radius));
|
errorCheck(objectData->FirstChildElement("radius")->QueryFloatText(&radius));
|
||||||
@ -207,6 +227,7 @@ void Level::load() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
objectNum = objectNum + 1;
|
||||||
}
|
}
|
||||||
XMLElement* light = composition->FirstChildElement("light");
|
XMLElement* light = composition->FirstChildElement("light");
|
||||||
for(; light; light=light->NextSiblingElement("light")){
|
for(; light; light=light->NextSiblingElement("light")){
|
||||||
|
Loading…
Reference in New Issue
Block a user