From 7b1be7c2d9b6879dce6e5d19625c1c1fee75e5ac Mon Sep 17 00:00:00 2001 From: tomoron Date: Thu, 23 Jan 2025 19:47:41 +0100 Subject: [PATCH] rendrerer : add a test split button to see if a part of path is good --- imgui.ini | 11 +++--- includes/RT/Renderer.hpp | 9 ++++- includes/RT/Window.hpp | 3 +- srcs/RT.cpp | 6 ++-- srcs/class/Camera.cpp | 3 +- srcs/class/Renderer.cpp | 72 +++++++++++++++++++++++++++++++++++--- srcs/class/SceneParser.cpp | 3 +- srcs/class/Window.cpp | 7 +++- 8 files changed, 94 insertions(+), 20 deletions(-) diff --git a/imgui.ini b/imgui.ini index f2af59a..dc1baba 100644 --- a/imgui.ini +++ b/imgui.ini @@ -3,7 +3,7 @@ Pos=60,60 Size=400,400 [Window][Camera] -Pos=399,48 +Pos=687,817 Size=259,200 [Window][Material] @@ -11,20 +11,19 @@ Pos=646,129 Size=266,299 [Window][Fog settings] -Pos=927,52 +Pos=35,863 Size=247,130 -Collapsed=1 [Window][Debug] Pos=1642,668 Size=260,143 [Window][Debug BVH] -Pos=927,72 +Pos=772,16 Size=274,205 Collapsed=1 [Window][Renderer] -Pos=636,712 -Size=307,319 +Pos=31,66 +Size=747,496 diff --git a/includes/RT/Renderer.hpp b/includes/RT/Renderer.hpp index c5b887d..08d9e6b 100644 --- a/includes/RT/Renderer.hpp +++ b/includes/RT/Renderer.hpp @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */ -/* Updated: 2025/01/22 19:34:22 by tomoron ### ########.fr */ +/* Updated: 2025/01/23 19:41:40 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,9 +30,11 @@ class Renderer public: Renderer(Scene *scene, Window *win); void renderImgui(void); + void update(void); private: void addPoint(void); + void makeMovement(float timeFromStart, float curSplitTimeReset); int _min; float _sec; @@ -40,6 +42,11 @@ class Renderer std::vector _path; Scene *_scene; Window *_win; + + int _curPathIndex; + int _destPathIndex; + double _curSplitStart; + int _curSamples; }; #endif diff --git a/includes/RT/Window.hpp b/includes/RT/Window.hpp index 8b39b36..d30eb81 100644 --- a/includes/RT/Window.hpp +++ b/includes/RT/Window.hpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/13 16:15:41 by TheRed #+# #+# */ -/* Updated: 2025/01/23 00:39:11 by tomoron ### ########.fr */ +/* Updated: 2025/01/23 15:31:28 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,6 +46,7 @@ class Window void setFrameCount(int nb); + void rendererUpdate(void); private: GLFWwindow *_window; Scene *_scene; diff --git a/srcs/RT.cpp b/srcs/RT.cpp index 2d57f86..37006c0 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: 2025/01/22 16:33:56 by tomoron ### ########.fr */ +/* Updated: 2025/01/23 18:37:21 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -115,6 +115,7 @@ int main(int argc, char **argv) std::vector gpu_lights_array(gpu_lights.begin(), gpu_lights.end()); glBindBuffer(GL_SHADER_STORAGE_BUFFER, lightSSBO); glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, gpu_lights_array.size() * sizeof(int), gpu_lights_array.data()); + window.rendererUpdate(); Camera *camera = scene.getCamera(); @@ -142,7 +143,6 @@ int main(int argc, char **argv) break; camera->setDirection(0, yaw - 180); - camera->updateCameraVectors(); } // @@ -177,7 +177,7 @@ int main(int argc, char **argv) window.imGuiRender(); window.display(); - window.pollEvents(); + window.pollEvents(); } ImGui_ImplOpenGL3_Shutdown(); diff --git a/srcs/class/Camera.cpp b/srcs/class/Camera.cpp index d2604be..2a09b80 100644 --- a/srcs/class/Camera.cpp +++ b/srcs/class/Camera.cpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 14:00:38 by TheRed #+# #+# */ -/* Updated: 2025/01/22 19:27:03 by tomoron ### ########.fr */ +/* Updated: 2025/01/23 18:34:29 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -150,6 +150,7 @@ void Camera::setDirection(float pitch, float yaw) { _pitch = pitch; _yaw = yaw; + updateCameraVectors(); } void Camera::setDOV(float aperture, float focus) diff --git a/srcs/class/Renderer.cpp b/srcs/class/Renderer.cpp index c851375..94d1954 100644 --- a/srcs/class/Renderer.cpp +++ b/srcs/class/Renderer.cpp @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */ -/* Updated: 2025/01/23 00:54:01 by tomoron ### ########.fr */ +/* Updated: 2025/01/23 19:42:56 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ Renderer::Renderer(Scene *scene, Window *win) _min = 0; _sec = 0; _samples = 1; + _curSamples = 0; } void Renderer::addPoint(void) @@ -31,15 +32,64 @@ void Renderer::addPoint(void) newPoint.pos = cam->getPosition(); newPoint.dir = cam->getDirection(); newPoint.time = _min + (_sec / 60); - std::cout << "position : " << glm::to_string(newPoint.pos) << std::endl; - std::cout << "direction : " << glm::to_string(newPoint.dir) << std::endl; - std::cout << "time : " << newPoint.time << std::endl; pos = _path.begin(); while(pos != _path.end() && pos->time <= newPoint.time) pos++; _path.insert(pos, newPoint); } +void Renderer::update(void) +{ + double curTime; + + if(!_destPathIndex) + return; + curTime = glfwGetTime(); + _curSamples++; + if(_curSamples == _samples) + { + makeMovement(curTime - _curSplitStart, curTime); + _curSamples = 0; + } +} + +void Renderer::makeMovement(float timeFromStart, float curSplitTimeReset) +{ + t_pathPoint from; + t_pathPoint to; + float pathTime; + Camera *cam; + glm::vec3 posStep; + glm::vec2 dirStep; + + from = _path[_curPathIndex]; + to = _path[_curPathIndex + 1]; + cam = _scene->getCamera(); + pathTime = (to.time - from.time) * 60; + + posStep.x = ((to.pos.x - from.pos.x) / pathTime) * timeFromStart; + posStep.y = ((to.pos.y - from.pos.y) / pathTime) * timeFromStart; + posStep.z = ((to.pos.z - from.pos.z) / pathTime) * timeFromStart; + dirStep.x = ((to.dir.x - from.dir.x) / pathTime) * timeFromStart; + dirStep.y = ((to.dir.y - from.dir.y) / pathTime) * timeFromStart; + + if(timeFromStart >= pathTime) + { + posStep = to.pos - from.pos; + dirStep = to.dir - from.dir; + _curSplitStart = curSplitTimeReset; + _curPathIndex++; + } + cam->setPosition(from.pos + posStep); + cam->setDirection(from.dir.x + dirStep.x, from.dir.y + dirStep.y); + _win->setFrameCount(0); + if(_curPathIndex == _destPathIndex) + { + _destPathIndex = 0; + std::cout << "done" << std::endl; + } +} + void Renderer::renderImgui(void) { ImGui::Begin("Renderer"); @@ -69,15 +119,27 @@ void Renderer::renderImgui(void) { _scene->getCamera()->setPosition(_path[i].pos); _scene->getCamera()->setDirection(_path[i].dir.x, _path[i].dir.y); - _scene->getCamera()->updateCameraVectors(); _win->setFrameCount(-1); } + ImGui::SameLine(); if(ImGui::Button(("edit pos##" + std::to_string(i)).c_str())) { _path[i].pos = _scene->getCamera()->getPosition(); _path[i].dir = _scene->getCamera()->getDirection(); } + + if(i) + ImGui::SameLine(); + if(i && ImGui::Button(("test split##" + std::to_string(i)).c_str())) + { + _scene->getCamera()->setPosition(_path[i].pos); + _scene->getCamera()->setDirection(_path[i].dir.x, _path[i].dir.y); + _win->setFrameCount(-1); + _curSplitStart = glfwGetTime(); + _curPathIndex = i - 1; + _destPathIndex = i; + } ImGui::Separator(); } ImGui::End(); diff --git a/srcs/class/SceneParser.cpp b/srcs/class/SceneParser.cpp index 26afc05..cee946d 100644 --- a/srcs/class/SceneParser.cpp +++ b/srcs/class/SceneParser.cpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/26 21:43:51 by TheRed #+# #+# */ -/* Updated: 2025/01/21 15:57:42 by tomoron ### ########.fr */ +/* Updated: 2025/01/23 18:39:28 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -86,7 +86,6 @@ void SceneParser::parseCamera(std::stringstream &line) _scene->getCamera()->setPosition(glm::vec3(x, y, z)); _scene->getCamera()->setDirection(yaw, pitch); - _scene->getCamera()->updateCameraVectors(); _scene->getCamera()->setDOV(aperture, focus); _scene->getCamera()->setFov(fov); diff --git a/srcs/class/Window.cpp b/srcs/class/Window.cpp index 75774d2..c4a56a3 100644 --- a/srcs/class/Window.cpp +++ b/srcs/class/Window.cpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */ -/* Updated: 2025/01/23 00:39:21 by tomoron ### ########.fr */ +/* Updated: 2025/01/23 16:26:39 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -161,6 +161,11 @@ bool Window::shouldClose() return glfwWindowShouldClose(_window); } +void Window::rendererUpdate(void) +{ + _renderer->update(); +} + void Window::imGuiNewFrame() { ImGui_ImplOpenGL3_NewFrame();