Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Enable non-linear easing #42

Merged
merged 5 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Match Identifier - Case Sensitive
[default.extend-identifiers]
t1_iy = "t1_iy"
t0_iy = "t0_iy"
tranform_before_mask_deprecated = "tranform_before_mask_deprecated"

# Match Inside a Word - Case Insensitive
Expand Down
28 changes: 12 additions & 16 deletions src/runtime/model/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ impl Time {
let t0 = times[ix0];
let t1 = times[ix1];
let (t0_ox, t0_oy) = t0.out_tangent.map(|o| (o.x, o.y)).unwrap_or((0.0, 0.0));
let (t1_ix, t1_iy) = t1.in_tangent.map(|i| (i.x, i.y)).unwrap_or((1.0, 1.0));
let (t0_ix, t0_iy) = t0.in_tangent.map(|i| (i.x, i.y)).unwrap_or((1.0, 1.0));
let easing = Easing {
o: EasingHandle { x: t0_ox, y: t0_oy },
i: EasingHandle { x: t1_ix, y: t1_iy },
i: EasingHandle { x: t0_ix, y: t0_iy },
};
let hold = t0.hold;
let t = (frame - t0.frame) / (t1.frame - t0.frame);
Expand Down Expand Up @@ -160,20 +160,16 @@ pub trait Tween: Clone + Default {
}

impl Tween for f64 {
fn tween(&self, other: &Self, t: f64, _easing: &Easing) -> Self {
// TODO: We are enforcing linear interpolation for now, but a decent amount of work is done for easings.
keyframe::ease(keyframe::functions::Linear, *self, *other, t)

// FIXME: Hopefully we can finish this up one day!
//keyframe::ease(
// keyframe::functions::BezierCurve::from(
// keyframe::mint::Vector2::from_slice(&[easing.o.x, easing.o.y]),
// keyframe::mint::Vector2::from_slice(&[easing.i.x, easing.i.y]),
// ),
// *self,
// *other,
// t,
//)
fn tween(&self, other: &Self, t: f64, easing: &Easing) -> Self {
keyframe::ease(
keyframe::functions::BezierCurve::from(
keyframe::mint::Vector2::from_slice(&[easing.o.x, easing.o.y]),
keyframe::mint::Vector2::from_slice(&[easing.i.x, easing.i.y]),
),
*self,
*other,
t,
)
}
}

Expand Down