C ++-无法理解easyInOutSine [英] C++ - Trouble understanding easeInOutSine

查看:256
本文介绍了C ++-无法理解easyInOutSine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解这个宽松的公式:

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;
};

以下是变量等于的值:

t:当前时间
b:起始值
c:值变化
d:持续时间

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.

如果我想例如以每秒0.25个单位的速度从y = 0向y = 10移动一个球,则感到困惑。 ,哪个值是?我真正要寻找的是这些变量相对于我所追求的含义的另一种解释。

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.

推荐答案

t 必须是系统/模拟的时间。

t must be the time of your system/simulation. This will change everytime you call it.

b 应该为 0 ,即起始值。

c 应该为 10 ,最终值

d 应该为 40000 (假设您的时间以毫秒为单位)。这实际上是持续时间。您想每前进四秒,就需要一个单元,总共需要40秒。

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;
    }
}

输出:

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

这篇关于C ++-无法理解easyInOutSine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆