-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
add curve utilities to create curves interpolating/easing between two values #14788
add curve utilities to create curves interpolating/easing between two values #14788
Conversation
Sorry if the comments seem mean! I appreciate the PR even though I nitpicked it a lot. |
line_curve
, easing_curve
and easing functionsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, first off thanks! You're one of the first people I've seen to start doing stuff with curves, and I think you're doing great. Really appreciate it.
In the discord, @mweatherley suggested that we might want something more like the following
fn eased_curve_between<T>(start: T, end: T, easing: impl Curve<f32>) -> impl Curve<T>
where
T: VectorSpace
{
let span = end - start;
easing.map(|x| (x * span) + start)
}
Then we define a set of concrete easing curves (like these) which pass through (0, 0)
and (1, 1)
.
We could even define a marker trait which has this invariant in it's docs as a contract.
trait EasingCurve: Curve<f32> {};
However, I don't see anything wrong with the current implementation and I do think it's in a merge-able state pretty much. So if you'd prefer, we can marge and refactor the api as follow-up.
Thanks for the review comment. That makes sense! Nevertheless I think that #14788 (comment) is also pretty valid. So I'd rather create a new struct |
58ba8cf
to
cff9622
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cff9622
to
0623e29
Compare
c0d325a
to
fcf5566
Compare
Co-Authored-By: Miles Silberling-Cook <NthTensor@users.noreply.github.com>
772ca80
to
3f9908f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple and lovely. @RobWalt when you have a chance, I'd appreciate merge conflict resolution here :)
This will be merged before the 0.15 release candidate, but I'll give you a bit of time to clean up those nits if you have the chance. |
Co-authored-by: Matty <weatherleymatthew@gmail.com>
… values (bevyengine#14788) # Objective Citing @mweatherley > There is a lot of shortfall for simple cases— e.g., we should have library functions for making a curve connecting two points, eased versions of that, and so on. ## Solution This PR implements - a simple `Easing` trait which is implemented for all `impl Curve<f32>` types. We can't really guarantee that these curves have unit interval domain, which some people would probably expect, but it is documented that this isn't the case for these types and we redirect to `EasingCurve` which is used for that purpose - an `EasingCurve` struct, which is used to interpolate between two values `start` and `end` using a `impl Easing` curve where the curve will be guaranteed to be reparametrized - a `LinearCurve` which linearly interpolates between two values `start` and `end` - a `CubicBezierCurve` which interpolates between `start` and `end` values using a `CubicSegment` - a `StepCurve` which interpolates between `start` and `end` with an step-function with `n` steps - an `ElasticCurve` which interpolates between `start` and `end` with spring like behavior where the elasticity of the spring is configurable - some `FunctionCurve` easing curves for different popular functions including: `quadratic_ease_in`, `quadratic_ease_out`, `smoothstep`, `identity` ## Testing - there are a few new tests for all of these in the main module --------- Co-authored-by: eckz <567737+eckz@users.noreply.github.com> Co-authored-by: Miles Silberling-Cook <NthTensor@users.noreply.github.com> Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: Matty <weatherleymatthew@gmail.com>
# Objective - Followup for #14788 - Support most usual ease function ## Solution - Use the crate [`interpolation`](https://docs.rs/interpolation/0.3.0/interpolation/trait.Ease.html) which has them all - it's already used by bevy_easings, bevy_tweening, be_tween, bevy_tweening_captured, bevy_enoki, kayak_ui in the Bevy ecosystem for various easing/tweening/interpolation
Objective
Citing @mweatherley
Solution
This PR implements
Easing
trait which is implemented for allimpl Curve<f32>
types. We can't really guarantee that these curves have unit interval domain, which some people would probably expect, but it is documented that this isn't the case for these types and we redirect toEasingCurve
which is used for that purposeEasingCurve
struct, which is used to interpolate between two valuesstart
andend
using aimpl Easing
curve where the curve will be guaranteed to be reparametrizedLinearCurve
which linearly interpolates between two valuesstart
andend
CubicBezierCurve
which interpolates betweenstart
andend
values using aCubicSegment
StepCurve
which interpolates betweenstart
andend
with an step-function withn
stepsElasticCurve
which interpolates betweenstart
andend
with spring like behavior where the elasticity of the spring is configurableFunctionCurve
easing curves for different popular functions including:quadratic_ease_in
,quadratic_ease_out
,smoothstep
,identity
Testing