Added resetPlayer function to the level.

This commit is contained in:
Steffen Fündgens 2015-02-13 17:14:29 +01:00
parent 3fc8e9c11a
commit 265c0b2ce5
7 changed files with 52 additions and 7 deletions

View File

@ -1,7 +1,7 @@
<!-- Rotations around the three axes are given in degrees. <!-- Rotations around the three axes are given in degrees.
The objects are first rotated around the z-, then y- and then x-axis. --> The objects are first rotated around the z-, then y- and then x-axis. -->
<!-- Marble --> <!-- Marble: Do not change!(except for mass)-->
<composition> <composition>
<typeID>20</typeID> <typeID>20</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
@ -415,7 +415,7 @@
<yRot>0.0</yRot> <yRot>0.0</yRot>
<zRot>0.0</zRot> <zRot>0.0</zRot>
<scale>1.5</scale> <scale>1.5</scale>
<mass>0.0</mass> <mass>100.0</mass>
</object> </object>
</composition> </composition>

View File

@ -14,7 +14,8 @@ void Application::init()
std::srand(std::time(NULL)); std::srand(std::time(NULL));
// choose Level TODO: Choose this in a menu // choose Level TODO: Choose this in a menu
std::string heightmapFilePath = heightmapPath + "heightmapLvl1.png"; std::string heightmapFilePath = heightmapPath + "heightmapLvl1.png";
this->level = Level(heightmapFilePath); std::string levelXmlFilePath = levelXmlPath + "Level1.xml";
this->level = Level(heightmapFilePath, levelXmlFilePath);
level.getPhysics()->init(geometryPath); level.getPhysics()->init(geometryPath);
// Don't change this! // Don't change this!
ignoredMouseUpdates = 0; ignoredMouseUpdates = 0;
@ -31,7 +32,7 @@ void Application::init()
// load Level // load Level
level.load(); level.load();
Loader loader = Loader(); Loader loader = Loader();
std::string levelXmlFilePath = levelXmlPath + "Level1.xml";
loader.load(levelXmlFilePath, &level, compositionsPath, scriptPath); loader.load(levelXmlFilePath, &level, compositionsPath, scriptPath);
graphics.init(&level); graphics.init(&level);

View File

@ -1,11 +1,13 @@
#include "level.hh" #include "level.hh"
#include "loader.hh"
#include <string> #include <string>
Level::Level(std::string heightmapFilePath){ Level::Level(std::string heightmapFilePath, std::string xmlFilePath){
this->terrain = Terrain(heightmapFilePath); this->terrain = Terrain(heightmapFilePath);
// default value // default value
skydomeSize = 50.0f; skydomeSize = 50.0f;
physics = Physics(); physics = Physics();
this->xmlFilePath = xmlFilePath;
} }
Level::Level() { Level::Level() {
@ -162,6 +164,12 @@ void Level::deleteObject(int objectIndex){
} }
} }
void Level::resetPlayer(){
Loader loader = Loader();
glm::vec3 newPosition = loader.reloadPlayerPosition(xmlFilePath, this);
//TODO cameraCenter.setPosition(newPosition);
}
void Level::setStrength(float strength) { void Level::setStrength(float strength) {
this->strength = strength; this->strength = strength;
} }

View File

@ -20,7 +20,7 @@ extern "C" {
class Level { class Level {
public: public:
Level(std::string heightmapFilePath); Level(std::string heightmapFilePath, std::string xmlFilePath);
Level(); Level();
~Level(); ~Level();
void load(); void load();
@ -55,6 +55,7 @@ class Level {
void addTrigger(Trigger trigger); void addTrigger(Trigger trigger);
lua_State* getLuaState(); lua_State* getLuaState();
Terrain* getTerrain(); Terrain* getTerrain();
void resetPlayer();
private: private:
lua_State* luaState=nullptr; lua_State* luaState=nullptr;
std::vector<Object*> objects; std::vector<Object*> objects;
@ -71,6 +72,7 @@ class Level {
Terrain terrain; Terrain terrain;
float skydomeSize; float skydomeSize;
float strength; float strength;
std::string xmlFilePath;
}; };
#endif #endif

View File

@ -507,6 +507,38 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
}//positionConstraints }//positionConstraints
} }
glm::vec3 Loader::reloadPlayerPosition(std::string filePath, Level* level){
XMLDocument* doc = new XMLDocument();
const char* xmlFile = filePath.c_str();
doc->LoadFile(xmlFile);
if (doc->ErrorID()!=0){
printf("Could not open ObjectSetupXml!\n");
exit(-1);
}
//iterate over all compositions in Level.xml
XMLElement* thisComposition = doc->FirstChildElement("composition");
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
int thisType = 0;
errorCheck(thisComposition->FirstChildElement("typeID")->QueryIntText(&thisType));
if (thisType == 20){
float compXPos, compYOffset, compZPos;
errorCheck(thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos));
errorCheck(thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset));
errorCheck(thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos));
compYOffset += level->getTerrain()->getHeightmap()[int(compXPos-0.5+0.5*level->getTerrain()->getHeightmapHeight())]
[int(compZPos-0.5+0.5*level->getTerrain()->getHeightmapWidth())];
glm::vec3 position = glm::vec3(compXPos, compYOffset, compZPos);
return position;
}
}
printf("Level.xml contains no player.");
exit(-1);
}
void Loader::errorCheck(XMLError error){ void Loader::errorCheck(XMLError error){
if (error) { if (error) {
printf("XMLError: "); printf("XMLError: ");

View File

@ -7,8 +7,9 @@
class Loader { class Loader {
public: public:
Loader(); Loader();
void load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath);
void loadConfig(Application* application); void loadConfig(Application* application);
void load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath);
glm::vec3 reloadPlayerPosition(std::string filePath, Level* level);
private: private:
void errorCheck(tinyxml2::XMLError error); void errorCheck(tinyxml2::XMLError error);
}; };

View File

@ -82,6 +82,7 @@ void Terrain::makeTriangleMesh(){
} }
ab->setDataElements(numVertices, abData); ab->setDataElements(numVertices, abData);
delete abData;
this->triangleMesh = std::make_shared<ACGL::OpenGL::VertexArrayObject>(); this->triangleMesh = std::make_shared<ACGL::OpenGL::VertexArrayObject>();
this->triangleMesh->bind(); this->triangleMesh->bind();
this->triangleMesh->setMode(GL_TRIANGLE_STRIP); this->triangleMesh->setMode(GL_TRIANGLE_STRIP);