29 : tween_(tween), apply_(
std::move(apply)) {}
32 float v = tween_.advance(dt);
33 if (apply_) apply_(
v);
36 bool finished()
const override {
return tween_.finished(); }
37 void reset()
override { tween_.reset(); }
41 std::function<void(
float)> apply_;
47 void add(std::unique_ptr<AnimationStep> step) {
48 steps_.push_back(std::move(step));
52 for (
auto&
s : steps_)
59 for (
auto&
s : steps_)
60 if (!
s->finished())
return false;
65 for (
auto&
s : steps_)
70 std::vector<std::unique_ptr<AnimationStep>> steps_;
89 std::function<
void(
float)> apply,
91 steps_.push_back(std::make_unique<TweenStep>(
92 Tween(from, to, duration, ease), std::move(apply)));
98 steps_.push_back(std::make_unique<TweenStep>(
99 Tween(0, 0, seconds),
nullptr));
105 parallel_ = std::make_unique<ParallelStep>();
111 std::function<
void(
float)> apply,
114 parallel_->add(std::make_unique<TweenStep>(
115 Tween(from, to, duration, ease), std::move(apply)));
123 steps_.push_back(std::move(parallel_));
129 std::vector<std::unique_ptr<AnimationStep>>
build() {
130 return std::move(steps_);
136 explicit Runner(std::vector<std::unique_ptr<AnimationStep>> steps,
137 std::string
name = {})
138 : steps_(
std::move(steps)) {
140 provenance_.source_kind =
"animator-set";
141 provenance_.source_id = std::move(name);
146 while (current_ <
static_cast<int>(steps_.size()) && dt > 0) {
147 steps_[current_]->advance(dt);
156 return current_ >=
static_cast<int>(steps_.size());
160 return current_ >=
static_cast<int>(steps_.size());
165 for (
auto&
s : steps_)
173 std::string metric_name,
176 if (provenance_.
is_set() && !opts.provenance.is_set()) {
177 opts.provenance = provenance_;
188 std::vector<std::unique_ptr<AnimationStep>> steps_;
194 return Runner(std::move(steps_), name_);
198 std::vector<std::unique_ptr<AnimationStep>> steps_;
199 std::unique_ptr<ParallelStep> parallel_;
207 inline float cubic_bezier(
float t,
float x1,
float y1,
float x2,
float y2) {
209 float cx = 3.0f * x1;
210 float bx = 3.0f * (x2 - x1) - cx;
211 float ax = 1.0f - cx - bx;
213 float cy = 3.0f * y1;
214 float by = 3.0f * (y2 - y1) - cy;
215 float ay = 1.0f - cy - by;
219 for (
int i = 0;
i < 8; ++
i) {
220 float x = ((ax * guess + bx) * guess + cx) * guess -
t;
221 float dx = (3.0f * ax * guess + 2.0f * bx) * guess + cx;
222 if (std::abs(dx) < 1e-7f)
break;
226 return ((ay * guess + by) * guess + cy) * guess;
230 inline float spring(
float t,
float stiffness = 100.0f,
float damping = 10.0f) {
231 float omega = std::sqrt(stiffness);
232 float zeta = damping / (2.0f * omega);
236 float omega_d = omega * std::sqrt(1.0f - zeta * zeta);
237 return 1.0f - std::exp(-zeta * omega *
t) *
238 (std::cos(omega_d *
t) + (zeta * omega / omega_d) * std::sin(omega_d *
t));
242 return 1.0f - (1.0f + omega *
t) * std::exp(-omega *
t);
247 float s = 1.70158f * 1.525f;
249 return (2.0f *
t *
t * ((
s + 1.0f) * 2.0f *
t -
s)) * 0.5f;
251 float u = 2.0f *
t - 2.0f;
252 return (
u *
u * ((
s + 1.0f) *
u +
s) + 2.0f) * 0.5f;
259 float x = 0,
y = 0,
z = 0;
267 return {
y *
o.z -
z *
o.y,
z *
o.x -
x *
o.z,
x *
o.y -
y *
o.x};
277 float w = 1,
x = 0,
y = 0,
z = 0;
282 float half = radians * 0.5f;
283 float s = std::sin(half);
285 return {std::cos(half),
n.x *
s,
n.y *
s,
n.z *
s};
290 w *
q.w -
x *
q.x -
y *
q.y -
z *
q.z,
291 w *
q.x +
x *
q.w +
y *
q.z -
z *
q.y,
292 w *
q.y -
x *
q.z +
y *
q.w +
z *
q.x,
293 w *
q.z +
x *
q.y -
y *
q.x +
z *
q.w
308 float dot =
a.w *
b.w +
a.x *
b.x +
a.y *
b.y +
a.z *
b.z;
315 a.w +
t * (b2.
w -
a.w),
316 a.x +
t * (b2.
x -
a.x),
317 a.y +
t * (b2.
y -
a.y),
318 a.z +
t * (b2.
z -
a.z)
322 float theta = std::acos(dot);
323 float sin_theta = std::sin(theta);
324 float wa = std::sin((1.0f -
t) * theta) / sin_theta;
325 float wb = std::sin(
t * theta) / sin_theta;
328 wa *
a.w + wb * b2.
w,
329 wa *
a.x + wb * b2.
x,
330 wa *
a.y + wb * b2.
y,
339 return {result.
x, result.
y, result.
z};
349 drag_start_ = project_to_sphere(
x,
y);
350 start_orientation_ = orientation_;
355 if (!dragging_)
return;
359 float dot = drag_start_.dot(current);
361 if (axis.
length() > 1e-6f) {
362 float angle = std::acos(std::clamp(dot, -1.0f, 1.0f));
364 orientation_ = rotation * start_orientation_;
386 bool dragging_ =
false;
388 static Vector3D project_to_sphere(
float x,
float y) {
389 float d =
x *
x +
y *
y;
391 return {
x,
y, std::sqrt(1.0f -
d)};
392 float scale = 1.0f / std::sqrt(
d);
A step in an animation sequence — either a tween or a parallel group.
Definition animator_set.hpp:17
virtual ~AnimationStep()=default
virtual bool finished() const =0
virtual float advance(float dt)=0
Run the built animation. Advances through sequence, returns true when all done.
Definition animator_set.hpp:134
const motion::Provenance & motion_provenance() const noexcept
Definition animator_set.hpp:183
bool finished() const
Definition animator_set.hpp:159
void publish(std::string view_name, std::string metric_name, double value, motion::PublishOptions opts={}) const
Publish the runner's current scalar through the motion publish channel, stamping the animator-set nam...
Definition animator_set.hpp:172
bool advance(float dt)
Definition animator_set.hpp:145
void reset()
Definition animator_set.hpp:163
Runner(std::vector< std::unique_ptr< AnimationStep > > steps, std::string name={})
Definition animator_set.hpp:136
Builder for composing animation sequences and parallel groups.
Definition animator_set.hpp:74
Runner build_runner()
Definition animator_set.hpp:193
std::vector< std::unique_ptr< AnimationStep > > build()
Build and return the step sequence.
Definition animator_set.hpp:129
AnimatorSetBuilder & with(float from, float to, float duration, std::function< void(float)> apply, EasingFunction ease=easing::linear)
Add a tween to the current parallel group.
Definition animator_set.hpp:110
AnimatorSetBuilder & end_parallel()
End parallel group and add it to the sequence.
Definition animator_set.hpp:121
AnimatorSetBuilder & then(float from, float to, float duration, std::function< void(float)> apply, EasingFunction ease=easing::linear)
Add a tween that runs in sequence.
Definition animator_set.hpp:88
AnimatorSetBuilder & begin_parallel()
Start a parallel group — all tweens added until end_parallel() run together.
Definition animator_set.hpp:104
AnimatorSetBuilder & delay(float seconds)
Add a delay (tween from 0 to 0).
Definition animator_set.hpp:97
AnimatorSetBuilder & name(std::string n)
Assign a logical name to this animator set.
Definition animator_set.hpp:80
const std::string & configured_name() const noexcept
Definition animator_set.hpp:85
Draggable 3D orientation — arcball rotation from mouse drag.
Definition animator_set.hpp:344
void begin_drag(float x, float y)
Begin a drag at the given 2D screen position (normalized -1 to 1).
Definition animator_set.hpp:347
const Quaternion & orientation() const
Current orientation quaternion.
Definition animator_set.hpp:372
void reset()
Reset to identity (also cancels any active drag).
Definition animator_set.hpp:375
void end_drag()
End the drag.
Definition animator_set.hpp:369
void update_drag(float x, float y)
Update during drag.
Definition animator_set.hpp:354
Parallel group — all steps run simultaneously.
Definition animator_set.hpp:45
bool finished() const override
Definition animator_set.hpp:58
void add(std::unique_ptr< AnimationStep > step)
Definition animator_set.hpp:47
void reset() override
Definition animator_set.hpp:64
float advance(float dt) override
Definition animator_set.hpp:51
void reset() override
Definition animator_set.hpp:37
float advance(float dt) override
Definition animator_set.hpp:31
bool finished() const override
Definition animator_set.hpp:36
TweenStep(Tween tween, std::function< void(float)> apply)
Definition animator_set.hpp:28
Definition animation.hpp:72
Agent-first motion observability: sample view geometry, scroll state, and arbitrary scalar values at ...
float spring(float t, float stiffness=100.0f, float damping=10.0f)
Spring physics easing (damped oscillation).
Definition animator_set.hpp:230
float linear(float t)
Definition animation.hpp:26
float cubic_bezier(float t, float x1, float y1, float x2, float y2)
Cubic bezier easing (simplified — approximates CSS cubic-bezier).
Definition animator_set.hpp:207
float ease_in_out_back(float t)
Ease-in-out back (slight overshoot).
Definition animator_set.hpp:246
void publish_value(std::string view_name, std::string metric_name, double value, PublishOptions opts={})
Single-component publish.
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ value
the widget's primary value (Knob, Fader, RangeSlider, Toggle, ProgressBar)
Definition binding_diagnostics.hpp:19
@ s
Definition input_events.hpp:41
@ a
Definition input_events.hpp:39
@ y
Definition input_events.hpp:42
@ q
Definition input_events.hpp:41
@ u
Definition input_events.hpp:41
@ n
Definition input_events.hpp:40
@ d
Definition input_events.hpp:39
@ p
Definition input_events.hpp:40
@ i
Definition input_events.hpp:40
@ b
Definition input_events.hpp:39
@ x
Definition input_events.hpp:41
@ v
Definition input_events.hpp:41
@ o
Definition input_events.hpp:40
@ t
Definition input_events.hpp:41
@ scale
Definition css_animation.hpp:126
float(*)(float) EasingFunction
Definition animation.hpp:51
Definition animator_set.hpp:276
Vector3D rotate(const Vector3D &v) const
Rotate a vector by this quaternion.
Definition animator_set.hpp:336
Quaternion conjugate() const
Definition animator_set.hpp:297
static Quaternion slerp(const Quaternion &a, const Quaternion &b, float t)
Spherical linear interpolation.
Definition animator_set.hpp:307
float y
Definition animator_set.hpp:277
static Quaternion identity()
Definition animator_set.hpp:279
float length() const
Definition animator_set.hpp:299
Quaternion normalized() const
Definition animator_set.hpp:301
float z
Definition animator_set.hpp:277
static Quaternion from_axis_angle(const Vector3D &axis, float radians)
Definition animator_set.hpp:281
float x
Definition animator_set.hpp:277
Quaternion operator*(const Quaternion &q) const
Definition animator_set.hpp:288
float w
Definition animator_set.hpp:277
Definition animator_set.hpp:258
Vector3D normalized() const
Definition animator_set.hpp:270
Vector3D operator-(const Vector3D &o) const
Definition animator_set.hpp:262
Vector3D cross(const Vector3D &o) const
Definition animator_set.hpp:266
float dot(const Vector3D &o) const
Definition animator_set.hpp:265
Vector3D operator+(const Vector3D &o) const
Definition animator_set.hpp:261
float x
Definition animator_set.hpp:259
float length() const
Definition animator_set.hpp:269
Vector3D operator*(float s) const
Definition animator_set.hpp:263
float y
Definition animator_set.hpp:259
float z
Definition animator_set.hpp:259
bool is_set() const noexcept
Definition motion.hpp:85
Definition motion.hpp:181