-
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
b32fe46
commit 86812ff
Showing
20 changed files
with
4,055 additions
and
6,196 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 |
---|---|---|
|
@@ -8,4 +8,5 @@ engine/CMakeFiles/* | |
.idea/* | ||
.vscode/* | ||
generator/generator | ||
engine/engine | ||
engine/engine | ||
build |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef CAMERA_HPP | ||
#define CAMERA_HPP | ||
|
||
#include <string> | ||
|
||
#include "Camera.hpp" | ||
#include "utils.hpp" | ||
|
||
class Camera { | ||
public: | ||
Point position; | ||
Point lookAt; | ||
Point up; | ||
int fov; | ||
float near; | ||
float far; | ||
|
||
Camera(); | ||
Camera(Point position, Point lookAt, Point up, int fov, float near, | ||
float far); | ||
|
||
std::string toString(); | ||
}; | ||
|
||
#endif // CAMERA_HPP |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef CONFIGURATION_HPP | ||
#define CONFIGURATION_HPP | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "Camera.hpp" | ||
#include "Configuration.hpp" | ||
#include "Window.hpp" | ||
|
||
class Configuration { | ||
public: | ||
Window window; | ||
Camera camera; | ||
std::vector<std::string> models; | ||
Configuration() = default; | ||
Configuration(Window window, Camera camera, std::vector<std::string> models); | ||
|
||
std::string toString(); | ||
}; | ||
|
||
#endif // CONFIGURATION_HPP |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef WINDOW_HPP | ||
#define WINDOW_HPP | ||
|
||
#include <string> | ||
|
||
#include "Window.hpp" | ||
|
||
class Window { | ||
public: | ||
float width; | ||
float height; | ||
|
||
Window(); | ||
Window(float width, float height); | ||
|
||
std::string toString(); | ||
}; | ||
|
||
#endif // WINDOW_HPP |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef PARSE_HPP | ||
#define PARSE_HPP | ||
|
||
#include <string> | ||
|
||
#include "../../lib/rapidxml-1.13/rapidxml.hpp" | ||
#include "Configuration.hpp" | ||
#include "parse.hpp" | ||
|
||
Configuration parseConfig(std::string filename); | ||
|
||
#endif // PARSE_HPP |
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "Camera.hpp" | ||
|
||
#include <sstream> | ||
#include <string> | ||
|
||
Camera::Camera() { | ||
this->position = Point(); | ||
this->lookAt = Point(); | ||
this->up = Point(); | ||
this->fov = 0; | ||
this->near = 0; | ||
this->far = 0; | ||
} | ||
|
||
Camera::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; | ||
} | ||
|
||
std::string Camera::toString() { | ||
std::stringstream ss; | ||
ss << "\tPosition: " << position.toString() << std::endl | ||
<< "\tLookAt: " << lookAt.toString() << std::endl | ||
<< "\tUp: " << up.toString() << std::endl | ||
<< "\tFOV: " << std::to_string(fov).c_str() << std::endl | ||
<< "\tNear: " << std::to_string(near).c_str() << std::endl | ||
<< "\tFar: " << std::to_string(far).c_str() << std::endl; | ||
return ss.str(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "Configuration.hpp" | ||
|
||
#include <sstream> | ||
#include <string> | ||
|
||
Configuration::Configuration(Window window, Camera camera, | ||
std::vector<std::string> models) { | ||
this->window = window; | ||
this->camera = camera; | ||
this->models = models; | ||
} | ||
|
||
std::string vectorToString(std::vector<std::string> v) { | ||
std::stringstream ss; | ||
for (auto i : v) { | ||
ss << i << " "; | ||
} | ||
return ss.str(); | ||
} | ||
|
||
std::string Configuration::toString() { | ||
std::stringstream ss; | ||
ss << "Window:\n" | ||
<< window.toString() << std::endl | ||
<< "Camera:\n" | ||
<< camera.toString() << std::endl | ||
<< "Models: " << vectorToString(models) << std::endl; | ||
return ss.str(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "Window.hpp" | ||
|
||
#include <sstream> | ||
#include <string> | ||
|
||
Window::Window() { | ||
this->width = 0; | ||
this->height = 0; | ||
} | ||
|
||
Window::Window(float width, float height) { | ||
this->width = width; | ||
this->height = height; | ||
} | ||
|
||
std::string Window::toString() { | ||
std::stringstream ss; | ||
ss << "\tWidth: " << width << std::endl | ||
<< "\tHeight: " << height << std::endl; | ||
return ss.str(); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "parse.hpp" | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
|
||
Configuration parseConfig(std::string filename) { | ||
// open file in read mode | ||
std::ifstream file(filename); | ||
|
||
// 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<std::string> 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(std::string(model->first_attribute("file")->value())); | ||
} | ||
|
||
return Configuration(window_info, camera_info, models_info); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<world> | ||
<window width="512" height="512" /> <!-- gluPerspective Ratio --> | ||
<camera> | ||
<position x="5" y="5" z="5" /> <!-- gluLookAt eye --> | ||
<lookAt x="0" y="0" z="0" /> <!-- gluLookAt center--> | ||
<up x="0" y="1" z="0" /> <!-- gluLookAt up--> | ||
<projection fov="60" near="1" far="1000" /> <!--gluPerspective--> | ||
</camera> | ||
<group> | ||
<models> | ||
<model file="cone.3d" /> | ||
<model file="sphere.3d" /> <!-- generator cone 1 2 4 3 cone.3d --> | ||
</models> | ||
</group> | ||
</world> |
Oops, something went wrong.