feat: improve action animations

This commit is contained in:
2026-02-05 20:23:37 +08:00
parent 9e2d885949
commit e66e997a16
5 changed files with 105 additions and 18 deletions

View File

@@ -1,7 +1,10 @@
#pragma once
#include <utility>
#include "Config.h"
#include <cmath>
static inline float easeInOutSine(float t) {
return -(cos(M_PI * t) - 1) / 2.0f;
}
namespace Tools {
inline std::pair<int, int> physicalToLogical(float physicalX, float physicalY, const Viewport& viewport) {
std::pair<int, int> logicalPoint = {0 , 0};
@@ -16,4 +19,34 @@ namespace Tools {
return logicalPoint;
}
// t ∈ [0, 1]0=开始0.5=最远点1=回到原点(带震荡)
// b = 起始值(原位置)
// c = 偏移量(最大偏移距离)
inline float pingPongSpring(float t, float b, float c) {
if (t <= 0.0f) return b;
if (t >= 1.0f) return b; // 最终回到原点!
float overshoot = 1.70158f;
if (t < 0.5f) {
// 前半段:从 0 → 1冲到最远点
t *= 2.0f; // 映射到 [0,1]
float val = t * t * ((overshoot + 1) * t - overshoot);
return b + c * val;
} else {
// 后半段:从 1 → 0从最远点弹回原点带过冲
t = (t - 0.5f) * 2.0f; // 映射到 [0,1]
t -= 1;
float val = t * t * ((overshoot + 1) * t + overshoot) + 1;
return b + c * (1.0f - val); // 从 c 往回减到 0
}
}
// 通用插值函数
inline float smoothMove(float t, float start, float end) {
float progress = easeInOutSine(t); // t ∈ [0,1]
return start + (end - start) * progress;
}
}