mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
add to render path automatically when going through a portal and fix images on tp path nodes
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 13:59:57 by TheRed #+# #+# */
|
||||
/* Updated: 2025/02/05 19:05:45 by ycontre ### ########.fr */
|
||||
/* Updated: 2025/02/17 22:47:47 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -27,6 +27,7 @@ struct GPUCamera
|
||||
};
|
||||
|
||||
class Scene;
|
||||
class Renderer;
|
||||
|
||||
class Camera
|
||||
{
|
||||
@ -36,14 +37,14 @@ class Camera
|
||||
~Camera(void);
|
||||
|
||||
|
||||
void update(Scene *scene, float deltaTime);
|
||||
void update(Scene *scene, float deltaTime, Renderer &renderer);
|
||||
void processMouse(float xoffset, float yoffset, bool constrainPitch);
|
||||
void processKeyboard(bool forward, bool backward, bool left, bool right, bool up, bool down);
|
||||
|
||||
void updateCameraVectors();
|
||||
void updateCameraDirections();
|
||||
|
||||
int portalTeleport(Scene *scene, float delta_time);
|
||||
int portalTeleport(Scene *scene, float delta_time, Renderer &renderer);
|
||||
|
||||
glm::vec3 getPosition();
|
||||
glm::vec2 getDirection();
|
||||
@ -89,4 +90,4 @@ class Camera
|
||||
int _bounce = 5;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */
|
||||
/* Updated: 2025/02/16 23:20:09 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/02/17 22:55:09 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -40,6 +40,7 @@ class Renderer
|
||||
Renderer(Scene *scene, Window *win, Arguments &args);
|
||||
|
||||
void update(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
|
||||
void addTeleport(glm::vec3 from_pos, glm::vec2 from_dir, glm::vec3 to_pos, glm::vec2 to_dir);
|
||||
void renderImgui(void);
|
||||
|
||||
int rendering(void) const;
|
||||
@ -50,7 +51,7 @@ class Renderer
|
||||
|
||||
void showRenderInfo(int isImgui);
|
||||
std::string floatToTime(double timef);
|
||||
float calcTime(void);
|
||||
float calcTime(glm::vec3 pos);
|
||||
|
||||
void addPoint(float time);
|
||||
void imguiPathCreation(void);
|
||||
@ -98,6 +99,7 @@ class Renderer
|
||||
bool _ignoreUnavailableCodec;
|
||||
bool _tp;
|
||||
bool _autoTime;
|
||||
bool _autoTP;
|
||||
std::vector<const char *> _codecListStr;
|
||||
int _codecIndex;
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 14:00:38 by TheRed #+# #+# */
|
||||
/* Updated: 2025/02/06 19:45:46 by ycontre ### ########.fr */
|
||||
/* Updated: 2025/02/17 23:00:28 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -60,7 +60,7 @@ void Camera::updateCameraDirections()
|
||||
_pitch = glm::clamp(_pitch, -89.0f, 89.0f);
|
||||
}
|
||||
|
||||
void Camera::update(Scene *scene, float delta_time)
|
||||
void Camera::update(Scene *scene, float delta_time, Renderer &renderer)
|
||||
{
|
||||
// delta_time = std::min(delta_time, 0.01f);
|
||||
|
||||
@ -73,13 +73,13 @@ void Camera::update(Scene *scene, float delta_time)
|
||||
if (speed > _maxSpeed)
|
||||
_velocity = glm::normalize(_velocity) * _maxSpeed;
|
||||
|
||||
if (glm::length(_velocity) > 0.0f && !this->portalTeleport(scene, delta_time))
|
||||
if (glm::length(_velocity) > 0.0f && !this->portalTeleport(scene, delta_time, renderer))
|
||||
_position += _velocity * delta_time;
|
||||
|
||||
_acceleration = glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
int Camera::portalTeleport(Scene *scene, float delta_time)
|
||||
int Camera::portalTeleport(Scene *scene, float delta_time, Renderer &renderer)
|
||||
{
|
||||
for (const GPUObject &obj : scene->getObjectData())
|
||||
{
|
||||
@ -124,17 +124,20 @@ int Camera::portalTeleport(Scene *scene, float delta_time)
|
||||
|
||||
//teleportation
|
||||
|
||||
glm::vec3 previous_position = _position;
|
||||
glm::vec3 relative_pos = _position - obj.position;
|
||||
glm::vec3 transformed_relative_pos = portal_transform * relative_pos;
|
||||
|
||||
float remaining_distance = distance_future_pos - distance_portal + imprecision;
|
||||
glm::vec3 new_movement = remaining_distance * portal_transform * linked_portal.normal;
|
||||
|
||||
|
||||
_position = linked_portal.position + transformed_relative_pos - new_movement;
|
||||
// _position = (linked_portal.position) + (_position - obj.position) - (((distance_future_pos - distance_portal + imprecision)) * linked_portal.normal);
|
||||
|
||||
// view direction
|
||||
|
||||
glm::vec2 previous_direction = getDirection();
|
||||
_forward = glm::vec3(portal_transform * glm::vec4(_forward, 1.0f));
|
||||
_up = glm::vec3(portal_transform * glm::vec4(_up, 1.0f));
|
||||
_right = glm::vec3(portal_transform * glm::vec4(_right, 1.0f));
|
||||
@ -143,6 +146,8 @@ int Camera::portalTeleport(Scene *scene, float delta_time)
|
||||
|
||||
_velocity = glm::vec3(portal_transform * glm::vec4(_velocity, 0.0f));
|
||||
|
||||
renderer.addTeleport(previous_position, previous_direction, linked_portal.position + transformed_relative_pos, getDirection());
|
||||
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */
|
||||
/* Updated: 2025/02/16 23:57:31 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/02/17 23:20:03 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -572,6 +572,11 @@ void Renderer::makeMovement(float timeFromStart, float curSplitTimeReset)
|
||||
dir = to.dir;
|
||||
_curSplitStart = curSplitTimeReset;
|
||||
_curPathIndex++;
|
||||
while( _curPathIndex < _destPathIndex && _path[_curPathIndex].time == _path[_curPathIndex + 1].time)
|
||||
{
|
||||
_curPathIndex++;
|
||||
std::cout << "skip tp" << std::endl;
|
||||
}
|
||||
}
|
||||
cam->setPosition(pos);
|
||||
cam->setDirection(dir.x, dir.y);
|
||||
@ -584,21 +589,42 @@ void Renderer::makeMovement(float timeFromStart, float curSplitTimeReset)
|
||||
}
|
||||
}
|
||||
|
||||
float Renderer::calcTime(void)
|
||||
void Renderer::addTeleport(glm::vec3 from_pos, glm::vec2 from_dir, glm::vec3 to_pos, glm::vec2 to_dir)
|
||||
{
|
||||
t_pathPoint point;
|
||||
|
||||
if(!_autoTP || !_path.size() || !_autoTime)
|
||||
return ;
|
||||
|
||||
point.pos = from_pos;
|
||||
point.dir = from_dir;
|
||||
point.time = calcTime(from_pos);
|
||||
_path.push_back(point);
|
||||
|
||||
point.pos = to_pos;
|
||||
point.dir = to_dir;
|
||||
_path.push_back(point);
|
||||
}
|
||||
|
||||
float Renderer::calcTime(glm::vec3 pos)
|
||||
{
|
||||
float prevSpeed;
|
||||
float time;
|
||||
int index;
|
||||
|
||||
prevSpeed = 0;
|
||||
if(_path.size() > 1)
|
||||
prevSpeed = glm::distance(_path[_path.size() - 2].pos, _path[_path.size() - 1].pos) / (_path[_path.size() - 1].time - _path[_path.size() - 2].time);
|
||||
else
|
||||
prevSpeed = 0;
|
||||
{
|
||||
index = _path.size() - 1;
|
||||
while(index >= 1 && _path[index].time == _path[index - 1].time)
|
||||
index--;
|
||||
prevSpeed = glm::distance(_path[index - 1].pos, _path[index].pos) / (_path[index].time - _path[index - 1].time);
|
||||
}
|
||||
|
||||
if(_autoTime)
|
||||
{
|
||||
_tp = 0;
|
||||
if(_path.size() > 1)
|
||||
time = _path[_path.size() - 1].time + (glm::distance(_path[_path.size() - 1].pos, _scene->getCamera()->getPosition()) / prevSpeed);
|
||||
time = _path[_path.size() - 1].time + (glm::distance(_path[_path.size() - 1].pos, pos) / prevSpeed);
|
||||
else
|
||||
time = (float)_path.size() / 60;
|
||||
if(std::isnan(time))
|
||||
@ -608,7 +634,6 @@ float Renderer::calcTime(void)
|
||||
}
|
||||
else if(_tp)
|
||||
{
|
||||
_autoTime = 0;
|
||||
if(!_path.size())
|
||||
time = 0;
|
||||
else
|
||||
@ -652,10 +677,20 @@ void Renderer::imguiPathCreation(void)
|
||||
_autoTime = 0;
|
||||
_tp = 0;
|
||||
}
|
||||
time = calcTime();
|
||||
time = calcTime(_scene->getCamera()->getPosition());
|
||||
|
||||
ImGui::Checkbox("guess time automatically", &_autoTime);
|
||||
ImGui::Checkbox("tp", &_tp);
|
||||
if (ImGui::Checkbox("guess time automatically", &_autoTime))
|
||||
_tp = 0;
|
||||
|
||||
if(_autoTime)
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("auto tp", &_autoTP);
|
||||
}
|
||||
|
||||
|
||||
if (ImGui::Checkbox("tp", &_tp))
|
||||
_autoTime = 0;
|
||||
if(ImGui::Button("add step"))
|
||||
addPoint(time);
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */
|
||||
/* Updated: 2025/02/15 22:54:33 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/02/17 21:40:43 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -164,7 +164,7 @@ void Window::display()
|
||||
void Window::pollEvents()
|
||||
{
|
||||
this->process_input();
|
||||
_scene->getCamera()->update(_scene, _delta);
|
||||
_scene->getCamera()->update(_scene, _delta, *_renderer);
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
Reference in New Issue
Block a user