soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SInterpolatorImpl.cpp
1#include "souistd.h"
2#include "animation/SInterpolatorImpl.h"
3#include "layout/SLayoutSize.h" //for SLayoutSize::fequal
4#pragma warning(push)
5#pragma warning(disable : 4985) // disable the warning message during the include
6#include <math.h> // this is where I would normally get the warning message
7#pragma warning(pop)
8
9SNSBEGIN
10
11static const float PI = 3.1415926f;
12
13//////////////////////////////////////////////////////////////////////////
15{
16 return input;
17}
18
19//////////////////////////////////////////////////////////////////////////
21{
22 if (SLayoutSize::fequal(mFactor, 1.0f))
23 {
24 return input * input;
25 }
26 else
27 {
28 return (float)pow((double)input, mDoubleFactor);
29 }
30}
31
33 : mFactor(factor)
34 , mDoubleFactor(2 * factor)
35{
36}
37
38//////////////////////////////////////////////////////////////////////////
39
41{
42 float result;
43 if (SLayoutSize::fequal(mFactor, 1.0f))
44 {
45 result = (float)(1.0f - (1.0f - input) * (1.0f - input));
46 }
47 else
48 {
49 result = (float)(1.0f - pow((1.0f - input), 2 * mFactor));
50 }
51 return result;
52}
53
55 : mFactor(factor)
56{
57}
58
59//////////////////////////////////////////////////////////////////////////
61{
62 return (float)(cos((input + 1) * PI) / 2.0f) + 0.5f;
63}
64
65//////////////////////////////////////////////////////////////////////////
67{
68 // a(t) = t * t * ((tension + 1) * t - tension)
69 return t * t * ((mTension + 1) * t - mTension);
70}
71
73 : mTension(tension)
74{
75}
76
81
82//////////////////////////////////////////////////////////////////////////
84{
85 // a(t, s) = t * t * ((s + 1) * t - s)
86 // o(t, s) = t * t * ((s + 1) * t + s)
87 // f(t) = 0.5 * a(t * 2, tension * extraTension), when t < 0.5
88 // f(t) = 0.5 * (o(t * 2 - 2, tension * extraTension) + 2), when t <= 1.0
89 if (t < 0.5f)
90 return 0.5f * a(t * 2.0f, getTensionMulti());
91 else
92 return 0.5f * (o(t * 2.0f - 2.0f, getTensionMulti()) + 2.0f);
93}
94
95float SAnticipateOvershootInterpolator::o(float t, float s)
96{
97 return t * t * ((s + 1) * t + s);
98}
99
100float SAnticipateOvershootInterpolator::a(float t, float s)
101{
102 return t * t * ((s + 1) * t - s);
103}
104
106 : mTension(tension)
107 , mExtraTension(extraTension)
108{
109}
110
111//////////////////////////////////////////////////////////////////////////
113{
114 // _b(t) = t * t * 8
115 // bs(t) = _b(t) for t < 0.3535
116 // bs(t) = _b(t - 0.54719) + 0.7 for t < 0.7408
117 // bs(t) = _b(t - 0.8526) + 0.9 for t < 0.9644
118 // bs(t) = _b(t - 1.0435) + 0.95 for t <= 1.0
119 // b(t) = bs(t * 1.1226)
120 t *= 1.1226f;
121 if (t < 0.3535f)
122 return bounce(t);
123 else if (t < 0.7408f)
124 return bounce(t - 0.54719f) + 0.7f;
125 else if (t < 0.9644f)
126 return bounce(t - 0.8526f) + 0.9f;
127 else
128 return bounce(t - 1.0435f) + 0.95f;
129}
130
131float SBounceInterpolator::bounce(float t)
132{
133 return t * t * 8.0f;
134}
135
136//////////////////////////////////////////////////////////////////////////
138{
139 return (float)(sin(2 * mCycles * PI * input));
140}
141
143 : mCycles(cycles)
144{
145}
146
147//////////////////////////////////////////////////////////////////////////
148
150{
151 // _o(t) = t * t * ((tension + 1) * t + tension)
152 // o(t) = _o(t - 1) + 1
153 t -= 1.0f;
154 return t * t * ((mTension + 1) * t + mTension) + 1.0f;
155}
156
158 : mTension(tension)
159{
160}
161
162SNSEND
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
SAccelerateInterpolator(float factor=1.0f)
Constructor for SAccelerateInterpolator.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
SAnticipateInterpolator()
Default constructor for SAnticipateInterpolator.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
SAnticipateOvershootInterpolator(float tension=2.0f, float extraTension=1.5f)
Constructor for SAnticipateOvershootInterpolator.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
SCycleInterpolator(float cycles=1.0f)
Constructor for SCycleInterpolator.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
SDecelerateInterpolator(float factor=1.0f)
Constructor for SDecelerateInterpolator.
static bool fequal(float a, float b)
比较两个浮点数是否相等
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
SOvershootInterpolator(float tension=2.0f)
Constructor for SOvershootInterpolator.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.