问题
I am trying to understand this easing formula:
float easeInOutSine(float t, float b, float c, float d)
{
return -c/2 * (cos(M_PI*t/d) - 1) + b;
};
Here are what the variables equal:
t: current time b: start value c: change in value d: duration
I am trying to apply this to a sprite transformation and am confused about what exactly needs to be passed in.
If I wanted for instance to move a ball from y = 0 towards y = 10 at 0.25 units per second, which values are which? What I am really looking for is another explanation of what these variables mean in relation to what I am after.
回答1:
t
must be the time of your system/simulation. This will change everytime you call it.
b
should be 0
, the starting value.
c
should be 10
, the final value,
d
should be 40000
(assuming your time is in milliseconds). This is essentially the duration. Each four second you want to advance by one unit which will take a total of 40 seconds.
You can test/play with it with a sample program:
float easeInOutSine(float t, float b, float c, float d)
{
return -c/2 * (cos(M_PI*t/d) - 1) + b;
}
int main() {
for (unsigned t = 0; t <= 40*1000; t += 1000) {
cout << "t= " << t << " y=" << easeInOutSine(t, 0, 10, 40000) << std::endl;
}
}
Output:
t= 0 y=0
t= 1000 y=0.0154133
t= 2000 y=0.0615583
t= 3000 y=0.13815
t= 4000 y=0.244717
t= 5000 y=0.380602
t= 6000 y=0.544967
t= 7000 y=0.736799
t= 8000 y=0.954915
t= 9000 y=1.19797
t= 10000 y=1.46447
t= 11000 y=1.75276
t= 12000 y=2.06107
t= 13000 y=2.38751
t= 14000 y=2.73005
t= 15000 y=3.08658
t= 16000 y=3.45492
t= 17000 y=3.83277
t= 18000 y=4.21783
t= 19000 y=4.6077
t= 20000 y=5
t= 21000 y=5.3923
t= 22000 y=5.78217
t= 23000 y=6.16723
t= 24000 y=6.54508
t= 25000 y=6.91342
t= 26000 y=7.26995
t= 27000 y=7.61249
t= 28000 y=7.93893
t= 29000 y=8.24724
t= 30000 y=8.53553
t= 31000 y=8.80203
t= 32000 y=9.04508
t= 33000 y=9.2632
t= 34000 y=9.45503
t= 35000 y=9.6194
t= 36000 y=9.75528
t= 37000 y=9.86185
t= 38000 y=9.93844
t= 39000 y=9.98459
t= 40000 y=10
来源:https://stackoverflow.com/questions/23038569/c-trouble-understanding-easeinoutsine