Added the option to define initial position constraints in the Level.xml file.

This commit is contained in:
Steffen 2015-01-17 14:07:12 +01:00
parent 10017bb855
commit d26722595e
2 changed files with 49 additions and 7 deletions

View File

@ -98,14 +98,32 @@ Converter::Converter(std::string level){
//Create global physics parameters
XMLElement* physics = doc->NewElement("physics");
XMLElement* friction = doc->NewElement("friction");
XMLElement* strength = doc->NewElement("strength");
friction->SetText("0.9");
strength->SetText("100.0");
physics->InsertEndChild(friction);
physics->InsertEndChild(strength);
XMLElement* playerFriction = doc->NewElement("friction");
XMLElement* playerStrength = doc->NewElement("strength");
playerFriction->SetText("0.9");
playerStrength->SetText("100.0");
physics->InsertEndChild(playerFriction);
physics->InsertEndChild(playerStrength);
doc->InsertEndChild(physics);
//create positionConstraint Dummy
XMLElement* positionConstraint = doc->NewElement("positionConstraint");
XMLElement* positionConstraintObjectNum = doc->NewElement("objectNum");
XMLElement* positionConstraintXPos = doc->NewElement("xPosition");
XMLElement* positionConstraintYPos = doc->NewElement("yPosition");
XMLElement* positionConstraintZPos = doc->NewElement("zPosition");
XMLElement* positionConstraintStrength = doc->NewElement("strength");
positionConstraintObjectNum->SetText("0");
positionConstraintXPos->SetText("0.0");
positionConstraintYPos->SetText("0.0");
positionConstraintZPos->SetText("0.0");
positionConstraintStrength->SetText("100.0");
positionConstraint->InsertEndChild(positionConstraintObjectNum);
positionConstraint->InsertEndChild(positionConstraintXPos);
positionConstraint->InsertEndChild(positionConstraintYPos);
positionConstraint->InsertEndChild(positionConstraintZPos);
positionConstraint->InsertEndChild(positionConstraintStrength);
doc->InsertEndChild(positionConstraint);
}else{
dst << src.rdbuf();
XMLElement* thisComposition = doc->FirstChildElement("composition");

View File

@ -387,7 +387,31 @@ void Level::load() {
}
}
}
}
}//triggers
//load positionConstraints
composition = doc->FirstChildElement("composition");
for(; composition; composition=composition->NextSiblingElement("composition")){
XMLElement* positionConstraint = composition->FirstChildElement("positionConstraint");
for(; positionConstraint; positionConstraint=positionConstraint->NextSiblingElement("positionConstraint")){
float xPos, yPos, zPos, strength;
int objectNum, idGreen, idBlue, objectIndex;
errorCheck(positionConstraint->FirstChildElement("xPosition")->QueryFloatText(&xPos));
errorCheck(positionConstraint->FirstChildElement("yPosition")->QueryFloatText(&yPos));
errorCheck(positionConstraint->FirstChildElement("zPosition")->QueryFloatText(&zPos));
errorCheck(positionConstraint->FirstChildElement("strength")->QueryFloatText(&strength));
errorCheck(positionConstraint->FirstChildElement("objectNum")->QueryIntText(&objectNum));
errorCheck(composition->FirstChildElement("idGreen")->QueryIntText(&idGreen));
errorCheck(composition->FirstChildElement("idBlue")->QueryIntText(&idBlue));
for (unsigned int i = 0; i<objectIdentifiers.size(); i++){
if (objectIdentifiers[i][1]==idGreen && objectIdentifiers[i][2]==idBlue && objectIdentifiers[i][3]==objectNum){
objectIndex = objectIdentifiers[i][0];
}
}
glm::vec3 position = glm::vec3(xPos, yPos, zPos);
physics.addPositionConstraint(objectIndex, strength, position);
}
}//positionConstraints
}
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,