mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ Parsing object system
This commit is contained in:
@ -39,7 +39,7 @@ class Object
|
||||
SPHERE,
|
||||
};
|
||||
|
||||
virtual Type getType() const = 0;
|
||||
virtual Type getType() const = 0;
|
||||
};
|
||||
|
||||
#endif
|
@ -36,17 +36,20 @@ class Scene
|
||||
Scene();
|
||||
~Scene();
|
||||
|
||||
Camera *getCamera(void) const;
|
||||
bool parseScene(char *name);
|
||||
|
||||
void addObject(Object *object);
|
||||
|
||||
void updateGPUData();
|
||||
const std::vector<GPUObject>& getGPUData() const;
|
||||
|
||||
const std::vector<GPUObject> &getGPUData() const;
|
||||
Camera *getCamera(void) const;
|
||||
|
||||
private:
|
||||
std::vector<Object *> _objects;
|
||||
std::vector<GPUObject> _gpuObjects;
|
||||
std::vector<Object *> _objects;
|
||||
std::vector<GPUObject> _gpu_objects;
|
||||
|
||||
Camera *_camera;
|
||||
Camera *_camera;
|
||||
};
|
||||
|
||||
#endif
|
31
includes/RT/SceneParser.hpp
Normal file
31
includes/RT/SceneParser.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* SceneParser.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: TheRed <TheRed@students.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/26 21:37:37 by TheRed #+# #+# */
|
||||
/* Updated: 2024/12/26 21:37:37 by TheRed ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef RT_SceneParser__HPP
|
||||
# define RT_SceneParser__HPP
|
||||
|
||||
# include "RT.hpp"
|
||||
|
||||
class SceneParser
|
||||
{
|
||||
public:
|
||||
SceneParser(Scene *scene);
|
||||
|
||||
bool parseLine(const std::string &line);
|
||||
|
||||
private:
|
||||
Scene *_scene;
|
||||
|
||||
std::map<std::string, std::function<Object *(std::stringstream &)>> object_parsers;
|
||||
};
|
||||
|
||||
#endif
|
@ -20,11 +20,10 @@ class Scene;
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
Window(int width, int height, const char *title, int sleep);
|
||||
Window(Scene *scene, int width, int height, const char *title, int sleep);
|
||||
~Window(void);
|
||||
|
||||
GLFWwindow *getWindow(void) const;
|
||||
Scene *getScene(void) const;
|
||||
float getFps(void) const;
|
||||
|
||||
void display();
|
||||
|
@ -17,15 +17,59 @@
|
||||
|
||||
class Sphere : public Object
|
||||
{
|
||||
|
||||
public:
|
||||
struct ParseError : public std::runtime_error
|
||||
{
|
||||
ParseError(const std::string& msg) : std::runtime_error("Sphere parse error: " + msg) {}
|
||||
};
|
||||
|
||||
Sphere(std::stringstream &line) : Object(glm::vec3(0.0f), nullptr)
|
||||
{
|
||||
_mat = new Material;
|
||||
|
||||
try {
|
||||
float x, y, z, radius;
|
||||
float r, g, b, rough, spec;
|
||||
|
||||
if (!(line >> x >> y >> z >> radius))
|
||||
throw std::invalid_argument("Missing position or radius values");
|
||||
|
||||
if (radius <= 0.0f)
|
||||
throw std::invalid_argument("Radius must be positive");
|
||||
|
||||
if (!(line >> r >> g >> b >> rough >> spec))
|
||||
throw std::invalid_argument("Missing material properties");
|
||||
|
||||
if (r < 0.0f || r > 255.0f || g < 0.0f || g > 255.0f || b < 0.0f || b > 255.0f)
|
||||
throw std::invalid_argument("Color values must be between 0 and 255");
|
||||
|
||||
if (rough < 0.0f || rough > 1.0f)
|
||||
throw std::invalid_argument("Roughness must be between 0 and 1");
|
||||
|
||||
if (spec < 0.0f || spec > 1.0f)
|
||||
throw std::invalid_argument("Specular must be between 0 and 1");
|
||||
|
||||
_position = glm::vec3(x, y, z);
|
||||
_radius = radius;
|
||||
|
||||
_mat->color = glm::vec3(r / 255.0f, g / 255.0f, b / 255.0f);
|
||||
_mat->roughness = rough;
|
||||
_mat->specular = spec;
|
||||
|
||||
_material = _mat;
|
||||
}
|
||||
catch (const std::exception& e) { throw; }
|
||||
}
|
||||
Sphere(const glm::vec3& position, float radius, const Material *material)
|
||||
: Object(position, material), _radius(radius) {}
|
||||
|
||||
float getRadius() const { return (_radius); }
|
||||
Type getType() const override { return Type::SPHERE; }
|
||||
float getRadius() const { return (_radius); }
|
||||
Type getType() const override { return Type::SPHERE; }
|
||||
|
||||
private:
|
||||
float _radius;
|
||||
Material *_mat;
|
||||
float _radius;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user