From 8cb5eb6b0e5ef1c0506920fee2c73c4339ebdadc Mon Sep 17 00:00:00 2001 From: hgn Date: Sun, 10 Mar 2024 16:35:13 +0000 Subject: [PATCH] Replay camera curve adjustment thing --- player_replay.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/player_replay.c b/player_replay.c index 174851e..6cff0c0 100644 --- a/player_replay.c +++ b/player_replay.c @@ -322,6 +322,25 @@ void skaterift_get_replay_cam( vg_camera *cam ) l = te-ts; t = (replay->cursor-ts)/l; + /* + * Adjust t, so that its derivative matches at the endpoints. + * Since t needs to go from 0 to 1, it will naturally change at + * different rates between keyframes. So this smooths it out. + * + * Newton method, going through standard direct quadratic eq has + * precision / other problems. Also we only care about 0>t>1. + */ + f32 b = (kf[1].time-ts)/l, + x0 = 1.0-t; + for( u32 i=0; i<4; i ++ ) + { + f32 ix0 = 1.0f-x0, + fx_x0 = 2.0f*b*x0*ix0 + ix0*ix0 - t, + fxd_x0 = 2.0f*(-2.0f*b*x0 + b + x0 - 1.0f); + x0 = x0 - (fx_x0/fxd_x0); + } + t = 1.0-x0; + f32 t0 = t*m_start+(1.0f-m_start), t1 = t*m_end; -- 2.25.1