mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
rendrerer : add a test split button to see if a part of path is good
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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<int> 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();
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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();
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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();
|
||||
|
Reference in New Issue
Block a user