-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBaseBounceAnimationT.cs
45 lines (40 loc) · 1.41 KB
/
BaseBounceAnimationT.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
namespace BrainbeanApps.ValueAnimation
{
public abstract class BaseBounceAnimation<T> : BaseAnimation<T>
where T : struct, IComparable
{
public BaseBounceAnimation(IValueOperations<T> valueOperations)
: base(valueOperations)
{
}
public T GetValue(float currentTime, float duration, T initialValue, T deltaValue, bool isAttenuation)
{
if (!isAttenuation)
currentTime = duration - currentTime;
var progress = currentTime / duration;
float factor;
if (progress < (1.0f / 2.75f))
factor = 7.5625f * progress * progress;
else if (progress < (2.0f / 2.75f))
{
var t = progress - 1.5f / 2.75f;
factor = 7.5625f * t * t + 0.75f;
}
else if (progress < (2.5f / 2.75f))
{
var t = progress - 2.25f / 2.75f;
factor = 7.5625f * t * t + 0.9375f;
}
else
{
var t = progress - 2.625f / 2.75f;
factor = 7.5625f * t * t + 0.984375f;
}
var value = ValueOperations.ScaleByFactor(deltaValue, factor);
if (!isAttenuation)
value = ValueOperations.Subtract(deltaValue, value);
return ValueOperations.Add(initialValue, value);
}
}
}