Added resetPlayer function to the level.
This commit is contained in:
parent
3fc8e9c11a
commit
265c0b2ce5
@ -1,7 +1,7 @@
|
||||
<!-- Rotations around the three axes are given in degrees.
|
||||
The objects are first rotated around the z-, then y- and then x-axis. -->
|
||||
|
||||
<!-- Marble -->
|
||||
<!-- Marble: Do not change!(except for mass)-->
|
||||
<composition>
|
||||
<typeID>20</typeID>
|
||||
<ignoreHeightmap>false</ignoreHeightmap>
|
||||
@ -415,7 +415,7 @@
|
||||
<yRot>0.0</yRot>
|
||||
<zRot>0.0</zRot>
|
||||
<scale>1.5</scale>
|
||||
<mass>0.0</mass>
|
||||
<mass>100.0</mass>
|
||||
</object>
|
||||
</composition>
|
||||
|
||||
|
@ -14,7 +14,8 @@ void Application::init()
|
||||
std::srand(std::time(NULL));
|
||||
// choose Level TODO: Choose this in a menu
|
||||
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);
|
||||
// Don't change this!
|
||||
ignoredMouseUpdates = 0;
|
||||
@ -31,7 +32,7 @@ void Application::init()
|
||||
// load Level
|
||||
level.load();
|
||||
Loader loader = Loader();
|
||||
std::string levelXmlFilePath = levelXmlPath + "Level1.xml";
|
||||
|
||||
loader.load(levelXmlFilePath, &level, compositionsPath, scriptPath);
|
||||
graphics.init(&level);
|
||||
|
||||
|
10
level.cc
10
level.cc
@ -1,11 +1,13 @@
|
||||
#include "level.hh"
|
||||
#include "loader.hh"
|
||||
#include <string>
|
||||
|
||||
Level::Level(std::string heightmapFilePath){
|
||||
Level::Level(std::string heightmapFilePath, std::string xmlFilePath){
|
||||
this->terrain = Terrain(heightmapFilePath);
|
||||
// default value
|
||||
skydomeSize = 50.0f;
|
||||
physics = Physics();
|
||||
this->xmlFilePath = xmlFilePath;
|
||||
}
|
||||
|
||||
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) {
|
||||
this->strength = strength;
|
||||
}
|
||||
|
4
level.hh
4
level.hh
@ -20,7 +20,7 @@ extern "C" {
|
||||
|
||||
class Level {
|
||||
public:
|
||||
Level(std::string heightmapFilePath);
|
||||
Level(std::string heightmapFilePath, std::string xmlFilePath);
|
||||
Level();
|
||||
~Level();
|
||||
void load();
|
||||
@ -55,6 +55,7 @@ class Level {
|
||||
void addTrigger(Trigger trigger);
|
||||
lua_State* getLuaState();
|
||||
Terrain* getTerrain();
|
||||
void resetPlayer();
|
||||
private:
|
||||
lua_State* luaState=nullptr;
|
||||
std::vector<Object*> objects;
|
||||
@ -71,6 +72,7 @@ class Level {
|
||||
Terrain terrain;
|
||||
float skydomeSize;
|
||||
float strength;
|
||||
std::string xmlFilePath;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
32
loader.cc
32
loader.cc
@ -507,6 +507,38 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
||||
}//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){
|
||||
if (error) {
|
||||
printf("XMLError: ");
|
||||
|
@ -7,8 +7,9 @@
|
||||
class Loader {
|
||||
public:
|
||||
Loader();
|
||||
void load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath);
|
||||
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:
|
||||
void errorCheck(tinyxml2::XMLError error);
|
||||
};
|
||||
|
@ -82,6 +82,7 @@ void Terrain::makeTriangleMesh(){
|
||||
}
|
||||
|
||||
ab->setDataElements(numVertices, abData);
|
||||
delete abData;
|
||||
this->triangleMesh = std::make_shared<ACGL::OpenGL::VertexArrayObject>();
|
||||
this->triangleMesh->bind();
|
||||
this->triangleMesh->setMode(GL_TRIANGLE_STRIP);
|
||||
|
Loading…
Reference in New Issue
Block a user