【发布时间】:2021-01-20 18:32:05
【问题描述】:
我正在渲染正在处理的卡片。玩家卡位于屏幕底部,经销商卡位于顶部。卡片从顶部的“屏幕外”发牌。因此牌的起始位置和玩家手之间的距离大于起始位置和庄家手之间的距离。
我正在使用介于0.0 和1.0 之间的interpolated_position 值计算卡片当前位置。由于距离不同,动画的动画速度也不同。
/// Updates the first animation in the queue then deletes it
void Update(float delta_time)
{
if (pause == false && !animation_confs.empty())
{
interpolated_position += delta_time * (animation_confs[0].speed); // animation speed is 1.3 here
if (interpolated_position >= 1.0f) // Finished animation reset values
{
interpolated_position = 0.0f;
if (!animation_confs.empty())
{
animation_confs.erase(animation_confs.begin());
return;
}
}
InterpolateFrame();
}
}
// Interpolates card position between two points based on interpolation factor
void InterpolateFrame()
{
if (!animation_confs.empty())
{
float t = interpolated_position;
float x1 = animation_confs[0].start.x;
float x2 = animation_confs[0].goal.x;
position.x = x1 + t * (x2 - x1);
float y1 = animation_confs[0].start.y;
float y2 = animation_confs[0].goal.y;
position.y = y1 + t * (y2 - y1);
}
}
这种行为的原因可能是什么?我认为将delta_time 应用于插值会保持速度恒定。
【问题讨论】:
标签: c++ animation interpolation