vibe/animation/families/
spatial.rs1use crate::animation::curves::EasingCurve;
4use crate::animation::pga::Motor;
5use crate::animation::presets::AnimationSample;
6use crate::animation::spring::{SpringConfig, SpringState1D};
7
8pub fn eval(preset: &str, t: f64) -> AnimationSample {
10 match preset {
11 "orbit_spin" | "orbit" => {
12 let angle = t * std::f64::consts::PI * 2.0 * 0.5; let radius = 10.0;
14 let x = radius * angle.cos();
15 let z = radius * angle.sin();
16 let motor = Motor::from_rotation_translation(
17 [(angle * 0.5).cos(), 0.0, (angle * 0.5).sin(), 0.0],
18 [x, 0.0, z],
19 );
20 AnimationSample {
21 scalar: angle,
22 vector: [x, 0.0, z],
23 motor,
24 secondary: radius,
25 settled: false,
26 }
27 }
28 "hero_drift" => {
29 let progress = (t * 0.2).clamp(0.0, 1.0);
30 let ease = EasingCurve::CubicInOut.eval(progress);
31 let m0 = Motor::identity();
32 let m1 =
33 Motor::from_rotation_translation([0.9238, 0.0, 0.3826, 0.0], [5.0, 2.0, -10.0]);
34 let motor = Motor::sclerp(&m0, &m1, ease);
35 let (_, trans) = motor.to_rotation_translation();
36 AnimationSample {
37 scalar: ease,
38 vector: trans,
39 motor,
40 secondary: 1.0 - ease,
41 settled: progress >= 1.0,
42 }
43 }
44 "elastic_snap" => {
45 let config = SpringConfig::snappy();
46 let state = SpringState1D::new(0.0, 0.0, 10.0);
47 let (pos, vel, settled) = state.evaluate_at(&config, t);
48 let motor = Motor::from_rotation_translation([1.0, 0.0, 0.0, 0.0], [pos, 0.0, 0.0]);
49 AnimationSample {
50 scalar: pos,
51 vector: [pos, 0.0, 0.0],
52 motor,
53 secondary: vel,
54 settled,
55 }
56 }
57 "geodesic_warp" => {
58 let phase = t * 0.8;
59 let curvature = (phase * 1.5).sin() * 0.5;
60 let r = 1.0 + curvature;
61 let motor = Motor::from_rotation_translation(
62 [(phase * 0.25).cos(), 0.0, (phase * 0.25).sin(), 0.0],
63 [curvature * 2.0, 0.0, 0.0],
64 );
65 AnimationSample {
66 scalar: curvature,
67 vector: [r, r, r],
68 motor,
69 secondary: phase,
70 settled: false,
71 }
72 }
73 _ => AnimationSample::default(),
74 }
75}