Now using the xml query functions everywhere in the loader class.
This commit is contained in:
parent
99d8a45380
commit
153e0116c7
303
loader.cc
303
loader.cc
@ -41,27 +41,20 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
//load global physic parameter
|
//load global physic parameter
|
||||||
float friction, strength;
|
|
||||||
XMLElement* physicsElement = doc->FirstChildElement("physics");
|
XMLElement* physicsElement = doc->FirstChildElement("physics");
|
||||||
errorCheck(physicsElement->FirstChildElement("strength")->QueryFloatText(&strength));
|
float strength = queryFloat(physicsElement, "strength");
|
||||||
errorCheck(physicsElement->FirstChildElement("friction")->QueryFloatText(&friction));
|
float friction = queryFloat(physicsElement, "friction");
|
||||||
level->setStrength(strength);
|
level->setStrength(strength);
|
||||||
|
|
||||||
// load the terrain
|
// load the terrain
|
||||||
level->getTerrain()->load();
|
level->getTerrain()->load();
|
||||||
Model terrainModel = Model(level->getTerrain()->getModel());
|
Model terrainModel = Model(level->getTerrain()->getModel());
|
||||||
XMLElement* terrainElement = doc->FirstChildElement("terrain");
|
XMLElement* terrainElement = doc->FirstChildElement("terrain");
|
||||||
const char* charTerrainTexture = terrainElement->FirstChildElement("texture")->GetText();
|
std::string terrainTexture = queryString(terrainElement, "texture");
|
||||||
if(charTerrainTexture == NULL){
|
float terrainAmbientFactor = queryFloat(terrainElement, "ambientFactor");
|
||||||
printf("XMLError: No terrainTexture found.\n");
|
float terrainDiffuseFactor = queryFloat(terrainElement, "diffuseFactor");
|
||||||
exit(-1);
|
float terrainSpecularFactor = queryFloat(terrainElement, "specularFactor");
|
||||||
}
|
float terrainShininess = queryFloat(terrainElement, "shininess");
|
||||||
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);
|
Material terrainMaterial = Material(terrainTexture, terrainAmbientFactor, terrainDiffuseFactor, terrainSpecularFactor, terrainShininess);
|
||||||
Object* terrainObject = new Object(terrainModel, terrainMaterial,
|
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.5*(float)level->getTerrain()->getHeightmapHeight(), 0.0f, -0.5f*(float)level->getTerrain()->getHeightmapWidth()),
|
||||||
@ -71,12 +64,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
|||||||
|
|
||||||
//load the skydome
|
//load the skydome
|
||||||
XMLElement* skydomeElement = doc->FirstChildElement("skydome");
|
XMLElement* skydomeElement = doc->FirstChildElement("skydome");
|
||||||
const char* charSkydomeTexture = skydomeElement->FirstChildElement("texture")->GetText();
|
std::string skydomeTexture = queryString(skydomeElement, "texture");;
|
||||||
if(charSkydomeTexture == NULL){
|
|
||||||
printf("XMLError: No skydomeTexture found.\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
std::string skydomeTexture = charSkydomeTexture;
|
|
||||||
Model skydomeModel = Model("skydome.obj", level->getSkydomeSize());
|
Model skydomeModel = Model("skydome.obj", level->getSkydomeSize());
|
||||||
Material skydomeMaterial = Material(skydomeTexture, 0.7f, 0.0f, 0.0f, 0.0f);
|
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),
|
Object* skydomeObject = new Object(skydomeModel, skydomeMaterial, glm::vec3(0.0f, 0.0f, 0.0f),
|
||||||
@ -87,32 +75,31 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
|||||||
//load lighting parameters
|
//load lighting parameters
|
||||||
float rColour, gColour, bColour, alpha, xOffset, yOffset, zOffset, intensity;
|
float rColour, gColour, bColour, alpha, xOffset, yOffset, zOffset, intensity;
|
||||||
XMLElement* ambientElement = doc->FirstChildElement("ambientLight");
|
XMLElement* ambientElement = doc->FirstChildElement("ambientLight");
|
||||||
errorCheck(ambientElement->FirstChildElement("rColour")->QueryFloatText(&rColour));
|
rColour = queryFloat(ambientElement, "rColour");
|
||||||
errorCheck(ambientElement->FirstChildElement("gColour")->QueryFloatText(&gColour));
|
gColour = queryFloat(ambientElement, "gColour");
|
||||||
errorCheck(ambientElement->FirstChildElement("bColour")->QueryFloatText(&bColour));
|
bColour = queryFloat(ambientElement, "bColour");
|
||||||
level->setAmbientLight(glm::vec3(rColour,gColour,bColour));
|
level->setAmbientLight(glm::vec3(rColour,gColour,bColour));
|
||||||
|
|
||||||
XMLElement* fogElement = doc->FirstChildElement("fogColour");
|
XMLElement* fogElement = doc->FirstChildElement("fogColour");
|
||||||
errorCheck(fogElement->FirstChildElement("rColour")->QueryFloatText(&rColour));
|
rColour = queryFloat(fogElement, "rColour");
|
||||||
errorCheck(fogElement->FirstChildElement("gColour")->QueryFloatText(&gColour));
|
gColour = queryFloat(fogElement, "gColour");
|
||||||
errorCheck(fogElement->FirstChildElement("bColour")->QueryFloatText(&bColour));
|
bColour = queryFloat(fogElement, "bColour");
|
||||||
errorCheck(fogElement->FirstChildElement("alpha")->QueryFloatText(&alpha));
|
alpha = queryFloat(fogElement, "alpha");
|
||||||
level->setFogColour(glm::vec4(rColour,gColour,bColour, alpha));
|
level->setFogColour(glm::vec4(rColour,gColour,bColour, alpha));
|
||||||
|
|
||||||
XMLElement* directionalElement = doc->FirstChildElement("directionalLight");
|
XMLElement* directionalElement = doc->FirstChildElement("directionalLight");
|
||||||
errorCheck(directionalElement->FirstChildElement("xOffset")->QueryFloatText(&xOffset));
|
xOffset = queryFloat(directionalElement, "xOffset");
|
||||||
errorCheck(directionalElement->FirstChildElement("yOffset")->QueryFloatText(&yOffset));
|
yOffset = queryFloat(directionalElement, "yOffset");
|
||||||
errorCheck(directionalElement->FirstChildElement("zOffset")->QueryFloatText(&zOffset));
|
zOffset = queryFloat(directionalElement, "zOffset");
|
||||||
errorCheck(directionalElement->FirstChildElement("rColour")->QueryFloatText(&rColour));
|
rColour = queryFloat(directionalElement, "rColour");
|
||||||
errorCheck(directionalElement->FirstChildElement("gColour")->QueryFloatText(&gColour));
|
gColour = queryFloat(directionalElement, "gColour");
|
||||||
errorCheck(directionalElement->FirstChildElement("bColour")->QueryFloatText(&bColour));
|
bColour = queryFloat(directionalElement, "bColour");
|
||||||
errorCheck(directionalElement->FirstChildElement("intensity")->QueryFloatText(&intensity));
|
intensity = queryFloat(directionalElement, "intensity");
|
||||||
level->setDirectionalLight(Light(glm::vec3(xOffset,yOffset,zOffset), glm::vec3(rColour,gColour,bColour), intensity));
|
level->setDirectionalLight(Light(glm::vec3(xOffset,yOffset,zOffset), glm::vec3(rColour,gColour,bColour), intensity));
|
||||||
|
|
||||||
//load Objects
|
//load Objects
|
||||||
std::vector<std::vector<int>> objectIdentifiers = std::vector<std::vector<int>>(); //The first entry is the index in objects, the second one the index in physicObjects, the others are idGreen, idBlue and objectNum.
|
std::vector<std::vector<int>> objectIdentifiers = std::vector<std::vector<int>>(); //The first entry is the index in objects, the second one the index in physicObjects, the others are idGreen, idBlue and objectNum.
|
||||||
XMLDocument* compositions = new XMLDocument();
|
XMLDocument* compositions = new XMLDocument();
|
||||||
//TODO move path to config.xml
|
|
||||||
const char* compositionsFile = compositionsPath.c_str();
|
const char* compositionsFile = compositionsPath.c_str();
|
||||||
compositions->LoadFile(compositionsFile);
|
compositions->LoadFile(compositionsFile);
|
||||||
if (compositions->ErrorID()!=0){
|
if (compositions->ErrorID()!=0){
|
||||||
@ -122,73 +109,51 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
|||||||
//iterate over all compositions in Level.xml
|
//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 = queryInt(thisComposition, "typeID");
|
||||||
errorCheck(thisComposition->FirstChildElement("typeID")->QueryIntText(&thisType));
|
|
||||||
//iterate over all compositions in Compositions.xml to find the one corresponding to the current composition
|
//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 = queryInt(composition, "typeID");
|
||||||
errorCheck(composition->FirstChildElement("typeID")->QueryIntText(&compositionType));
|
|
||||||
//corect composition found
|
//corect composition found
|
||||||
if(thisType == compositionType){
|
if(thisType == compositionType){
|
||||||
//iterate over all objects of the composition
|
//iterate over all objects of the composition
|
||||||
XMLElement* xmlObject = composition->FirstChildElement("object");
|
XMLElement* xmlObject = composition->FirstChildElement("object");
|
||||||
int objectNum = 0;
|
int objectNum = 0;
|
||||||
for(; xmlObject; xmlObject=xmlObject->NextSiblingElement("object")){
|
for(; xmlObject; xmlObject=xmlObject->NextSiblingElement("object")){
|
||||||
const char* charModelPath = xmlObject->FirstChildElement("modelPath")->GetText();
|
std::string modelPath = queryString(xmlObject, "modelPath");
|
||||||
if(charModelPath == NULL){
|
float objectScale = queryFloat(xmlObject, "scale");
|
||||||
printf("XMLError: No modelPath found in object.\n");
|
float compScale = queryFloat(thisComposition, "scale");
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
std::string modelPath = charModelPath;
|
|
||||||
float objectScale, compScale;
|
|
||||||
errorCheck(xmlObject->FirstChildElement("scale")->QueryFloatText(&objectScale));
|
|
||||||
errorCheck(thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale));
|
|
||||||
//find the objectData for the current object
|
//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();
|
std::string dataModelPath = queryString(objectData, "modelPath");
|
||||||
if(charDataModelPath == NULL){
|
|
||||||
printf("XMLError: No modelPath found in objectData.\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
std::string dataModelPath = charDataModelPath;
|
|
||||||
//objectData found
|
//objectData found
|
||||||
if(dataModelPath.compare(modelPath) == 0){
|
if(dataModelPath.compare(modelPath) == 0){
|
||||||
bool renderable;
|
bool renderable = queryBool(objectData, "renderable");
|
||||||
errorCheck(objectData->FirstChildElement("renderable")->QueryBoolText(&renderable));
|
|
||||||
//create the object
|
//create the object
|
||||||
Material material;
|
Material material;
|
||||||
Model model;
|
Model model;
|
||||||
if (renderable) {
|
if (renderable) {
|
||||||
float ambientFactor, diffuseFactor, specularFactor, shininess;
|
float ambientFactor = queryFloat(objectData, "ambientFactor");
|
||||||
errorCheck(objectData->FirstChildElement("ambientFactor")->QueryFloatText(&ambientFactor));
|
float diffuseFactor = queryFloat(objectData, "diffuseFactor");
|
||||||
errorCheck(objectData->FirstChildElement("diffuseFactor")->QueryFloatText(&diffuseFactor));
|
float specularFactor = queryFloat(objectData, "specularFactor");
|
||||||
errorCheck(objectData->FirstChildElement("specularFactor")->QueryFloatText(&specularFactor));
|
float shininess = queryFloat(objectData, "shininess");
|
||||||
errorCheck(objectData->FirstChildElement("shininess")->QueryFloatText(&shininess));
|
std::string texturePath = queryString(objectData, "texturePath");
|
||||||
const char* charTexturePath = objectData->FirstChildElement("texturePath")->GetText();
|
|
||||||
if(charTexturePath == NULL){
|
|
||||||
printf("XMLError: No texturePath found in objectData.\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
std::string texturePath = charTexturePath;
|
|
||||||
material = Material(texturePath, ambientFactor, diffuseFactor, specularFactor, shininess);
|
material = Material(texturePath, ambientFactor, diffuseFactor, specularFactor, shininess);
|
||||||
model = Model(modelPath, objectScale * compScale);
|
model = Model(modelPath, objectScale * compScale);
|
||||||
}
|
}
|
||||||
float compXPos, compYOffset, compZPos;
|
float compXPos = queryFloat(thisComposition, "xPos");
|
||||||
|
float compYOffset = queryFloat(thisComposition, "yOffset");
|
||||||
|
float compZPos = queryFloat(thisComposition, "zPos");
|
||||||
glm::vec3 objectOffset, compRot;
|
glm::vec3 objectOffset, compRot;
|
||||||
errorCheck(xmlObject->FirstChildElement("xOffset")->QueryFloatText(&objectOffset[0]));
|
objectOffset[0] = queryFloat(xmlObject, "xOffset");
|
||||||
errorCheck(xmlObject->FirstChildElement("yOffset")->QueryFloatText(&objectOffset[1]));
|
objectOffset[1] = queryFloat(xmlObject, "yOffset");
|
||||||
errorCheck(xmlObject->FirstChildElement("zOffset")->QueryFloatText(&objectOffset[2]));
|
objectOffset[2] = queryFloat(xmlObject, "zOffset");
|
||||||
errorCheck(thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos));
|
compRot[0] = queryFloat(thisComposition, "xRot");
|
||||||
errorCheck(thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset));
|
compRot[1] = queryFloat(thisComposition, "yRot");
|
||||||
errorCheck(thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos));
|
compRot[2] = queryFloat(thisComposition, "zRot");
|
||||||
errorCheck(thisComposition->FirstChildElement("xRot")->QueryFloatText(&compRot[0]));
|
|
||||||
errorCheck(thisComposition->FirstChildElement("yRot")->QueryFloatText(&compRot[1]));
|
|
||||||
errorCheck(thisComposition->FirstChildElement("zRot")->QueryFloatText(&compRot[2]));
|
|
||||||
compRot *= 0.0174532925; //transform degrees to radians
|
compRot *= 0.0174532925; //transform degrees to radians
|
||||||
bool ignoreHeightmap;
|
bool ignoreHeightmap = queryBool(composition, "ignoreHeightmap");
|
||||||
errorCheck(composition->FirstChildElement("ignoreHeightmap")->QueryBoolText(&ignoreHeightmap));
|
|
||||||
if (!ignoreHeightmap){
|
if (!ignoreHeightmap){
|
||||||
compYOffset = compYOffset+level->getTerrain()->getHeightmap()[int(compXPos-0.5+0.5*level->getTerrain()->getHeightmapHeight())]
|
compYOffset = compYOffset+level->getTerrain()->getHeightmap()[int(compXPos-0.5+0.5*level->getTerrain()->getHeightmapHeight())]
|
||||||
[int(compZPos-0.5+0.5*level->getTerrain()->getHeightmapWidth())];
|
[int(compZPos-0.5+0.5*level->getTerrain()->getHeightmapWidth())];
|
||||||
@ -201,60 +166,47 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
|||||||
* glm::vec4(objectOffset, 0);
|
* glm::vec4(objectOffset, 0);
|
||||||
glm::vec3 objectPosition = compPos + glm::vec3(rotatedObjectOffset.x,rotatedObjectOffset.y,rotatedObjectOffset.z);
|
glm::vec3 objectPosition = compPos + glm::vec3(rotatedObjectOffset.x,rotatedObjectOffset.y,rotatedObjectOffset.z);
|
||||||
glm::vec3 objectRot;
|
glm::vec3 objectRot;
|
||||||
errorCheck(xmlObject->FirstChildElement("xRot")->QueryFloatText(&objectRot[0]));
|
objectRot[0] = queryFloat(xmlObject, "xRot");
|
||||||
errorCheck(xmlObject->FirstChildElement("yRot")->QueryFloatText(&objectRot[1]));
|
objectRot[1] = queryFloat(xmlObject, "yRot");
|
||||||
errorCheck(xmlObject->FirstChildElement("zRot")->QueryFloatText(&objectRot[2]));
|
objectRot[2] = queryFloat(xmlObject, "zRot");
|
||||||
objectRot *= 0.0174532925; //transform degrees to radians
|
objectRot *= 0.0174532925; //transform degrees to radians
|
||||||
Object* object = new Object(model, material, objectPosition, compRot+objectRot, renderable);
|
Object* object = new Object(model, material, objectPosition, compRot+objectRot, renderable);
|
||||||
level->addObject(object);
|
level->addObject(object);
|
||||||
|
|
||||||
//add object to physics
|
//add object to physics
|
||||||
const char* charPhysicType = objectData->FirstChildElement("physicType")->GetText();
|
std::string physicType = queryString(objectData, "physicType");
|
||||||
if(charPhysicType == NULL){
|
float mass = queryFloat(xmlObject, "mass");
|
||||||
printf("XMLError: No physicType found.\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
std::string physicType = charPhysicType;
|
|
||||||
float mass;
|
|
||||||
errorCheck(xmlObject->FirstChildElement("mass")->QueryFloatText(&mass));
|
|
||||||
XMLElement* constraint = thisComposition->FirstChildElement("positionConstraint");
|
XMLElement* constraint = thisComposition->FirstChildElement("positionConstraint");
|
||||||
bool rotate = (constraint == NULL);
|
bool rotate = (constraint == NULL);
|
||||||
|
float dampningL, dampningA;
|
||||||
|
if (physicType.compare("None") != 0){
|
||||||
|
dampningL = queryFloat(objectData, "dampningL");
|
||||||
|
dampningA = queryFloat(objectData, "dampningA");
|
||||||
|
}
|
||||||
if (physicType.compare("Player") == 0){
|
if (physicType.compare("Player") == 0){
|
||||||
float radius, dampningL, dampningA;
|
float radius = queryFloat(objectData, "radius");
|
||||||
errorCheck(objectData->FirstChildElement("dampningL")->QueryFloatText(&dampningL));
|
|
||||||
errorCheck(objectData->FirstChildElement("dampningA")->QueryFloatText(&dampningA));
|
|
||||||
errorCheck(objectData->FirstChildElement("radius")->QueryFloatText(&radius));
|
|
||||||
radius *= objectScale*compScale;
|
radius *= objectScale*compScale;
|
||||||
level->addPhysicsObject(object);
|
level->addPhysicsObject(object);
|
||||||
level->getPhysics()->addPlayer(friction, radius, *object, mass, dampningL, dampningA, level->getPhysicsObjectsVectorSize());
|
level->getPhysics()->addPlayer(friction, radius, *object, mass, dampningL, dampningA, level->getPhysicsObjectsVectorSize());
|
||||||
}else if (physicType.compare("Box") == 0){
|
}else if (physicType.compare("Box") == 0){
|
||||||
float width, height, length, dampningL, dampningA;
|
float width = queryFloat(objectData, "width");
|
||||||
errorCheck(objectData->FirstChildElement("dampningL")->QueryFloatText(&dampningL));
|
float height = queryFloat(objectData, "height");
|
||||||
errorCheck(objectData->FirstChildElement("dampningA")->QueryFloatText(&dampningA));
|
float length = queryFloat(objectData, "length");
|
||||||
errorCheck(objectData->FirstChildElement("width")->QueryFloatText(&width));
|
|
||||||
errorCheck(objectData->FirstChildElement("height")->QueryFloatText(&height));
|
|
||||||
errorCheck(objectData->FirstChildElement("length")->QueryFloatText(&length));
|
|
||||||
width *= objectScale*compScale;
|
width *= objectScale*compScale;
|
||||||
height *= objectScale*compScale;
|
height *= objectScale*compScale;
|
||||||
length *= objectScale*compScale;
|
length *= objectScale*compScale;
|
||||||
level->addPhysicsObject(object);
|
level->addPhysicsObject(object);
|
||||||
level->getPhysics()->addBox(width, height, length, *object, mass, dampningL, dampningA, level->getPhysicsObjectsVectorSize(), rotate);
|
level->getPhysics()->addBox(width, height, length, *object, mass, dampningL, dampningA, level->getPhysicsObjectsVectorSize(), rotate);
|
||||||
}else if (physicType.compare("Button") == 0){
|
}else if (physicType.compare("Button") == 0){
|
||||||
float width, height, length, dampningL, dampningA;
|
float width = queryFloat(objectData, "width");
|
||||||
errorCheck(objectData->FirstChildElement("dampningL")->QueryFloatText(&dampningL));
|
float height = queryFloat(objectData, "height");
|
||||||
errorCheck(objectData->FirstChildElement("dampningA")->QueryFloatText(&dampningA));
|
float length = queryFloat(objectData, "length");
|
||||||
errorCheck(objectData->FirstChildElement("width")->QueryFloatText(&width));
|
|
||||||
errorCheck(objectData->FirstChildElement("height")->QueryFloatText(&height));
|
|
||||||
errorCheck(objectData->FirstChildElement("length")->QueryFloatText(&length));
|
|
||||||
width *= objectScale*compScale;
|
width *= objectScale*compScale;
|
||||||
height *= objectScale*compScale;
|
height *= objectScale*compScale;
|
||||||
length *= objectScale*compScale;
|
length *= objectScale*compScale;
|
||||||
level->addPhysicsObject(object);
|
level->addPhysicsObject(object);
|
||||||
level->getPhysics()->addButton(width, height, length, *object, mass, dampningL, dampningA, level->getPhysicsObjectsVectorSize(), rotate);
|
level->getPhysics()->addButton(width, height, length, *object, mass, dampningL, dampningA, level->getPhysicsObjectsVectorSize(), rotate);
|
||||||
}else if (physicType.compare("TriangleMesh") == 0){
|
}else if (physicType.compare("TriangleMesh") == 0){
|
||||||
float dampningL, dampningA;
|
|
||||||
errorCheck(objectData->FirstChildElement("dampningL")->QueryFloatText(&dampningL));
|
|
||||||
errorCheck(objectData->FirstChildElement("dampningA")->QueryFloatText(&dampningA));
|
|
||||||
level->addPhysicsObject(object);
|
level->addPhysicsObject(object);
|
||||||
level->getPhysics()->addTriangleMeshBody(*object, modelPath, mass, dampningL, dampningA, level->getPhysicsObjectsVectorSize(), objectScale*compScale, rotate);
|
level->getPhysics()->addTriangleMeshBody(*object, modelPath, mass, dampningL, dampningA, level->getPhysicsObjectsVectorSize(), objectScale*compScale, rotate);
|
||||||
}else if (physicType.compare("None") == 0){
|
}else if (physicType.compare("None") == 0){
|
||||||
@ -272,9 +224,8 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
|||||||
}else{
|
}else{
|
||||||
objectIdentifier[1] = level->getPhysicsObjectsVectorSize()-1;
|
objectIdentifier[1] = level->getPhysicsObjectsVectorSize()-1;
|
||||||
}
|
}
|
||||||
int idGreen, idBlue;
|
int idGreen = queryInt(thisComposition, "idGreen");
|
||||||
errorCheck(thisComposition->FirstChildElement("idGreen")->QueryIntText(&idGreen));
|
int idBlue = queryInt(thisComposition, "idBlue");
|
||||||
errorCheck(thisComposition->FirstChildElement("idBlue")->QueryIntText(&idBlue));
|
|
||||||
objectIdentifier[2] = idGreen;
|
objectIdentifier[2] = idGreen;
|
||||||
objectIdentifier[3] = idBlue;
|
objectIdentifier[3] = idBlue;
|
||||||
objectIdentifier[4] = objectNum;
|
objectIdentifier[4] = objectNum;
|
||||||
@ -293,21 +244,20 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
|||||||
XMLElement* xmlLight = composition->FirstChildElement("light");
|
XMLElement* xmlLight = composition->FirstChildElement("light");
|
||||||
for(; xmlLight; xmlLight=xmlLight->NextSiblingElement("light")){
|
for(; xmlLight; xmlLight=xmlLight->NextSiblingElement("light")){
|
||||||
glm::vec3 compRot, lightOffset, lightColour;
|
glm::vec3 compRot, lightOffset, lightColour;
|
||||||
float compScale, compXPos, compYOffset, compZPos, lightIntensity;
|
compRot[0] = queryFloat(thisComposition, "xRot");
|
||||||
errorCheck(thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale));
|
compRot[1] = queryFloat(thisComposition, "yRot");
|
||||||
errorCheck(xmlLight->FirstChildElement("xOffset")->QueryFloatText(&lightOffset[0]));
|
compRot[2] = queryFloat(thisComposition, "zRot");
|
||||||
errorCheck(xmlLight->FirstChildElement("yOffset")->QueryFloatText(&lightOffset[1]));
|
lightOffset[0] = queryFloat(xmlLight, "xOffset");
|
||||||
errorCheck(xmlLight->FirstChildElement("zOffset")->QueryFloatText(&lightOffset[2]));
|
lightOffset[1] = queryFloat(xmlLight, "yOffset");
|
||||||
errorCheck(thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos));
|
lightOffset[2] = queryFloat(xmlLight, "zOffset");
|
||||||
errorCheck(thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset));
|
lightColour[0] = queryFloat(xmlLight, "rColour");
|
||||||
errorCheck(thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos));
|
lightColour[1] = queryFloat(xmlLight, "gColour");
|
||||||
errorCheck(thisComposition->FirstChildElement("xRot")->QueryFloatText(&compRot[0]));
|
lightColour[2] = queryFloat(xmlLight, "bColour");
|
||||||
errorCheck(thisComposition->FirstChildElement("yRot")->QueryFloatText(&compRot[1]));
|
float compScale = queryFloat(thisComposition, "scale");
|
||||||
errorCheck(thisComposition->FirstChildElement("zRot")->QueryFloatText(&compRot[2]));
|
float compXPos = queryFloat(thisComposition, "xPos");
|
||||||
errorCheck(xmlLight->FirstChildElement("rColour")->QueryFloatText(&lightColour[0]));
|
float compYOffset = queryFloat(thisComposition, "yOffset");
|
||||||
errorCheck(xmlLight->FirstChildElement("gColour")->QueryFloatText(&lightColour[1]));
|
float compZPos = queryFloat(thisComposition, "zPos");
|
||||||
errorCheck(xmlLight->FirstChildElement("bColour")->QueryFloatText(&lightColour[2]));
|
float lightIntensity = queryFloat(xmlLight, "intensity");
|
||||||
errorCheck(xmlLight->FirstChildElement("intensity")->QueryFloatText(&lightIntensity));
|
|
||||||
glm::vec3 compPos = glm::vec3(compXPos,
|
glm::vec3 compPos = glm::vec3(compXPos,
|
||||||
compYOffset+level->getTerrain()->getHeightmap()[int(compXPos-0.5+0.5*level->getTerrain()->getHeightmapHeight())]
|
compYOffset+level->getTerrain()->getHeightmap()[int(compXPos-0.5+0.5*level->getTerrain()->getHeightmapHeight())]
|
||||||
[int(compZPos-0.5+0.5*level->getTerrain()->getHeightmapWidth())],
|
[int(compZPos-0.5+0.5*level->getTerrain()->getHeightmapWidth())],
|
||||||
@ -335,59 +285,43 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
|||||||
|
|
||||||
//load triggers
|
//load triggers
|
||||||
|
|
||||||
// call init.lua to init the module load path in Lua
|
// call init.lua to initialize the module load path in Lua
|
||||||
std::string initLuaPath = scriptPath + "init.lua";
|
std::string initLuaPath = scriptPath + "init.lua";
|
||||||
luaL_dofile(level->getLuaState(), initLuaPath.c_str());
|
luaL_dofile(level->getLuaState(), initLuaPath.c_str());
|
||||||
XMLElement* composition = doc->FirstChildElement("composition");
|
XMLElement* composition = doc->FirstChildElement("composition");
|
||||||
for(; composition; composition=composition->NextSiblingElement("composition")){
|
for(; composition; composition=composition->NextSiblingElement("composition")){
|
||||||
XMLElement* xmlTrigger = composition->FirstChildElement("trigger");
|
XMLElement* xmlTrigger = composition->FirstChildElement("trigger");
|
||||||
for(; xmlTrigger; xmlTrigger=xmlTrigger->NextSiblingElement("trigger")){
|
for(; xmlTrigger; xmlTrigger=xmlTrigger->NextSiblingElement("trigger")){
|
||||||
const char* charName = xmlTrigger->FirstChildElement("name")->GetText();
|
std::string name = queryString(xmlTrigger, "name");
|
||||||
if(charName == NULL){
|
|
||||||
printf("XMLError: No name found for a trigger.\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
std::string name = charName;
|
|
||||||
if (name.compare("-") != 0){
|
if (name.compare("-") != 0){
|
||||||
float xPos, yPos, zPos, distance;
|
float xPos = queryFloat(xmlTrigger, "xPosition");
|
||||||
bool isBigger;
|
float yPos = queryFloat(xmlTrigger, "yPosition");
|
||||||
int idGreen, idBlue, objectNum;
|
float zPos = queryFloat(xmlTrigger, "zPosition");
|
||||||
|
|
||||||
errorCheck(xmlTrigger->FirstChildElement("xPosition")->QueryFloatText(&xPos));
|
|
||||||
errorCheck(xmlTrigger->FirstChildElement("yPosition")->QueryFloatText(&yPos));
|
|
||||||
errorCheck(xmlTrigger->FirstChildElement("zPosition")->QueryFloatText(&zPos));
|
|
||||||
glm::vec3 position = glm::vec3(xPos, yPos, zPos);
|
glm::vec3 position = glm::vec3(xPos, yPos, zPos);
|
||||||
const char* charTarget = xmlTrigger->FirstChildElement("targetIdGreen")->GetText();
|
std::string stringTarget = queryString(xmlTrigger, "targetIdGreen");
|
||||||
if(charTarget == NULL){
|
|
||||||
printf("XMLError: No targetIdGreen found for a trigger.\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
std::string stringTarget = charTarget;
|
|
||||||
if (stringTarget.compare("-") != 0){
|
if (stringTarget.compare("-") != 0){
|
||||||
int targetIdGreen = 0, targetIdBlue = 0;
|
int targetIdGreen = queryInt(xmlTrigger, "targetIdGreen");
|
||||||
errorCheck(xmlTrigger->FirstChildElement("targetIdGreen")->QueryIntText(&targetIdGreen));
|
int targetIdBlue = queryInt(xmlTrigger, "targetIdBlue");
|
||||||
errorCheck(xmlTrigger->FirstChildElement("targetIdBlue")->QueryIntText(&targetIdBlue));
|
|
||||||
XMLElement* thisComposition = doc->FirstChildElement("composition");
|
XMLElement* thisComposition = doc->FirstChildElement("composition");
|
||||||
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
|
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
|
||||||
int thisIdGreen, thisIdBlue;
|
int thisIdGreen = queryInt(thisComposition, "idGreen");
|
||||||
errorCheck(thisComposition->FirstChildElement("idGreen")->QueryIntText(&thisIdGreen));
|
int thisIdBlue = queryInt(thisComposition, "idBlue");
|
||||||
errorCheck(thisComposition->FirstChildElement("idBlue")->QueryIntText(&thisIdBlue));
|
|
||||||
if (targetIdGreen == thisIdGreen && targetIdBlue == thisIdBlue){
|
if (targetIdGreen == thisIdGreen && targetIdBlue == thisIdBlue){
|
||||||
glm::vec3 targetPosition;
|
glm::vec3 targetPosition;
|
||||||
errorCheck(thisComposition->FirstChildElement("xPos")->QueryFloatText(&targetPosition[0]));
|
targetPosition[0] = queryFloat(thisComposition, "xPos");
|
||||||
errorCheck(thisComposition->FirstChildElement("yOffset")->QueryFloatText(&targetPosition[1]));
|
targetPosition[1] = queryFloat(thisComposition, "yOffset");
|
||||||
errorCheck(thisComposition->FirstChildElement("zPos")->QueryFloatText(&targetPosition[2]));
|
targetPosition[2] = queryFloat(thisComposition, "zPos");
|
||||||
targetPosition[1] += level->getTerrain()->getHeightmap()[int(targetPosition[0]-0.5+0.5*level->getTerrain()->getHeightmapHeight())]
|
targetPosition[1] += level->getTerrain()->getHeightmap()[int(targetPosition[0]-0.5+0.5*level->getTerrain()->getHeightmapHeight())]
|
||||||
[int(targetPosition[2]-0.5+0.5*level->getTerrain()->getHeightmapWidth())];
|
[int(targetPosition[2]-0.5+0.5*level->getTerrain()->getHeightmapWidth())];
|
||||||
position += targetPosition;
|
position += targetPosition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errorCheck(xmlTrigger->FirstChildElement("distance")->QueryFloatText(&distance));
|
float distance = queryFloat(xmlTrigger, "distance");
|
||||||
errorCheck(xmlTrigger->FirstChildElement("isBiggerThan")->QueryBoolText(&isBigger));
|
bool isBigger = queryBool(xmlTrigger, "isBiggerThan");
|
||||||
errorCheck(composition->FirstChildElement("idGreen")->QueryIntText(&idGreen));
|
int idGreen = queryInt(composition, "idGreen");
|
||||||
errorCheck(composition->FirstChildElement("idBlue")->QueryIntText(&idBlue));
|
int idBlue = queryInt(composition, "idBlue");
|
||||||
errorCheck(xmlTrigger->FirstChildElement("objectNum")->QueryIntText(&objectNum));
|
int objectNum = queryInt(xmlTrigger, "objectNum");
|
||||||
Object* object=0;
|
Object* object=0;
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
for (unsigned int i = 0; i<objectIdentifiers.size(); i++){
|
for (unsigned int i = 0; i<objectIdentifiers.size(); i++){
|
||||||
@ -404,22 +338,20 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
|||||||
printf("No index found for a trigger object while loading triggers.");
|
printf("No index found for a trigger object while loading triggers.");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
const char* charLuaScript = xmlTrigger->FirstChildElement("luaScript")->GetText();
|
std::string luaScript = queryString(xmlTrigger, "luaScript");
|
||||||
if(charLuaScript == NULL){
|
|
||||||
printf("XMLError: No Lua script found for a trigger.\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
std::string luaScript = charLuaScript;
|
|
||||||
|
|
||||||
int toChangeIdGreen, toChangeIdBlue, toChangeObjNum, objectToChange=-1;
|
int toChangeIdGreen = queryInt(xmlTrigger, "toChangeIdGreen");
|
||||||
errorCheck(xmlTrigger->FirstChildElement("toChangeIdGreen")->QueryIntText(&toChangeIdGreen));
|
int toChangeIdBlue = queryInt(xmlTrigger, "toChangeIdBlue");
|
||||||
errorCheck(xmlTrigger->FirstChildElement("toChangeIdBlue")->QueryIntText(&toChangeIdBlue));
|
int toChangeObjNum = queryInt(xmlTrigger, "toChangeObjNum");
|
||||||
errorCheck(xmlTrigger->FirstChildElement("toChangeObjNum")->QueryIntText(&toChangeObjNum));
|
int objectToChange=-1;
|
||||||
for (unsigned int i = 0; i<objectIdentifiers.size(); i++){
|
for (unsigned int i = 0; i<objectIdentifiers.size(); i++){
|
||||||
if (objectIdentifiers[i][2]==toChangeIdGreen && objectIdentifiers[i][3]==toChangeIdBlue && objectIdentifiers[i][4]==toChangeObjNum){
|
if (objectIdentifiers[i][2]==toChangeIdGreen && objectIdentifiers[i][3]==toChangeIdBlue && objectIdentifiers[i][4]==toChangeObjNum){
|
||||||
objectToChange = objectIdentifiers[i][1]; //Index in physic objects
|
objectToChange = objectIdentifiers[i][1]; //Index in physic objects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (objectToChange == -1){
|
||||||
|
printf("No Identifier found for an object that was to be changed by a trigger.\n");
|
||||||
|
}
|
||||||
if (object != 0) {
|
if (object != 0) {
|
||||||
Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, level->getLuaState(), objectToChange, scriptPath);
|
Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, level->getLuaState(), objectToChange, scriptPath);
|
||||||
level->addTrigger(trigger);
|
level->addTrigger(trigger);
|
||||||
@ -437,23 +369,22 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
|||||||
for(; composition; composition=composition->NextSiblingElement("composition")){
|
for(; composition; composition=composition->NextSiblingElement("composition")){
|
||||||
XMLElement* positionConstraint = composition->FirstChildElement("positionConstraint");
|
XMLElement* positionConstraint = composition->FirstChildElement("positionConstraint");
|
||||||
for(; positionConstraint; positionConstraint=positionConstraint->NextSiblingElement("positionConstraint")){
|
for(; positionConstraint; positionConstraint=positionConstraint->NextSiblingElement("positionConstraint")){
|
||||||
float xPos, yPos, zPos, strength;
|
float xPos = queryFloat(positionConstraint, "xPosition");
|
||||||
int objectNum=0, idGreen=0, idBlue=0, objectIndex=0;
|
float yPos = queryFloat(positionConstraint, "yPosition");
|
||||||
errorCheck(positionConstraint->FirstChildElement("xPosition")->QueryFloatText(&xPos));
|
float zPos = queryFloat(positionConstraint, "zPosition");
|
||||||
errorCheck(positionConstraint->FirstChildElement("yPosition")->QueryFloatText(&yPos));
|
float strength = queryFloat(positionConstraint, "strength");
|
||||||
errorCheck(positionConstraint->FirstChildElement("zPosition")->QueryFloatText(&zPos));
|
int objectNum = queryInt(positionConstraint, "objectNum");
|
||||||
errorCheck(positionConstraint->FirstChildElement("strength")->QueryFloatText(&strength));
|
int idGreen = queryInt(composition, "idGreen");
|
||||||
errorCheck(positionConstraint->FirstChildElement("objectNum")->QueryIntText(&objectNum));
|
int idBlue = queryInt(composition, "idBlue");
|
||||||
errorCheck(composition->FirstChildElement("idGreen")->QueryIntText(&idGreen));
|
int objectIndex;
|
||||||
errorCheck(composition->FirstChildElement("idBlue")->QueryIntText(&idBlue));
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
for (unsigned int i = 0; i<objectIdentifiers.size(); i++){
|
for (unsigned int i = 0; i<objectIdentifiers.size(); i++){
|
||||||
if (objectIdentifiers[i][2]==idGreen && objectIdentifiers[i][3]==idBlue && objectIdentifiers[i][4]==objectNum){
|
if (objectIdentifiers[i][2]==idGreen && objectIdentifiers[i][3]==idBlue && objectIdentifiers[i][4]==objectNum){
|
||||||
objectIndex = objectIdentifiers[i][1]; //Index in physic objects
|
|
||||||
if(ok){
|
if(ok){
|
||||||
printf("2 objects have the same ID while loading constraints.");
|
printf("2 objects have the same ID while loading constraints.");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
objectIndex = objectIdentifiers[i][1]; //Index in physic objects
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -480,13 +411,11 @@ glm::vec3 Loader::reloadPlayerPosition(std::string filePath, Level* level){
|
|||||||
//iterate over all compositions in Level.xml
|
//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 = queryInt(thisComposition, "typeID");
|
||||||
errorCheck(thisComposition->FirstChildElement("typeID")->QueryIntText(&thisType));
|
|
||||||
if (thisType == 20){
|
if (thisType == 20){
|
||||||
float compXPos, compYOffset, compZPos;
|
float compXPos = queryFloat(thisComposition, "xPos");
|
||||||
errorCheck(thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos));
|
float compYOffset = queryFloat(thisComposition, "yOffset");
|
||||||
errorCheck(thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset));
|
float compZPos = queryFloat(thisComposition, "zPos");
|
||||||
errorCheck(thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos));
|
|
||||||
compYOffset += level->getTerrain()->getHeightmap()[int(compXPos-0.5+0.5*level->getTerrain()->getHeightmapHeight())]
|
compYOffset += level->getTerrain()->getHeightmap()[int(compXPos-0.5+0.5*level->getTerrain()->getHeightmapHeight())]
|
||||||
[int(compZPos-0.5+0.5*level->getTerrain()->getHeightmapWidth())];
|
[int(compZPos-0.5+0.5*level->getTerrain()->getHeightmapWidth())];
|
||||||
glm::vec3 position = glm::vec3(compXPos, compYOffset, compZPos);
|
glm::vec3 position = glm::vec3(compXPos, compYOffset, compZPos);
|
||||||
|
Loading…
Reference in New Issue
Block a user