线性插值算法

从A变到B

void lerp(float A,float B)
{
    float length=B-A;

    float value; //变化的结果值
    //t=change-A/length; //t的取值0-1,change【A-B】
    for(int change=A,change<B;++change)
    {
     t=change-A/length; //t的取值0-1,change【A-B】
     value=A+t*(B-A);
    }
//    float value=A+t*(B-A);
}

void lerp(float A, float B)
{
    float length = B - A;

    float value; //变化的结果值
    //t=change-A/length; //t的取值0-1,change【A-B】
    for (float change = A; change <=B;++change)
    {

        float   t = (change - A) / length; //t的取值0-1,change【A-B】
        if (t>0.9)
        {
            t = 1;
        }
        value = A + t * length;

        std::cout << value << std::endl;
    }

}


static int64_t  getNowInMilliSec()
{
    return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
}

//获取当前时间 (毫秒)
static int64_t  system_clock_now()
{
    return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}

void lerp_time(float A, float B,float len)
{

    //获取当前时间戳
    int64_t now = getNowInMilliSec();
    int64_t end = now + len;

    float length = B - A;

    for (int64_t change = now; change <=end; change+=20)
    {
        float   t = (change - now) / len;   //百分比
        float  value = A + t * length;
        std::cout << value << std::endl;
        std::chrono::milliseconds et(20);
        std::this_thread::sleep_for(et);  
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值