Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
diogogmatos committed Mar 2, 2024
1 parent 63afb72 commit ae699ad
Show file tree
Hide file tree
Showing 8 changed files with 3,097 additions and 3,297 deletions.
47 changes: 24 additions & 23 deletions engine/src/Camera.cpp
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;
}
};
20 changes: 10 additions & 10 deletions engine/src/Configuration.cpp
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;
}
};
22 changes: 11 additions & 11 deletions engine/src/Window.cpp
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;
}
};
141 changes: 68 additions & 73 deletions engine/src/parse.cpp
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);
}
Loading

0 comments on commit ae699ad

Please sign in to comment.