Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Easing curves for tuples #16945

Merged
merged 1 commit into from
Dec 24, 2024
Merged

Conversation

mweatherley
Copy link
Contributor

Objective

Make it so that users can ease between tuples of easeable values.

Solution

Use variadics_please's all_tuples_enumerated macro to generate code that creates these trait implementations. For two elements, the result looks like this:

impl<T0: Ease, T1: Ease> Ease for (T0, T1) {
    fn interpolating_curve_unbounded(start: Self, end: Self) -> impl Curve<Self> {
        let curve_tuple = (
            <T0 as Ease>::interpolating_curve_unbounded(start.0, end.0),
            <T1 as Ease>::interpolating_curve_unbounded(start.1, end.1),
        );
        FunctionCurve::new(Interval::EVERYWHERE, move |t| {
            (
                curve_tuple.0.sample_unchecked(t),
                curve_tuple.1.sample_unchecked(t),
            )
        })
    }
}

Testing

It compiles, and I futzed about with some manual examples, which seem to work as expected.


Showcase

Easing curves now support easing tuples of values that can themselves be eased. For example:

// Easing between two `(Vec3, Quat)` values:
let easing_curve = EasingCurve::new(
    (vec3(0.0, 0.0, 0.0), Quat::from_rotation_z(-FRAC_PI_2)),
    (vec3(1.0, 1.0, 1.0), Quat::from_rotation_z(FRAC_PI_2)),
    EaseFunction::ExponentialInOut
);

@mweatherley mweatherley added C-Feature A new feature, making something new possible C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Math Fundamental domain-agnostic mathematical operations D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 23, 2024
Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

@BenjaminBrienen BenjaminBrienen added S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 24, 2024
@lewiszlw lewiszlw added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! labels Dec 24, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 24, 2024
Merged via the queue into bevyengine:main with commit 43d5472 Dec 24, 2024
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Math Fundamental domain-agnostic mathematical operations C-Feature A new feature, making something new possible C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants