3#include <Foundation/Math/Math.h>
7 PL_ALWAYS_INLINE
double GetCurveValue_Linear(
double t)
12 PL_ALWAYS_INLINE
double GetCurveValue_ConstantZero(
double t)
17 PL_ALWAYS_INLINE
double GetCurveValue_ConstantOne(
double t)
22 PL_ALWAYS_INLINE
double GetCurveValue_EaseInSine(
double t)
27 PL_ALWAYS_INLINE
double GetCurveValue_EaseOutSine(
double t)
32 PL_ALWAYS_INLINE
double GetCurveValue_EaseInOutSine(
double t)
37 PL_ALWAYS_INLINE
double GetCurveValue_EaseInQuad(
double t)
42 PL_ALWAYS_INLINE
double GetCurveValue_EaseOutQuad(
double t)
44 return 1.0 - (1.0 - t) * (1.0 - t);
47 PL_ALWAYS_INLINE
double GetCurveValue_EaseInOutQuad(
double t)
49 return t < 0.5 ? 2.0 * t * t : 1.0 - plMath::Pow(-2.0 * t + 2, 2.0) / 2;
52 PL_ALWAYS_INLINE
double GetCurveValue_EaseInCubic(
double t)
57 PL_ALWAYS_INLINE
double GetCurveValue_EaseOutCubic(
double t)
59 return 1.0 - pow(1 - t, 3.0);
63 PL_ALWAYS_INLINE
double GetCurveValue_EaseInOutCubic(
double t)
65 return t < 0.5 ? 4.0 * t * t * t : 1.0 - plMath::Pow(-2.0 * t + 2.0, 3.0) / 2.0;
69 PL_ALWAYS_INLINE
double GetCurveValue_EaseInQuartic(
double t)
75 PL_ALWAYS_INLINE
double GetCurveValue_EaseOutQuartic(
double t)
77 return 1.0 - plMath::Pow(1.0 - t, 4.0);
81 PL_ALWAYS_INLINE
double GetCurveValue_EaseInOutQuartic(
double t)
83 return t < 0.5 ? 8.0 * t * t * t * t : 1.0 - plMath::Pow(-2.0 * t + 2.0, 4.0) / 2.0;
87 PL_ALWAYS_INLINE
double GetCurveValue_EaseInQuintic(
double t)
89 return t * t * t * t * t;
93 PL_ALWAYS_INLINE
double GetCurveValue_EaseOutQuintic(
double t)
95 return 1.0 - plMath::Pow(1.0 - t, 5.0);
99 PL_ALWAYS_INLINE
double GetCurveValue_EaseInOutQuintic(
double t)
101 return t < 0.5 ? 16.0 * t * t * t * t * t : 1.0 - plMath::Pow(-2.0 * t + 2.0, 5.0) / 2.0;
105 PL_ALWAYS_INLINE
double GetCurveValue_EaseInExpo(
double t)
107 return t == 0 ? 0 : plMath::Pow(2.0, 10.0 * t - 10.0);
111 PL_ALWAYS_INLINE
double GetCurveValue_EaseOutExpo(
double t)
113 return t == 1.0 ? 1.0 : 1.0 - plMath::Pow(2.0, -10.0 * t);
117 PL_ALWAYS_INLINE
double GetCurveValue_EaseInOutExpo(
double t)
129 return t < 0.5 ? plMath::Pow(2.0, 20.0 * t - 10.0) / 2.0
130 : (2.0 - plMath::Pow(2.0, -20.0 * t + 10.0)) / 2.0;
135 PL_ALWAYS_INLINE
double GetCurveValue_EaseInCirc(
double t)
141 PL_ALWAYS_INLINE
double GetCurveValue_EaseOutCirc(
double t)
147 PL_ALWAYS_INLINE
double GetCurveValue_EaseInOutCirc(
double t)
150 ? (1.0 -
plMath::Sqrt(1.0 - plMath::Pow(2.0 * t, 2.0))) / 2.0
155 PL_ALWAYS_INLINE
double GetCurveValue_EaseInBack(
double t)
157 return 2.70158 * t * t * t - 1.70158 * t * t;
161 PL_ALWAYS_INLINE
double GetCurveValue_EaseOutBack(
double t)
163 return 1 + 2.70158 * plMath::Pow(t - 1.0, 3.0) + 1.70158 * plMath::Pow(t - 1.0, 2.0);
167 PL_ALWAYS_INLINE
double GetCurveValue_EaseInOutBack(
double t)
170 ? (plMath::Pow(2.0 * t, 2.0) * (((1.70158 * 1.525) + 1.0) * 2 * t - (1.70158 * 1.525))) / 2.0
171 : (
plMath::Pow(2.0 * t - 2.0, 2.0) * (((1.70158 * 1.525) + 1.0) * (t * 2.0 - 2.0) + (1.70158 * 1.525)) + 2.0) / 2.0;
175 PL_ALWAYS_INLINE
double GetCurveValue_EaseInElastic(
double t)
187 return -plMath::Pow(2.0, 10.0 * t - 10.0) * sin((t * 10.0 - 10.75) * ((2.0 *
plMath::Pi<double>()) / 3.0));
192 PL_ALWAYS_INLINE
double GetCurveValue_EaseOutElastic(
double t)
204 return plMath::Pow(2.0, -10.0 * t) * sin((t * 10.0 - 0.75) * ((2.0 *
plMath::Pi<double>()) / 3.0)) + 1.0;
208 PL_ALWAYS_INLINE
double GetCurveValue_EaseInOutElastic(
double t)
221 ? -(plMath::Pow(2.0, 20.0 * t - 10.0) * sin((20.0 * t - 11.125) * ((2 *
plMath::Pi<double>()) / 4.5))) / 2.0
222 : (
plMath::Pow(2.0, -20.0 * t + 10.0) * sin((20.0 * t - 11.125) * ((2 *
plMath::
Pi<double>()) / 4.5))) / 2.0 + 1.0;
226 PL_ALWAYS_INLINE
double GetCurveValue_EaseInBounce(
double t)
228 return 1.0 - GetCurveValue_EaseOutBounce(1.0 - t);
231 PL_ALWAYS_INLINE
double GetCurveValue_EaseOutBounce(
double t)
235 return 7.5625 * t * t;
237 else if (t < 2.0 / 2.75)
240 return 7.5625 * t * t + 0.75;
242 else if (t < 2.5 / 2.75)
245 return 7.5625 * t * t + 0.9375;
250 return 7.5625 * t * t + 0.984375;
254 PL_ALWAYS_INLINE
double GetCurveValue_EaseInOutBounce(
double t)
257 ? (1.0 - GetCurveValue_EaseOutBounce(1.0 - 2.0 * t)) / 2.0
258 : (1.0 + GetCurveValue_EaseOutBounce(2.0 * t - 1.0)) / 2.0;
261 PL_ALWAYS_INLINE
double GetCurveValue_Conical(
double t)
265 return 1.0f - plMath::Pow(1.0 - (t * 5.0), 4.0);
271 return 1.0 - plMath::Pow(t, 2.0);
275 PL_ALWAYS_INLINE
double GetCurveValue_FadeInHoldFadeOut(
double t)
279 return 1.0f - plMath::Pow(1.0 - (t * 5.0), 3.0);
283 return 1.0 - plMath::Pow((t - 0.8) * 5.0, 3.0);
291 PL_ALWAYS_INLINE
double GetCurveValue_FadeInFadeOut(
double t)
295 return 1.0f - plMath::Pow(1.0 - (t * 2.0), 3.0);
299 return 1.0 - plMath::Pow((t - 0.5) * 2.0, 3.0);
303 PL_ALWAYS_INLINE
double GetCurveValue_Bell(
double t)
307 return (plMath::Pow((t * 4.0), 3.0)) * 0.5;
311 return (1.0f - plMath::Pow(1.0 - ((t - 0.25) * 4.0), 3.0)) * 0.5 + 0.5;
315 return (1.0f - plMath::Pow(((t - 0.5) * 4.0), 3.0)) * 0.5 + 0.5;
319 return (plMath::Pow(1.0 - ((t - 0.75) * 4.0), 3.0)) * 0.5;
330 return plMath::GetCurveValue_Linear(x);
332 return plMath::GetCurveValue_ConstantZero(x);
334 return plMath::GetCurveValue_ConstantOne(x);
336 return plMath::GetCurveValue_EaseInSine(x);
338 return plMath::GetCurveValue_EaseOutSine(x);
340 return plMath::GetCurveValue_EaseInOutSine(x);
342 return plMath::GetCurveValue_EaseInQuad(x);
344 return plMath::GetCurveValue_EaseOutQuad(x);
346 return plMath::GetCurveValue_EaseInOutQuad(x);
348 return plMath::GetCurveValue_EaseInCubic(x);
350 return plMath::GetCurveValue_EaseOutCubic(x);
352 return plMath::GetCurveValue_EaseInOutCubic(x);
354 return plMath::GetCurveValue_EaseInQuartic(x);
356 return plMath::GetCurveValue_EaseOutQuartic(x);
357 case EaseInOutQuartic:
358 return plMath::GetCurveValue_EaseInOutQuartic(x);
360 return plMath::GetCurveValue_EaseInQuintic(x);
362 return plMath::GetCurveValue_EaseOutQuintic(x);
363 case EaseInOutQuintic:
364 return plMath::GetCurveValue_EaseInOutQuintic(x);
366 return plMath::GetCurveValue_EaseInExpo(x);
368 return plMath::GetCurveValue_EaseOutExpo(x);
370 return plMath::GetCurveValue_EaseInOutExpo(x);
372 return plMath::GetCurveValue_EaseInCirc(x);
374 return plMath::GetCurveValue_EaseOutCirc(x);
376 return plMath::GetCurveValue_EaseInOutCirc(x);
378 return plMath::GetCurveValue_EaseInBack(x);
380 return plMath::GetCurveValue_EaseOutBack(x);
382 return plMath::GetCurveValue_EaseInOutBack(x);
384 return plMath::GetCurveValue_EaseInElastic(x);
386 return plMath::GetCurveValue_EaseOutElastic(x);
388 return plMath::GetCurveValue_EaseInOutElastic(x);
390 return plMath::GetCurveValue_EaseInBounce(x);
392 return plMath::GetCurveValue_EaseOutBounce(x);
393 case EaseInOutBounce:
394 return plMath::GetCurveValue_EaseInOutBounce(x);
396 return plMath::GetCurveValue_Conical(x);
397 case FadeInHoldFadeOut:
398 return plMath::GetCurveValue_FadeInHoldFadeOut(x);
400 return plMath::GetCurveValue_FadeInFadeOut(x);
402 return plMath::GetCurveValue_Bell(x);
404 PL_DEFAULT_CASE_NOT_IMPLEMENTED;
413 double value =
GetValue(function, x);
415 return bInverse ? (1.0 - value) : value;
This namespace provides common math-functionality as functions.
Definition Constants.h:6
constexpr TYPE Pi()
Returns the natural constant Pi.
PL_ALWAYS_INLINE double Sqrt(double f)
Returns the square root of f.
Definition MathDouble_inl.h:99
static double GetValue(Enum function, double x)
Helper function that returns the function value at the given x coordinate.
Definition CurveFunctions_inl.h:325
Enum
Definition CurveFunctions.h:19
@ EaseInOutBack
Values exceed the 0-1 range briefly.
Definition CurveFunctions.h:55
@ EaseInElastic
Values exceed the 0-1 range briefly.
Definition CurveFunctions.h:57
@ EaseOutBack
Values exceed the 0-1 range briefly.
Definition CurveFunctions.h:54
@ EaseOutElastic
Values exceed the 0-1 range briefly.
Definition CurveFunctions.h:58
@ EaseInOutElastic
Values exceed the 0-1 range briefly.
Definition CurveFunctions.h:59
@ EaseInBack
Values exceed the 0-1 range briefly.
Definition CurveFunctions.h:53