Skip to content

Commit

Permalink
feat: first steps
Browse files Browse the repository at this point in the history
  • Loading branch information
diogogmatos committed Mar 2, 2024
1 parent ee10c8f commit 63afb72
Show file tree
Hide file tree
Showing 11 changed files with 3,911 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ engine/CMakeFiles/*
.idea/*
.vscode/*
generator/generator
engine/engine
engine/engine
build
29 changes: 29 additions & 0 deletions engine/src/Camera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "utils.hpp"

class Camera {
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(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;
}
};
15 changes: 15 additions & 0 deletions engine/src/Configuration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Window.cpp"
#include "Camera.cpp"

class Configuration {
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;
}
};
15 changes: 15 additions & 0 deletions engine/src/Window.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Window {
public:
float width;
float height;

Window() {
this->width = 0;
this->height = 0;
}

Window(float width, float height) {
this->width = width;
this->height = height;
}
};
79 changes: 79 additions & 0 deletions engine/src/parse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "Configuration.cpp"
#include "Camera.cpp"
#include "Window.cpp"

#include <iostream>
#include <fstream>

#include "utils.hpp"

#include "../../lib/rapidxml-1.13/rapidxml.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);
}
52 changes: 52 additions & 0 deletions lib/rapidxml-1.13/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Use of this software is granted under one of the following two licenses,
to be chosen freely by the user.

1. Boost Software License - Version 1.0 - August 17th, 2003
===============================================================================

Copyright (c) 2006, 2007 Marcin Kalicinski

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

2. The MIT License
===============================================================================

Copyright (c) 2006, 2007 Marcin Kalicinski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
Loading

0 comments on commit 63afb72

Please sign in to comment.