Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
[FEAT]: init parse with libconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
bobis33 committed Apr 12, 2024
1 parent b9776b4 commit 8651165
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 12 deletions.
22 changes: 22 additions & 0 deletions App/include/RayTracer/Abstraction/IShapes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
** EPITECH PROJECT, 2024
** Raytracer
** File description:
** IShapes.cpp
*/

#ifndef RAYTRACER_ISHAPES_HPP
#define RAYTRACER_ISHAPES_HPP

namespace RayTracer {

class IShapes {

public:
virtual ~IShapes() = default;

}; // IShapes

} // namespace RayTracer

#endif //RAYTRACER_ISHAPES_HPP
47 changes: 46 additions & 1 deletion App/include/RayTracer/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,56 @@

#include <iostream>
#include <vector>
#include <cstdint>
#include <tuple>

namespace RayTracer {

struct Light_t {
bool isSet{false};
float ambient{0.0F};
float diffuse{0.0F};
std::tuple<int16_t, int16_t, int16_t> point{0, 0, 0};
std::tuple<int16_t, int16_t, int16_t> direction{0, 0, 0};
};

struct Plane_t {
bool isSet{false};
};

struct Sphere_t {
bool isSet{false};
};

struct Cylinder_t {
bool isSet{false};
};

struct Cone_t {
bool isSet{false};
};

struct Primitive_t {
bool isSet{false};
Sphere_t sphere;
Plane_t plane;
Cylinder_t cylinder;
Cone_t cone;
};

struct Camera_t {
bool isSet{false};
std::pair<uint16_t, uint16_t> resolution{1920, 1080};
std::tuple<int16_t, int16_t, int16_t> position{0, 0, 0};
std::tuple<int16_t, int16_t, int16_t> rotation{0, 0, 0};
float fov{0.0F};

};

struct Scene {
std::vector<std::string> config;
Camera_t camera;
Light_t light;
Primitive_t primitive;
};

class Parser {
Expand Down
18 changes: 9 additions & 9 deletions App/src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
*/

#include <filesystem>
#include <fstream>
#include <libconfig.h++>

#include "RayTracer/Parser.hpp"
#include "RayTracer/Constants.hpp"


RayTracer::Scene RayTracer::Parser::parseFile(const std::string &filePath)
{
libconfig::Config config;
Scene scene;
std::string line;
std::ifstream file(filePath);

while(std::getline(file, line)) {
scene.config.push_back(line);
}

if (scene.config.empty()) {
throw ParserException{"File is empty"};
try {
config.readFile(filePath.c_str());
} catch (const libconfig::FileIOException &e) {
throw ParserException{"Error while reading file"};
} catch (const libconfig::ParseException &e) {
throw ParserException{e.getError()};
}

return scene;
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ target_sources(${PROJECT_NAME} PRIVATE
)

target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE raytracer_interface)
target_link_libraries(${PROJECT_NAME} PRIVATE raytracer_interface config++)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
target_compile_options(${PROJECT_NAME} PRIVATE ${WARNING_FLAGS})
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $> ./build.sh build
### Launch RayTracer

```bash
$> ./raytracer .
$> ./raytracer <SCENE_FILE>
[...]
```

Expand Down
Binary file modified doc/RayTracer.pdf
Binary file not shown.

0 comments on commit 8651165

Please sign in to comment.