Replay camera curve adjustment thing
authorhgn <hgodden00@gmail.com>
Sun, 10 Mar 2024 16:35:13 +0000 (16:35 +0000)
committerhgn <hgodden00@gmail.com>
Sun, 10 Mar 2024 16:35:13 +0000 (16:35 +0000)
player_replay.c

index 174851e952ba34c792427e97316940410c2cba48..6cff0c0fc8d450e598ba21f4117b4b9354f0313a 100644 (file)
@@ -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;