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

[Suggestion] Easing GTX #761

Closed
Robadob opened this issue May 5, 2018 · 2 comments
Closed

[Suggestion] Easing GTX #761

Robadob opened this issue May 5, 2018 · 2 comments
Assignees
Milestone

Comments

@Robadob
Copy link

Robadob commented May 5, 2018

Easing functions are useful in animation and similar, currently as far I can tell, glm only has linear interpolation (mix, lerp) and spherical interpolation (slerp for quaternions).

Examples of the kind of things I'm talking about here.

An easy strategy would be to convert this file (it has one of the ultra liberal licenses), so that each contained function is templated and returns the result of forwarding the original return value to the corresponding linear interpolation function.

I'm happy to produce the above if you agree that it would be a useful addition.

@Robadob
Copy link
Author

Robadob commented May 5, 2018

Slow evening, so I made a version that builds in Visual Studio 2013 for vec, dvec and quat types here.

If you want any refinements made, or it's worth submitting a pull request, let me know.

Thanks


Edit 3 : Having checked them all visually, backInOut was incorrect, failing to meet in the middle. I've instead replaced it's functions with the formulas from STween wiki. This has added the ability to provide an optional 'overshoot' parameter to further modify the ease function. Updated gist here .


Edit 2 : I've made the changes specified in edit 1 to the gist .


Edit 1 : Having thought more on this, two things come to mind.

  1. The easing functions really need to also be available for float and double, this isn't available in the above implementation.
  2. Internal of the easing quat users are more likely to desire slerp, although mix/lerp may also be desirable in some cases (I guess).

This leads to the thought that it would be better structured closer to the original file mentioned in the OP. With each function instead taking the form e.g.

template <typename genType>
GLM_FUNC_DECL genType cubicEaseOut(genType const & a);

Such that they can be used e.g.

{
    float a, b, c;
    c = glm::mix(a, b, glm::cubicEaseOut(0.5f));
}
{
    glm::vec3 a, b, c;
    c = glm::mix(a, b, glm::cubicEaseOut(0.5f));
}
{
    glm::dvec3 a, b, c;
    c = glm::mix(a, b, glm::cubicEaseOut(0.5));
}
{
    glm::quat a, b, c;
    c = glm::slerp(a, b, glm::cubicEaseOut(0.5f));
}

This would also make the underlying code alot cleaner. But without working directly on the types it feels a little less GLM relevant imo.

@Groovounet
Copy link
Member

Hi,
I added you proposed implementation with some edits to the master repository.
I can picture that additional work is needed but PRs are welcome.

Thanks for contributing,
Christophe

@Groovounet Groovounet self-assigned this May 7, 2018
@Groovounet Groovounet added this to the GLM 0.9.9 milestone May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants