修改游戏底层矩阵相关
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2016-2018 Kiwano - Nomango
|
||||
// Copyright (c) 2016-2018 Ember - Nomango
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2016-2018 Kiwano - Nomango
|
||||
// Copyright (c) 2016-2018 Ember - Nomango
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -249,7 +249,7 @@ inline bool operator<(const RefBasePtr<_Ty, _RefPolicy> &lhs, const RefBasePtr<_
|
||||
}
|
||||
|
||||
// template class cannot specialize std::swap,
|
||||
// so implement a swap function in kiwano namespace
|
||||
// so implement a swap function in ember namespace
|
||||
template <class _Ty, class _RefPolicy>
|
||||
inline void swap(RefBasePtr<_Ty, _RefPolicy> &lhs, RefBasePtr<_Ty, _RefPolicy> &rhs) noexcept
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2016-2018 Kiwano - Nomango
|
||||
// Copyright (c) 2016-2018 Ember - Nomango
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
#include "TransformT.h"
|
||||
|
||||
TransformT::TransformT()
|
||||
: rotation(0.f), position(), scale(1.f, 1.f)
|
||||
{
|
||||
}
|
||||
|
||||
bool TransformT::IsFast() const
|
||||
{
|
||||
return scale.x == 1.f && scale.y == 1.f && rotation == 0.f;
|
||||
}
|
||||
|
||||
bool TransformT::operator==(const TransformT &rhs) const
|
||||
{
|
||||
return position == rhs.position && rotation == rhs.rotation && scale == rhs.scale;
|
||||
}
|
||||
|
||||
// -------------------------- 加法运算符实现 --------------------------
|
||||
TransformT TransformT::operator+(const TransformT &rhs) const
|
||||
{
|
||||
TransformT result;
|
||||
result.rotation = this->rotation + rhs.rotation;
|
||||
result.position = this->position + rhs.position;
|
||||
result.scale = this->scale + rhs.scale;
|
||||
return result;
|
||||
}
|
||||
|
||||
TransformT TransformT::operator-(const TransformT &rhs) const
|
||||
{
|
||||
TransformT result;
|
||||
result.rotation = this->rotation - rhs.rotation;
|
||||
result.position = this->position - rhs.position;
|
||||
result.scale = this->scale - rhs.scale;
|
||||
return result;
|
||||
}
|
||||
|
||||
// -------------------------- 复合赋值运算符实现 --------------------------
|
||||
TransformT &TransformT::operator+=(const TransformT &rhs)
|
||||
{
|
||||
this->rotation += rhs.rotation;
|
||||
this->position += rhs.position;
|
||||
this->scale += rhs.scale;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TransformT &TransformT::operator-=(const TransformT &rhs)
|
||||
{
|
||||
this->rotation -= rhs.rotation;
|
||||
this->position -= rhs.position;
|
||||
this->scale -= rhs.scale;
|
||||
return *this;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
#include "Tool/Common.h"
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 二维放射变换
|
||||
*/
|
||||
class TransformT
|
||||
{
|
||||
public:
|
||||
float rotation; ///< 旋转
|
||||
VecFPos position; ///< 坐标
|
||||
VecFPos scale; ///< 缩放
|
||||
|
||||
public:
|
||||
TransformT();
|
||||
|
||||
bool IsFast() const;
|
||||
|
||||
bool operator==(const TransformT &rhs) const;
|
||||
|
||||
TransformT operator+(const TransformT &rhs) const;
|
||||
TransformT operator-(const TransformT &rhs) const;
|
||||
TransformT &operator+=(const TransformT &rhs);
|
||||
TransformT &operator-=(const TransformT &rhs);
|
||||
};
|
||||
Reference in New Issue
Block a user