mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
+ | Going to start object systems
This commit is contained in:
9
Makefile
9
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))
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
30
includes/RT/Object.hpp
Normal file
30
includes/RT/Object.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Object.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
34
includes/RT/Scene.hpp
Normal file
34
includes/RT/Scene.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Scene.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
30
includes/RT/objects/Sphere.hpp
Normal file
30
includes/RT/objects/Sphere.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Sphere.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_SPHERE__HPP
|
||||
# define RT_SPHERE__HPP
|
||||
|
||||
# include "RT.hpp"
|
||||
|
||||
class Sphere : public Object
|
||||
{
|
||||
public:
|
||||
float radius;
|
||||
glm::vec3 position;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
12
srcs/class/Object.cpp
Normal file
12
srcs/class/Object.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Object.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/23 18:44:00 by ycontre #+# #+# */
|
||||
/* Updated: 2024/12/23 18:44:01 by ycontre ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
28
srcs/class/Scene.cpp
Normal file
28
srcs/class/Scene.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Scene.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
12
srcs/parsing/parsing.cpp
Normal file
12
srcs/parsing/parsing.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/23 18:28:59 by ycontre #+# #+# */
|
||||
/* Updated: 2024/12/23 18:29:00 by ycontre ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
Reference in New Issue
Block a user