mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
change camera movement smoothing when movement is similar
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */
|
/* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/01/29 23:58:48 by tomoron ### ########.fr */
|
/* Updated: 2025/01/30 17:12:58 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class Renderer
|
|||||||
void imguiPathCreation(void);
|
void imguiPathCreation(void);
|
||||||
void imguiRenderInfo(void);
|
void imguiRenderInfo(void);
|
||||||
std::string floatToTime(float timef);
|
std::string floatToTime(float timef);
|
||||||
glm::vec2 sphereInterpolate(glm::vec2 from, glm::vec2 to, float time);
|
glm::vec2 bezierSphereInterpolate(glm::vec4 control, glm::vec2 from, glm::vec2 to, float time);
|
||||||
void updateAvailableCodecs(void);
|
void updateAvailableCodecs(void);
|
||||||
void fillGoodCodecList(std::vector<AVCodecID> &lst);
|
void fillGoodCodecList(std::vector<AVCodecID> &lst);
|
||||||
glm::vec3 hermiteInterpolate(glm::vec3 points[4], double alpha);
|
glm::vec3 hermiteInterpolate(glm::vec3 points[4], double alpha);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */
|
/* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/01/29 23:57:21 by tomoron ### ########.fr */
|
/* Updated: 2025/01/30 18:34:15 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -320,14 +320,14 @@ glm::quat eulerToQuaternion(float pitch, float yaw)
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
glm::vec2 Renderer::sphereInterpolate(glm::vec2 from, glm::vec2 to, float time)
|
glm::vec2 Renderer::bezierSphereInterpolate(glm::vec4 control, glm::vec2 from, glm::vec2 to, float time)
|
||||||
{
|
{
|
||||||
glm::vec2 delta;
|
glm::vec2 delta;
|
||||||
glm::vec2 p1, p2;
|
glm::vec2 p1, p2;
|
||||||
float t;
|
float t;
|
||||||
|
|
||||||
p1 = glm::vec2(0.20, 0);
|
p1 = glm::vec2(control.x, control.y);
|
||||||
p2 = glm::vec2(0.80, 1);
|
p2 = glm::vec2(control.z, control.w);
|
||||||
t = time;
|
t = time;
|
||||||
for(int i = 0; i < 5; i++) {
|
for(int i = 0; i < 5; i++) {
|
||||||
float currentX = 3.0f * ((1 - t) * (1 - t)) * t * p1.x + 3.0f * (1 - t) * (t * t) * p2.x + (t * t * t);
|
float currentX = 3.0f * ((1 - t) * (1 - t)) * t * p1.x + 3.0f * (1 - t) * (t * t) * p2.x + (t * t * t);
|
||||||
@ -369,6 +369,9 @@ void Renderer::makeMovement(float timeFromStart, float curSplitTimeReset)
|
|||||||
glm::vec3 pos;
|
glm::vec3 pos;
|
||||||
glm::vec2 dir;
|
glm::vec2 dir;
|
||||||
float normalTime;
|
float normalTime;
|
||||||
|
bool smallDistPrev;
|
||||||
|
bool smallDistNext;
|
||||||
|
glm::vec4 bezierControl;
|
||||||
|
|
||||||
from = _path[_curPathIndex];
|
from = _path[_curPathIndex];
|
||||||
to = _path[_curPathIndex + 1];
|
to = _path[_curPathIndex + 1];
|
||||||
@ -376,18 +379,24 @@ void Renderer::makeMovement(float timeFromStart, float curSplitTimeReset)
|
|||||||
prev = _path[_curPathIndex - 1];
|
prev = _path[_curPathIndex - 1];
|
||||||
else
|
else
|
||||||
prev = from;
|
prev = from;
|
||||||
if((size_t)_curPathIndex + 3 == _path.size())
|
if((size_t)_curPathIndex + 2 < _path.size())
|
||||||
next = _path[_curPathIndex + 2];
|
next = _path[_curPathIndex + 2];
|
||||||
else
|
else
|
||||||
next = to;
|
next = to;
|
||||||
|
|
||||||
|
|
||||||
cam = _scene->getCamera();
|
cam = _scene->getCamera();
|
||||||
pathTime = (to.time - from.time) * 60;
|
pathTime = (to.time - from.time) * 60;
|
||||||
normalTime = 1 - ((pathTime - timeFromStart) / pathTime);
|
normalTime = 1 - ((pathTime - timeFromStart) / pathTime);
|
||||||
|
|
||||||
pos = hermiteInterpolate((glm::vec3 [4]){prev.pos, from.pos, to.pos, next.pos}, normalTime);
|
pos = hermiteInterpolate((glm::vec3 [4]){prev.pos, from.pos, to.pos, next.pos}, normalTime);
|
||||||
dir = sphereInterpolate(from.dir, to.dir, normalTime);
|
|
||||||
|
smallDistPrev = glm::distance((to.dir - from.dir) / glm::vec2(pathTime), (from.dir - prev.dir) / glm::vec2((from.time - prev.time) * 60)) < 40;
|
||||||
|
smallDistNext = glm::distance((to.dir - from.dir) / glm::vec2(pathTime), (next.dir - to.dir) / glm::vec2((next.time - to.time) * 60)) < 40;
|
||||||
|
bezierControl.x = 0.2f;
|
||||||
|
bezierControl.y = !_curPathIndex || smallDistPrev ? .1f : .0f;
|
||||||
|
bezierControl.z = 0.8f;
|
||||||
|
bezierControl.w = (size_t)_curPathIndex + 2 >= _path.size() || smallDistNext ? .9f : 1.0f;
|
||||||
|
dir = bezierSphereInterpolate(bezierControl, from.dir, to.dir, normalTime);
|
||||||
if(std::isnan(dir.x) || std::isnan(dir.y))
|
if(std::isnan(dir.x) || std::isnan(dir.y))
|
||||||
dir = from.dir;
|
dir = from.dir;
|
||||||
if(timeFromStart >= pathTime)
|
if(timeFromStart >= pathTime)
|
||||||
|
Reference in New Issue
Block a user