mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
refactor: replace pair with vec2
This commit is contained in:
@@ -2,20 +2,21 @@
|
||||
#include <utility>
|
||||
#include "Config.h"
|
||||
#include <cmath>
|
||||
#include <glm/glm.hpp>
|
||||
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};
|
||||
inline glm::ivec2 physicalToLogical(glm::vec2 physicalPos, const Viewport& viewport) {
|
||||
glm::ivec2 logicalPoint = {0 , 0};
|
||||
|
||||
// 计算相对于目标矩形的坐标
|
||||
float normalizedX = (physicalX - viewport.dst.x) / viewport.dst.w;
|
||||
float normalizedY = (physicalY - viewport.dst.y) / viewport.dst.h;
|
||||
float normalizedX = (physicalPos.x - viewport.dst.x) / viewport.dst.w;
|
||||
float normalizedY = (physicalPos.y - viewport.dst.y) / viewport.dst.h;
|
||||
|
||||
// 转换为逻辑坐标
|
||||
logicalPoint.first = static_cast<int>(normalizedX * viewport.logicalWidth);
|
||||
logicalPoint.second = static_cast<int>(normalizedY * viewport.logicalHeight);
|
||||
logicalPoint.x = static_cast<int>(normalizedX * viewport.logicalWidth);
|
||||
logicalPoint.y = static_cast<int>(normalizedY * viewport.logicalHeight);
|
||||
|
||||
return logicalPoint;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user