This commit is contained in:
sfroitzheim 2014-12-05 14:51:23 +01:00
commit 3268881a13
11 changed files with 4476 additions and 29 deletions

View File

@ -1,7 +1,7 @@
<composition>
<typeID>20</typeID>
<object>
<filePath>../Levels/Geometry/MarbleSmooth.obj</filePath>
<modelPath>MarbleSmooth.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>0.0</yOffset>
<zOffset>0.0</zOffset>
@ -12,7 +12,7 @@
<composition>
<typeID>40</typeID>
<object>
<filePath>../Levels/Geometry/Block.obj</filePath>
<modelPath>Block.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>1.0</yOffset>
<zOffset>2.0</zOffset>
@ -23,7 +23,7 @@
<composition>
<typeID>60</typeID>
<object>
<filePath>../Levels/Geometry/Column.obj</filePath>
<modelPath>Column.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>0.0</yOffset>
<zOffset>0.0</zOffset>
@ -34,35 +34,62 @@
<composition>
<typeID>80</typeID>
<object>
<filePath>../Levels/Geometry/torch.obj</filePath>
<modelPath>torch.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>0.0</yOffset>
<zOffset>0.0</zOffset>
<scale>1.0</scale>
</object>
<light>
<xOffset>0.0</xOffset>
<yOffset>1.0</yOffset>
<zOffset>0.0</zOffset>
<rColour>1.0</rColour>
<gColour>1.0</gColour>
<bColour>1.0</bColour>
<intensity>5.0</intensity>
</light>
</composition>
<composition>
<typeID>100</typeID>
<typeID>99</typeID>
<object>
<filePath>../Levels/Geometry/Column.obj</filePath>
<modelPath>Column.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>0.0</yOffset>
<zOffset>0.0</zOffset>
<scale>1.0</scale>
</object>
<object>
<filePath>../Levels/Geometry/Column.obj</filePath>
<modelPath>Column.obj</modelPath>
<xOffset>2.0</xOffset>
<yOffset>0.0</yOffset>
<zOffset>0.0</zOffset>
<scale>1.0</scale>
</object>
<object>
<filePath>../Levels/Geometry/Block.obj</filePath>
<modelPath>Block.obj</modelPath>
<xOffset>1.0</xOffset>
<yOffset>3.0</yOffset>
<zOffset>0.0</zOffset>
<scale>1.0</scale>
</object>
</composition>
<composition>
<typeID>120</typeID>
<object>
<modelPath>switch_inner.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>0.0</yOffset>
<zOffset>0.0</zOffset>
<scale>1.0</scale>
</object>
<object>
<modelPath>switch_outer.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>0.0</yOffset>
<zOffset>0.0</zOffset>
<scale>1.0</scale>
</object>
</composition>

View File

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -7,6 +7,8 @@ Application::Application() {
void Application::init()
{
// choose Level TODO: Choose this in a menu
this->level = Level("0");
// Don't change this!
ignoredMouseUpdates = 0;
cameraLock = true;

View File

@ -30,7 +30,7 @@ Converter::Converter(std::string level){
}else{
XMLElement* thisComposition = doc->FirstChildElement("composition");
int idGreen, idBlue;
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement()){
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
thisComposition->QueryIntAttribute("idGreen", &idGreen);
thisComposition->QueryIntAttribute("idBlue", &idBlue);
if(idGreen > nextID[0] || (idGreen == nextID[0] && idBlue > nextID[1])){
@ -96,7 +96,7 @@ std::vector<unsigned int> Converter::newComposition(unsigned int type, float pos
void Converter::updateComposition(unsigned int idG, unsigned int idB, float posX, float posZ){
XMLElement* thisComposition = doc->FirstChildElement("composition");
int idGreen, idBlue;
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement()){
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
thisComposition->QueryIntAttribute("idGreen", &idGreen);
thisComposition->QueryIntAttribute("idBlue", &idBlue);
if(idGreen == idG && idBlue == idB){
@ -109,7 +109,7 @@ void Converter::updateComposition(unsigned int idG, unsigned int idB, float posX
void Converter::deleteComposition(unsigned int idG, unsigned int idB){
XMLElement* thisComposition = doc->FirstChildElement("composition");
int idGreen, idBlue;
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement()){
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
thisComposition->QueryIntAttribute("idGreen", &idGreen);
thisComposition->QueryIntAttribute("idBlue", &idBlue);
if(idGreen == idG && idBlue == idB){
@ -129,7 +129,7 @@ std::vector<unsigned int> Converter::getNextID(){
/* finding a typeID in compositions:
XMLElement* thisComposition = compositions->FirstChildElement("composition");
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement()){
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
int thisType;
thisComposition->QueryIntAttribute("typeID", &thisType);
if(thisType == type){

View File

@ -1,10 +1,10 @@
#include "level.hh"
using namespace tinyxml2;
Level::Level(std::string filePath){
this->filePath = filePath;
this->terrain = Terrain(filePath + "/terrain");
Level::Level(std::string levelNum){
this->levelNum = levelNum;
this->terrain = Terrain(levelNum);
skydomeSize = 50.0f;
}
@ -17,18 +17,87 @@ Level::~Level() {
}
}
void Level::load() {
void Level::errorCheck(XMLError error){
if (error) {
printf("XMLError: ");
if (error == XML_WRONG_ATTRIBUTE_TYPE) {
printf("Wrong attribute type.\n");
}
else if (error == XML_NO_ATTRIBUTE) {
printf("No attribute.\n");
}
else if (error == XML_CAN_NOT_CONVERT_TEXT) {
printf("Can not convert text.\n");
}
else if (error == XML_NO_TEXT_NODE) {
printf("No text.\n");
}
else {
printf("Unknown error.\n");
}
}
}
void Level::load() {
XMLError error=XML_NO_ERROR;
this->physics = Physics();
this->physics.init();
// currently hard coded should later read this stuff out of a file
this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f);
//Loading Objects via xml:
XMLDocument* doc = new XMLDocument();
const char* xmlFile = ("../Levels/ObjectSetups/Level" + levelNum + ".xml").c_str();
doc->LoadFile(xmlFile);
if (doc->ErrorID()!=0){
printf("Could not open ObjectSetupXml!\n");
exit(-1);
}
XMLDocument* compositions = new XMLDocument();
const char* compositionsFile = "../Levels/ObjectSetups/Compositions.xml";
compositions->LoadFile(compositionsFile);
if (compositions->ErrorID()!=0){
printf("Could not open Compositions!\n");
exit(-1);
}
XMLElement* thisComposition = doc->FirstChildElement("composition");
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
int thisType = 0;
error = thisComposition->FirstChildElement("typeID")->QueryIntText(&thisType);
errorCheck(error);
XMLElement* compositionType = compositions->FirstChildElement("composition");
for(; compositionType; compositionType=compositionType->NextSiblingElement("composition")){
int compositionID = 0;
error = compositionType->FirstChildElement("typeID")->QueryIntText(&compositionID);
errorCheck(error);
if(thisType == compositionID){
XMLElement* object = compositionType->FirstChildElement("object");
for(; object; object=object->NextSiblingElement("object")){
const char* charModelPath = object->FirstChildElement("modelPath")->GetText();
if(charModelPath == NULL){
printf("XMLError: No modelPath found.\n");
}
std::string modelPath = charModelPath;
float scale;
object->FirstChildElement("scale")->QueryFloatText(&scale);
Model model = Model(modelPath, scale);
}
XMLElement* light = compositionType->FirstChildElement("light");
for(; light; light=light->NextSiblingElement("light")){
}
}
}
}
//add player
Model model = Model("MarbleSmooth.obj", 0.75f);
Material material = Material("marbleTexture_small.png", 0.1f, 0.5f, 0.5f, 3.0f);
Object* object = new Object(model, material, glm::vec3(2.0f, 10.0f, 2.0f),
Model marbleModel = Model("MarbleSmooth.obj", 0.75f);
Material marbleMaterial = Material("marbleTexture_small.png", 0.1f, 0.5f, 0.5f, 3.0f);
Object* object = new Object(marbleModel, marbleMaterial, glm::vec3(2.0f, 10.0f, 2.0f),
glm::vec3(0.0f, 0.0f, 0.0f));
objects.push_back(object);
physicObjects.push_back(object);

View File

@ -9,10 +9,11 @@
#include "material.hh"
#include "camera.hh"
#include "physics.hh"
#include "tinyxml2.hh"
class Level {
public:
Level(std::string filePath);
Level(std::string levelNum);
Level();
~Level();
void load();
@ -27,7 +28,8 @@ class Level {
glm::vec4 getFogColor();
void setSkydomeSize(float size);
private:
std::string filePath;
void errorCheck(tinyxml2::XMLError error);
std::string levelNum;
std::vector<Object*> objects;
std::vector<Object*> physicObjects;
std::vector<Light> lights;

View File

@ -1,8 +1,8 @@
#include "terrain.hh"
#include "lodepng.h"
Terrain::Terrain(std::string filePath){
this->filePath = filePath;
Terrain::Terrain(std::string levelNum){
this->levelNum = levelNum;
}
Terrain::Terrain(){
@ -13,10 +13,8 @@ Terrain::~Terrain() {
void Terrain::load() {
filePath = "../Levels/heightmapLvlTest.png"; //TODO remove this, its only for testing
std::vector<unsigned char> image; //the raw pixels
unsigned error = lodepng::decode(image, heightmapWidth, heightmapHeight, filePath);
unsigned error = lodepng::decode(image, heightmapWidth, heightmapHeight, "../Levels/heightmapLvl" + levelNum + ".png");
if (error) {
std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl;
}

View File

@ -7,7 +7,7 @@
#include "model.hh"
class Terrain {
public:
Terrain(std::string filePath);
Terrain(std::string levelNum);
Terrain();
~Terrain();
void load();
@ -19,7 +19,7 @@ class Terrain {
private:
Material material;
std::string filePath;
std::string levelNum;
unsigned int heightmapHeight, heightmapWidth;
float** heightmap; //can be accessed like 'float[][]'
bool heightmapChanged;

2258
tinyxml2.cc Executable file

File diff suppressed because it is too large Load Diff

2091
tinyxml2.hh Executable file

File diff suppressed because it is too large Load Diff