-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63afb72
commit ae699ad
Showing
8 changed files
with
3,097 additions
and
3,297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
#include "utils.hpp" | ||
|
||
class Camera { | ||
public: | ||
Point position; | ||
Point lookAt; | ||
Point up; | ||
int fov; | ||
float near; | ||
float far; | ||
public: | ||
Point position; | ||
Point lookAt; | ||
Point up; | ||
int fov; | ||
float near; | ||
float far; | ||
|
||
Camera() { | ||
this->position = Point(); | ||
this->lookAt = Point(); | ||
this->up = Point(); | ||
this->fov = 0; | ||
this->near = 0; | ||
this->far = 0; | ||
} | ||
Camera() { | ||
this->position = Point(); | ||
this->lookAt = Point(); | ||
this->up = Point(); | ||
this->fov = 0; | ||
this->near = 0; | ||
this->far = 0; | ||
} | ||
|
||
Camera(Point position, Point lookAt, Point up, int fov, float near, float far) { | ||
this->position = position; | ||
this->lookAt = lookAt; | ||
this->up = up; | ||
this->fov = fov; | ||
this->near = near; | ||
this->far = far; | ||
} | ||
Camera(Point position, Point lookAt, Point up, int fov, float near, | ||
float far) { | ||
this->position = position; | ||
this->lookAt = lookAt; | ||
this->up = up; | ||
this->fov = fov; | ||
this->near = near; | ||
this->far = far; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
#include "Window.cpp" | ||
#include "Camera.cpp" | ||
#include "Window.cpp" | ||
|
||
class Configuration { | ||
public: | ||
Window window; | ||
Camera camera; | ||
std::vector<char*> models; | ||
public: | ||
Window window; | ||
Camera camera; | ||
std::vector<char*> models; | ||
|
||
Configuration(Window window, Camera camera, std::vector<char*> models) { | ||
this->window = window; | ||
this->camera = camera; | ||
this->models = models; | ||
} | ||
Configuration(Window window, Camera camera, std::vector<char*> models) { | ||
this->window = window; | ||
this->camera = camera; | ||
this->models = models; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
class Window { | ||
public: | ||
float width; | ||
float height; | ||
public: | ||
float width; | ||
float height; | ||
|
||
Window() { | ||
this->width = 0; | ||
this->height = 0; | ||
} | ||
Window() { | ||
this->width = 0; | ||
this->height = 0; | ||
} | ||
|
||
Window(float width, float height) { | ||
this->width = width; | ||
this->height = height; | ||
} | ||
Window(float width, float height) { | ||
this->width = width; | ||
this->height = height; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,74 @@ | ||
#include "Configuration.cpp" | ||
#include "Camera.cpp" | ||
#include "Window.cpp" | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
|
||
#include "utils.hpp" | ||
#include <iostream> | ||
|
||
#include "../../lib/rapidxml-1.13/rapidxml.hpp" | ||
#include "Camera.cpp" | ||
#include "Configuration.cpp" | ||
#include "Window.cpp" | ||
#include "utils.hpp" | ||
|
||
Configuration parseConfig(char* filename) { | ||
// open file in read mode | ||
std::fstream file; | ||
file.open(filename, std::ios::in); | ||
|
||
// check if the file was opened successfully | ||
if (!file.is_open()) { | ||
std::cerr << "Error opening the file!" << std::endl; | ||
exit(1); | ||
} | ||
|
||
// read the XML file content into a string | ||
std::string xmlContent((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); | ||
file.close(); | ||
|
||
// parse the XML string using RapidXML | ||
rapidxml::xml_document<> doc; | ||
doc.parse<0>(&xmlContent[0]); | ||
|
||
// access the root node | ||
rapidxml::xml_node<>* root = doc.first_node("world"); | ||
|
||
// window information | ||
char* width = root->first_node("window")->first_attribute("width")->value(); | ||
char* height = root->first_node("window")->first_attribute("height")->value(); | ||
|
||
Window window_info = Window(std::stof(width), std::stof(height)); | ||
|
||
// camera information | ||
rapidxml::xml_node<>* camera = root->first_node("camera"); | ||
|
||
rapidxml::xml_node<>* position = camera->first_node("position"); | ||
Point position = Point( | ||
std::stof(position->first_attribute("x")->value()), | ||
std::stof(position->first_attribute("y")->value()), | ||
std::stof(position->first_attribute("z")->value()) | ||
); | ||
|
||
rapidxml::xml_node<>* lookAt = camera->first_node("lookAt"); | ||
Point lookAt = Point( | ||
std::stof(lookAt->first_attribute("x")->value()), | ||
std::stof(lookAt->first_attribute("y")->value()), | ||
std::stof(lookAt->first_attribute("z")->value()) | ||
); | ||
|
||
rapidxml::xml_node<>* up = camera->first_node("up"); | ||
Point up = Point( | ||
std::stof(up->first_attribute("x")->value()), | ||
std::stof(up->first_attribute("y")->value()), | ||
std::stof(up->first_attribute("z")->value()) | ||
); | ||
|
||
rapidxml::xml_node<>* projection = camera->first_node("projection"); | ||
int fov = std::stoi(projection->first_attribute("fov")->value()); | ||
float near = std::stof(projection->first_attribute("near")->value()); | ||
float far = std::stof(projection->first_attribute("far")->value()); | ||
|
||
Camera camera_info = Camera(position, lookAt, up, fov, near, far); | ||
|
||
// models | ||
std::vector<char*> models_info; | ||
rapidxml::xml_node<>* models = root->first_node("group")->first_node("models"); | ||
for (rapidxml::xml_node<>* model = models->first_node("model"); model; model = model->next_sibling("model")) { | ||
models_info.push_back(model->first_attribute("file")->value()); | ||
} | ||
|
||
return Configuration(window_info, camera_info, models_info); | ||
// open file in read mode | ||
std::fstream file; | ||
file.open(filename, std::ios::in); | ||
|
||
// check if the file was opened successfully | ||
if (!file.is_open()) { | ||
std::cerr << "Error opening the file!" << std::endl; | ||
exit(1); | ||
} | ||
|
||
// read the XML file content into a string | ||
std::string xmlContent((std::istreambuf_iterator<char>(file)), | ||
std::istreambuf_iterator<char>()); | ||
file.close(); | ||
|
||
// parse the XML string using RapidXML | ||
rapidxml::xml_document<> doc; | ||
doc.parse<0>(&xmlContent[0]); | ||
|
||
// access the root node | ||
rapidxml::xml_node<>* root = doc.first_node("world"); | ||
|
||
// window information | ||
char* width = root->first_node("window")->first_attribute("width")->value(); | ||
char* height = root->first_node("window")->first_attribute("height")->value(); | ||
|
||
Window window_info = Window(std::stof(width), std::stof(height)); | ||
|
||
// camera information | ||
rapidxml::xml_node<>* camera = root->first_node("camera"); | ||
|
||
rapidxml::xml_node<>* position_n = camera->first_node("position"); | ||
Point position = Point(std::stof(position_n->first_attribute("x")->value()), | ||
std::stof(position_n->first_attribute("y")->value()), | ||
std::stof(position_n->first_attribute("z")->value())); | ||
|
||
rapidxml::xml_node<>* lookAt_n = camera->first_node("lookAt"); | ||
Point lookAt = Point(std::stof(lookAt_n->first_attribute("x")->value()), | ||
std::stof(lookAt_n->first_attribute("y")->value()), | ||
std::stof(lookAt_n->first_attribute("z")->value())); | ||
|
||
rapidxml::xml_node<>* up_n = camera->first_node("up"); | ||
Point up = Point(std::stof(up_n->first_attribute("x")->value()), | ||
std::stof(up_n->first_attribute("y")->value()), | ||
std::stof(up_n->first_attribute("z")->value())); | ||
|
||
rapidxml::xml_node<>* projection = camera->first_node("projection"); | ||
int fov = std::stoi(projection->first_attribute("fov")->value()); | ||
float near = std::stof(projection->first_attribute("near")->value()); | ||
float far = std::stof(projection->first_attribute("far")->value()); | ||
|
||
Camera camera_info = Camera(position, lookAt, up, fov, near, far); | ||
|
||
// models | ||
std::vector<char*> models_info; | ||
rapidxml::xml_node<>* models = | ||
root->first_node("group")->first_node("models"); | ||
for (rapidxml::xml_node<>* model = models->first_node("model"); model; | ||
model = model->next_sibling("model")) { | ||
models_info.push_back(model->first_attribute("file")->value()); | ||
} | ||
|
||
return Configuration(window_info, camera_info, models_info); | ||
} |
Oops, something went wrong.