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