| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using System;
- namespace Urho
- {
- internal static class EaseMath
- {
- internal static float BackIn(float time)
- {
- const float overshoot = 1.70158f;
-
- return time * time * ((overshoot + 1) * time - overshoot);
- }
- internal static float BackOut(float time)
- {
- const float overshoot = 1.70158f;
- time = time - 1;
- return time * time * ((overshoot + 1) * time + overshoot) + 1;
- }
- internal static float BackInOut(float time)
- {
- const float overshoot = 1.70158f * 1.525f;
- time = time * 2;
- if (time < 1)
- {
- return (time * time * ((overshoot + 1) * time - overshoot)) / 2;
- }
- else
- {
- time = time - 2;
- return (time * time * ((overshoot + 1) * time + overshoot)) / 2 + 1;
- }
- }
- internal static float BounceOut(float time)
- {
- if (time < 1 / 2.75)
- {
- return 7.5625f * time * time;
- }
- else if (time < 2 / 2.75)
- {
- time -= 1.5f / 2.75f;
- return 7.5625f * time * time + 0.75f;
- }
- else if (time < 2.5 / 2.75)
- {
- time -= 2.25f / 2.75f;
- return 7.5625f * time * time + 0.9375f;
- }
- time -= 2.625f / 2.75f;
- return 7.5625f * time * time + 0.984375f;
- }
- internal static float BounceIn(float time)
- {
- return 1f - BounceOut(1f - time);
- }
- internal static float BounceInOut(float time)
- {
- if (time < 0.5f)
- {
- time = time * 2;
- return (1 - BounceOut(1 - time)) * 0.5f;
- }
- return BounceOut(time * 2 - 1) * 0.5f + 0.5f;
- }
- internal static float SineOut(float time)
- {
- return (float) Math.Sin(time * MathHelper.PiOver2);
- }
- internal static float SineIn(float time)
- {
- return -1f * (float)Math.Cos(time * MathHelper.PiOver2) + 1f;
- }
- internal static float SineInOut(float time)
- {
- return -0.5f * ((float)Math.Cos((float)Math.PI * time) - 1f);
- }
- internal static float ExponentialOut(float time)
- {
- return time == 1f ? 1f : (-(float)Math.Pow(2f, -10f * time / 1f) + 1f);
- }
- internal static float ExponentialIn(float time)
- {
- return time == 0f ? 0f : (float)Math.Pow(2f, 10f * (time / 1f - 1f)) - 1f * 0.001f;
- }
- internal static float ExponentialInOut(float time)
- {
- time /= 0.5f;
- if (time < 1)
- {
- return 0.5f * (float)Math.Pow(2f, 10f * (time - 1f));
- }
- else
- {
- return 0.5f * (-(float)Math.Pow(2f, -10f * (time - 1f)) + 2f);
- }
- }
- internal static float ElasticIn(float time, float period)
- {
- if (time == 0 || time == 1)
- {
- return time;
- }
- else
- {
- float s = period / 4;
- time = time - 1;
- return -(float)(Math.Pow(2, 10 * time) * Math.Sin((time - s) * MathHelper.Pi * 2.0f / period));
- }
- }
- internal static float ElasticOut(float time, float period)
- {
- if (time == 0 || time == 1)
- {
- return time;
- }
- else
- {
- float s = period / 4;
- return (float)(Math.Pow(2, -10 * time) * Math.Sin((time - s) * MathHelper.Pi * 2f / period) + 1);
- }
- }
- internal static float ElasticInOut(float time, float period)
- {
- if (time == 0 || time == 1)
- {
- return time;
- }
- else
- {
- time = time * 2;
- if (period == 0)
- {
- period = 0.3f * 1.5f;
- }
- float s = period / 4;
- time = time - 1;
- if (time < 0)
- {
- return (float)(-0.5f * Math.Pow(2, 10 * time) * Math.Sin((time - s) * MathHelper.TwoPi / period));
- }
- else
- {
- return (float)(Math.Pow(2, -10 * time) * Math.Sin((time - s) * MathHelper.TwoPi / period) * 0.5f + 1);
- }
- }
- }
- }
- }
|