From e931b496eedb396919917f9b87e6bc7ce17e5f22 Mon Sep 17 00:00:00 2001 From: RedShip Date: Mon, 23 Dec 2024 19:47:34 +0100 Subject: [PATCH] + | Going to start object systems --- Makefile | 9 +++++---- includes/RT.hpp | 5 ++++- includes/{ => RT}/Camera.hpp | 0 includes/RT/Object.hpp | 30 ++++++++++++++++++++++++++++++ includes/RT/Scene.hpp | 34 ++++++++++++++++++++++++++++++++++ includes/{ => RT}/Shader.hpp | 0 includes/{ => RT}/Window.hpp | 8 ++++---- includes/RT/objects/Sphere.hpp | 30 ++++++++++++++++++++++++++++++ srcs/RT.cpp | 6 +++--- srcs/{ => class}/Camera.cpp | 0 srcs/class/Object.cpp | 12 ++++++++++++ srcs/class/Scene.cpp | 28 ++++++++++++++++++++++++++++ srcs/{ => class}/Shader.cpp | 0 srcs/{ => class}/Window.cpp | 20 ++++++++++---------- srcs/parsing/parsing.cpp | 12 ++++++++++++ 15 files changed, 172 insertions(+), 22 deletions(-) rename includes/{ => RT}/Camera.hpp (100%) create mode 100644 includes/RT/Object.hpp create mode 100644 includes/RT/Scene.hpp rename includes/{ => RT}/Shader.hpp (100%) rename includes/{ => RT}/Window.hpp (91%) create mode 100644 includes/RT/objects/Sphere.hpp rename srcs/{ => class}/Camera.cpp (100%) create mode 100644 srcs/class/Object.cpp create mode 100644 srcs/class/Scene.cpp rename srcs/{ => class}/Shader.cpp (100%) rename srcs/{ => class}/Window.cpp (90%) create mode 100644 srcs/parsing/parsing.cpp diff --git a/Makefile b/Makefile index 36a375a..f4872ed 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ else DIR_DUP = mkdir -p $(@D) CC := clang++ CFLAGS := -Ofast -Wall -Wextra -Werror - IFLAGS := -I./includes -I/usr/include + IFLAGS := -I./includes -I./includes/RT -I/usr/include LDFLAGS := -L/usr/lib/x86_64-linux-gnu -lglfw -lGL -lGLU -lX11 -lpthread -ldl -lstdc++ FILE = $(shell ls -lR srcs/ | grep -F .c | wc -l) CMP = 1 @@ -39,9 +39,10 @@ NAME := RT SRCS_DIR := srcs OBJS_DIR := .objs ALL_SRCS := RT.cpp gl.cpp \ - Window.cpp \ - Shader.cpp \ - Camera.cpp + class/Window.cpp \ + class/Shader.cpp \ + class/Camera.cpp \ + class/Scene.cpp SRCS := $(ALL_SRCS:%=$(SRCS_DIR)/%) OBJS := $(addprefix $(OBJS_DIR)/, $(SRCS:%.cpp=%.o)) diff --git a/includes/RT.hpp b/includes/RT.hpp index 198eb28..2a88240 100644 --- a/includes/RT.hpp +++ b/includes/RT.hpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/27 14:52:10 by TheRed #+# #+# */ -/* Updated: 2024/10/13 20:52:17 by ycontre ### ########.fr */ +/* Updated: 2024/12/23 19:04:53 by ycontre ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,5 +28,8 @@ # include "Camera.hpp" # include "Window.hpp" # include "Shader.hpp" +# include "Scene.hpp" + + #endif \ No newline at end of file diff --git a/includes/Camera.hpp b/includes/RT/Camera.hpp similarity index 100% rename from includes/Camera.hpp rename to includes/RT/Camera.hpp diff --git a/includes/RT/Object.hpp b/includes/RT/Object.hpp new file mode 100644 index 0000000..b13ae92 --- /dev/null +++ b/includes/RT/Object.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Object.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ycontre +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/23 18:44:18 by ycontre #+# #+# */ +/* Updated: 2024/12/23 19:12:39 by ycontre ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RT_OBJECT__HPP +# define RT_OBJECT__HPP + +class Object +{ + public: + glm::vec3 position; + glm::vec3 color; + + Object(const glm::vec3& pos, const glm::vec3& col) : position(pos), color(col) {} + virtual ~Object() = default; + + // virtual bool hit(const glm::vec3& rayOrigin, const glm::vec3& rayDir, float& t, glm::vec3& hitNormal) const = 0; + + +}; + +#endif \ No newline at end of file diff --git a/includes/RT/Scene.hpp b/includes/RT/Scene.hpp new file mode 100644 index 0000000..59462d1 --- /dev/null +++ b/includes/RT/Scene.hpp @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Scene.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ycontre +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/23 18:30:18 by ycontre #+# #+# */ +/* Updated: 2024/12/23 18:46:13 by ycontre ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RT_SCENE__HPP +# define RT_SCENE__HPP + +# include "RT.hpp" + +class Camera; + +class Scene +{ + public: + Scene(); + ~Scene(); + + Camera *getCamera(void) const; + // Object *getObjects(void) const; + + private: + // Object *_objects; + Camera *_camera; +}; + +#endif \ No newline at end of file diff --git a/includes/Shader.hpp b/includes/RT/Shader.hpp similarity index 100% rename from includes/Shader.hpp rename to includes/RT/Shader.hpp diff --git a/includes/Window.hpp b/includes/RT/Window.hpp similarity index 91% rename from includes/Window.hpp rename to includes/RT/Window.hpp index f01eaf3..210f15e 100644 --- a/includes/Window.hpp +++ b/includes/RT/Window.hpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/13 16:15:41 by TheRed #+# #+# */ -/* Updated: 2024/10/13 20:48:46 by ycontre ### ########.fr */ +/* Updated: 2024/12/23 18:35:35 by ycontre ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ # include "RT.hpp" -class Camera; +class Scene; class Window { @@ -24,7 +24,7 @@ class Window ~Window(void); GLFWwindow *getWindow(void) const; - Camera *get_camera(void) const; + Scene *getScene(void) const; float getFps(void) const; void display(); @@ -37,7 +37,7 @@ class Window private: GLFWwindow *_window; - Camera *_camera; + Scene *_scene; float _fps; diff --git a/includes/RT/objects/Sphere.hpp b/includes/RT/objects/Sphere.hpp new file mode 100644 index 0000000..f48e8ff --- /dev/null +++ b/includes/RT/objects/Sphere.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Sphere.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ycontre +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/23 19:12:51 by ycontre #+# #+# */ +/* Updated: 2024/12/23 19:47:09 by ycontre ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RT_SPHERE__HPP +# define RT_SPHERE__HPP + +# include "RT.hpp" + +class Sphere : public Object +{ + public: + float radius; + glm::vec3 position; + + + private: + + +}; + +#endif \ No newline at end of file diff --git a/srcs/RT.cpp b/srcs/RT.cpp index 372440a..99441df 100644 --- a/srcs/RT.cpp +++ b/srcs/RT.cpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */ -/* Updated: 2024/10/14 19:54:42 by ycontre ### ########.fr */ +/* Updated: 2024/12/23 18:38:38 by ycontre ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,8 +31,8 @@ int main(void) glClear(GL_COLOR_BUFFER_BIT); shader.set_vec2("u_resolution", glm::vec2(WIDTH, HEIGHT)); - shader.set_vec3("u_cameraPosition", window.get_camera()->get_position()); - shader.set_mat4("u_viewMatrix", window.get_camera()->get_view_matrix()); + shader.set_vec3("u_cameraPosition", window.getScene()->getCamera()->get_position()); + shader.set_mat4("u_viewMatrix", window.getScene()->getCamera()->get_view_matrix()); glUseProgram(shader.getProgram()); shader.drawTriangles(size); diff --git a/srcs/Camera.cpp b/srcs/class/Camera.cpp similarity index 100% rename from srcs/Camera.cpp rename to srcs/class/Camera.cpp diff --git a/srcs/class/Object.cpp b/srcs/class/Object.cpp new file mode 100644 index 0000000..f75f2d2 --- /dev/null +++ b/srcs/class/Object.cpp @@ -0,0 +1,12 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Object.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ycontre +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/23 18:44:00 by ycontre #+# #+# */ +/* Updated: 2024/12/23 18:44:01 by ycontre ### ########.fr */ +/* */ +/* ************************************************************************** */ + diff --git a/srcs/class/Scene.cpp b/srcs/class/Scene.cpp new file mode 100644 index 0000000..fd632ff --- /dev/null +++ b/srcs/class/Scene.cpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Scene.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ycontre +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/23 18:29:41 by ycontre #+# #+# */ +/* Updated: 2024/12/23 18:40:17 by ycontre ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Scene.hpp" + +Scene::Scene() +{ + _camera = new Camera(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), -90.0f, 0.0f); +} + +Scene::~Scene() +{ + delete _camera; +} + +Camera *Scene::getCamera(void) const +{ + return (_camera); +} \ No newline at end of file diff --git a/srcs/Shader.cpp b/srcs/class/Shader.cpp similarity index 100% rename from srcs/Shader.cpp rename to srcs/class/Shader.cpp diff --git a/srcs/Window.cpp b/srcs/class/Window.cpp similarity index 90% rename from srcs/Window.cpp rename to srcs/class/Window.cpp index 83cc234..31d4113 100644 --- a/srcs/Window.cpp +++ b/srcs/class/Window.cpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */ -/* Updated: 2024/12/23 17:39:55 by ycontre ### ########.fr */ +/* Updated: 2024/12/23 18:39:37 by ycontre ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ Window::Window(int width, int height, const char *title, int sleep) { - _camera = new Camera(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), -90.0f, 0.0f); + _scene = new Scene(); if (!glfwInit()) { @@ -47,7 +47,7 @@ Window::Window(int width, int height, const char *title, int sleep) Window::~Window(void) { - delete _camera; + delete _scene; glfwTerminate(); } @@ -65,7 +65,7 @@ void Window::keyCallback(GLFWwindow* window, int key, int scancode, int action, bool up = glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS; bool down = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS; - win->_camera->process_keyboard(forward, backward, left, right, up, down); + win->_scene->getCamera()->process_keyboard(forward, backward, left, right, up, down); } void Window::mouseMoveCallback(GLFWwindow* window, double xpos, double ypos) { @@ -86,7 +86,7 @@ void Window::mouseMoveCallback(GLFWwindow* window, double xpos, double ypos) if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS) { - win->_camera->process_mouse(xoffset, yoffset, true); + win->_scene->getCamera()->process_mouse(xoffset, yoffset, true); // scene.frameCount = 0; } @@ -125,16 +125,16 @@ bool Window::shouldClose() return glfwWindowShouldClose(_window); } -Camera *Window::get_camera(void) const -{ - return (_camera); -} - GLFWwindow *Window::getWindow(void) const { return (_window); } +Scene *Window::getScene(void) const +{ + return (_scene); +} + float Window::getFps(void) const { return (_fps); diff --git a/srcs/parsing/parsing.cpp b/srcs/parsing/parsing.cpp new file mode 100644 index 0000000..a7092de --- /dev/null +++ b/srcs/parsing/parsing.cpp @@ -0,0 +1,12 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parsing.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ycontre +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/23 18:28:59 by ycontre #+# #+# */ +/* Updated: 2024/12/23 18:29:00 by ycontre ### ########.fr */ +/* */ +/* ************************************************************************** */ +