mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Optimization + reflection
This commit is contained in:
@ -37,6 +37,7 @@ struct Vertex {
|
||||
|
||||
# include "Object.hpp"
|
||||
# include "objects/Sphere.hpp"
|
||||
# include "objects/Plane.hpp"
|
||||
|
||||
# include "Camera.hpp"
|
||||
# include "Window.hpp"
|
||||
|
@ -38,6 +38,7 @@ class Object
|
||||
|
||||
enum class Type {
|
||||
SPHERE,
|
||||
PLANE,
|
||||
};
|
||||
|
||||
virtual Type getType() const = 0;
|
||||
|
@ -18,12 +18,16 @@
|
||||
struct GPUObject
|
||||
{
|
||||
alignas(16) glm::vec3 position;
|
||||
|
||||
alignas(16) glm::vec3 color;
|
||||
float emission;
|
||||
float roughness;
|
||||
float specular;
|
||||
float radius;
|
||||
int type;
|
||||
float emission;
|
||||
float roughness;
|
||||
float specular;
|
||||
|
||||
float radius; // sphere
|
||||
alignas(16) glm::vec3 normal; // plane
|
||||
|
||||
int type;
|
||||
};
|
||||
|
||||
class Sphere;
|
||||
|
@ -41,8 +41,9 @@ class Window
|
||||
GLFWwindow *_window;
|
||||
Scene *_scene;
|
||||
|
||||
int _frameCount;
|
||||
float _fps;
|
||||
float _delta;
|
||||
int _frameCount;
|
||||
|
||||
};
|
||||
|
||||
|
54
includes/RT/objects/Plane.hpp
Normal file
54
includes/RT/objects/Plane.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Plane.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/23 19:12:51 by ycontre #+# #+# */
|
||||
/* Updated: 2024/12/23 19:47:09 by ycontre ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef RT_Plane__HPP
|
||||
# define RT_Plane__HPP
|
||||
|
||||
# include "RT.hpp"
|
||||
|
||||
class Plane : public Object
|
||||
{
|
||||
public:
|
||||
Plane(std::stringstream &line) : Object(glm::vec3(0.0f), -1)
|
||||
{
|
||||
try {
|
||||
float x, y, z;
|
||||
float nx, ny, nz;
|
||||
int mat_index;
|
||||
|
||||
if (!(line >> x >> y >> z))
|
||||
throw std::runtime_error("Missing position");
|
||||
|
||||
if (!(line >> nx >> ny >> nz))
|
||||
throw std::runtime_error("Missing plane's normal");
|
||||
|
||||
if (!(line >> mat_index))
|
||||
throw std::runtime_error("Missing material properties");
|
||||
|
||||
_position = glm::vec3(x, y, z);
|
||||
_normal = glm::vec3(nx, ny, nz);
|
||||
|
||||
_mat_index = mat_index;
|
||||
}
|
||||
catch (const std::exception &e) { throw; }
|
||||
}
|
||||
Plane(const glm::vec3 &position, const glm::vec3 &normal, const int mat_index)
|
||||
: Object(position, mat_index), _normal(normal) {}
|
||||
|
||||
glm::vec3 getNormal() const { return (_normal); }
|
||||
Type getType() const override { return Type::PLANE; }
|
||||
|
||||
private:
|
||||
glm::vec3 _normal;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user