修改游戏底层矩阵相关
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
#include <cmath>
|
||||
#endif
|
||||
|
||||
#include "math/Math.h"
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 不可拷贝对象
|
||||
class Noncopyable
|
||||
@@ -30,134 +32,6 @@ private:
|
||||
Noncopyable &operator=(const Noncopyable &) = delete;
|
||||
};
|
||||
|
||||
// 整数坐标向量
|
||||
typedef struct VecPos
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
// 构造函数,方便初始化
|
||||
VecPos(int x_ = 0, int y_ = 0) : x(x_), y(y_) {}
|
||||
|
||||
// 定义到 SDL_Point 的转换运算符
|
||||
operator SDL_Point() const
|
||||
{
|
||||
return {x, y}; // 直接返回包含 x、y 的 SDL_Point
|
||||
}
|
||||
// 转换为SDL_Point指针的运算符(用于指针场景)
|
||||
operator const SDL_Point *() const
|
||||
{
|
||||
// 注意:这里返回的是指向当前对象的指针,需确保对象生命周期有效
|
||||
return reinterpret_cast<const SDL_Point *>(this);
|
||||
}
|
||||
|
||||
// 加法运算符重载:两个 VecPos 相加
|
||||
VecPos operator+(const VecPos &other) const
|
||||
{
|
||||
return VecPos(x + other.x, y + other.y);
|
||||
}
|
||||
|
||||
// 减法运算符重载:两个 VecPos 相减
|
||||
VecPos operator-(const VecPos &other) const
|
||||
{
|
||||
return VecPos(x - other.x, y - other.y);
|
||||
}
|
||||
|
||||
// 等于运算符重载:判断两个 VecPos 是否相等
|
||||
bool operator==(const VecPos &other) const
|
||||
{
|
||||
return x == other.x && y == other.y;
|
||||
}
|
||||
|
||||
// 复合赋值加法:当前对象加上另一个 VecPos
|
||||
VecPos &operator+=(const VecPos &other)
|
||||
{
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// 复合赋值减法:当前对象减去另一个 VecPos
|
||||
VecPos &operator-=(const VecPos &other)
|
||||
{
|
||||
x -= other.x;
|
||||
y -= other.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// 乘法
|
||||
VecPos operator*(float value) const
|
||||
{
|
||||
return VecPos(x * value, y * value);
|
||||
}
|
||||
} VecPos;
|
||||
|
||||
// 浮点数坐标向量
|
||||
typedef struct VecFPos
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
|
||||
// 构造函数,方便初始化
|
||||
VecFPos(float x_ = 0.0f, float y_ = 0.0f) : x(x_), y(y_) {}
|
||||
VecFPos(int x_, int y_ = 0) : x(static_cast<float>(x_)), y(static_cast<float>(y_)) {}
|
||||
|
||||
// 定义到 SDL_FPoint 的转换运算符
|
||||
operator SDL_FPoint() const
|
||||
{
|
||||
return {x, y}; // 直接返回包含 x、y 的 SDL_Point
|
||||
}
|
||||
|
||||
// 加法运算符重载:两个 VecFPos 相加
|
||||
VecFPos operator+(const VecFPos &other) const
|
||||
{
|
||||
return VecFPos(x + other.x, y + other.y);
|
||||
}
|
||||
|
||||
// 减法运算符重载:两个 VecFPos 相减
|
||||
VecFPos operator-(const VecFPos &other) const
|
||||
{
|
||||
return VecFPos(x - other.x, y - other.y);
|
||||
}
|
||||
|
||||
// 乘法运算符重载:两个 VecFPos 相乘
|
||||
VecFPos operator*(const VecFPos &other) const
|
||||
{
|
||||
return VecFPos(x * other.x, y * other.y);
|
||||
}
|
||||
|
||||
// 除法运算符重载:除以一个 float 值
|
||||
VecFPos operator/(float value) const
|
||||
{
|
||||
return VecFPos(x / value, y / value);
|
||||
}
|
||||
|
||||
// 等于运算符重载:判断两个 VecFPos 是否相等
|
||||
// 注意:浮点数比较需要考虑精度问题
|
||||
bool operator==(const VecFPos &other) const
|
||||
{
|
||||
// 使用一个小的epsilon值来比较浮点数
|
||||
const float epsilon = 0.0001f;
|
||||
return (fabs(x - other.x) < epsilon) && (fabs(y - other.y) < epsilon);
|
||||
}
|
||||
|
||||
// 复合赋值加法:当前对象加上另一个 VecFPos
|
||||
VecFPos &operator+=(const VecFPos &other)
|
||||
{
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// 复合赋值减法:当前对象减去另一个 VecFPos
|
||||
VecFPos &operator-=(const VecFPos &other)
|
||||
{
|
||||
x -= other.x;
|
||||
y -= other.y;
|
||||
return *this;
|
||||
}
|
||||
} VecFPos;
|
||||
|
||||
// 尺寸向量
|
||||
typedef struct VecSize
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user