Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Core: Lerp overload with custom easing function#267

Open
ismail-yilmaz wants to merge 2 commits into
ultimatepp:masterfrom
ismail-yilmaz:lerp_iteration
Open

Core: Lerp overload with custom easing function#267
ismail-yilmaz wants to merge 2 commits into
ultimatepp:masterfrom
ismail-yilmaz:lerp_iteration

Conversation

@ismail-yilmaz
Copy link
Copy Markdown
Member

@ismail-yilmaz ismail-yilmaz commented May 6, 2025

This PR does two things:

  1. Makes the existing Lerp function constexpr and marks it with noexcept
  2. Proposes a Lerp overload that takes a custom easing function. This easing function can easily be used to achieve different effects, such as bounce-in/bounce-out, ease-in/ease-out, etc. Overload can work with large types (vectors and matrices with properly defined operators)

An example easing function (bounce out) can look like this:

constexpr double BounceOut(double t) noexcept // Piecewise quadratic function to create a bouncing effect.
{
	if(t < 4.0 / 11.0)
		return (121.0 * t * t) / 16.0;
	if(t < 8.0 / 11.0)
		return (363.0 / 40.0 * t * t) - (99.0 / 10.0 * t) + 17.0 / 5.0;
	if(t < 9.0 / 10.0)
		return (4356.0 / 361.0 * t * t) - (35442.0 / 1805.0 * t) + 16061.0 / 1805.0;
	return (54.0 / 5.0 * t * t) - (513.0 / 25.0 * t) + 268.0 / 25.0;
}

This patch does and should not break anything.

P.s.: While the C++17 standard implicity assumes that a constexpr function is hinting inline, I explicitly added them for clarity.

Please review.

@ismail-yilmaz
Copy link
Copy Markdown
Member Author

@mirek-fidler

Any thoughts about this one?

@mirek-fidler
Copy link
Copy Markdown
Contributor

#274

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants