加入 Node节点类 还未测试新框架

This commit is contained in:
2025-10-27 23:12:56 +08:00
parent 80d088316b
commit 0ae47e5d6a
52 changed files with 1642 additions and 458 deletions

View File

@@ -0,0 +1,26 @@
#pragma once
#include <type_traits>
namespace bits
{
template <typename _Ty>
inline void Set(_Ty &old, _Ty flag)
{
static_assert(std::is_arithmetic<_Ty>::value, "_Ty must be an arithmetic type");
old |= flag;
}
template <typename _Ty>
inline void Unset(_Ty &old, _Ty flag)
{
static_assert(std::is_arithmetic<_Ty>::value, "_Ty must be an arithmetic type");
old &= ~flag;
}
template <typename _Ty>
inline bool Has(_Ty old, _Ty flag)
{
static_assert(std::is_arithmetic<_Ty>::value, "_Ty must be an arithmetic type");
return !!(old & flag);
}
}

View File

@@ -0,0 +1,57 @@
#pragma once
#include <cstdint> // uint8_t
#include "Bits.h"
template <typename _Ty>
class Flag
{
public:
static_assert(std::is_arithmetic<_Ty>::value, "_Ty must be an arithmetic type");
typedef _Ty value_type;
_Ty value;
inline Flag()
: value()
{
}
inline Flag(_Ty value)
: value(value)
{
}
inline void Set(_Ty value)
{
bits::Set(this->value, value);
}
inline void Unset(_Ty value)
{
bits::Unset(this->value, value);
}
inline bool Has(_Ty value) const
{
return bits::Has(this->value, value);
}
};
template <typename _Ty>
struct IsFlag : public std::false_type
{
};
template <typename _Ty>
struct IsFlag<Flag<_Ty>> : public std::true_type
{
};
typedef Flag<uint8_t> FlagUint8;
typedef Flag<uint16_t> FlagUint16;
typedef Flag<uint32_t> FlagUint32;
typedef Flag<uint64_t> FlagUint64;
typedef Flag<int8_t> FlagInt8;
typedef Flag<int16_t> FlagInt16;
typedef Flag<int32_t> FlagInt32;
typedef Flag<int64_t> FlagInt64;

View File

@@ -0,0 +1,61 @@
#include "Y_Transform.h"
#include <cmath>
Y_Transform::Y_Transform() : position(0.f, 0.f), scale(1.0f, 1.0f), skew(0.f, 0.f), rotation(0.f)
{
}
Matrix3x2 Y_Transform::ToMatrix() const
{
// 将角度转换为弧度
float rotRad = glm::radians(rotation);
float skewXRad = glm::radians(skew.x);
float skewYRad = glm::radians(skew.y);
// 计算旋转的正弦和余弦
float cosRot = std::cos(rotRad);
float sinRot = std::sin(rotRad);
// 计算错切的正切值
float tanSkewX = std::tan(skewXRad);
float tanSkewY = std::tan(skewYRad);
// 构造基础变换矩阵(缩放 × 错切 × 旋转的组合)
// 注意:矩阵乘法顺序为 旋转 × 错切 × 缩放(从右向左应用)
float m00 = scale.x * (cosRot - sinRot * tanSkewY);
float m01 = scale.y * (-sinRot + cosRot * tanSkewX);
float m10 = scale.x * (sinRot + cosRot * tanSkewY);
float m11 = scale.y * (cosRot + sinRot * tanSkewX);
// 平移分量
float tx = position.x;
float ty = position.y;
// 构造并返回 3x2 矩阵(假设 Matrix3x2 可通过此方式初始化)
return Matrix3x2(m00, m01, m10, m11, tx, ty);
}
glm::mat4 Y_Transform::GetTransformMatrix() const
{
// 缩放矩阵Scale
glm::mat4 scaleMat = glm::mat4(1.0f); // 单位矩阵
scaleMat[0][0] = scale.x; // x轴缩放
scaleMat[1][1] = scale.y; // y轴缩放
// 错切矩阵Skew先将角度转为弧度
float skewX = glm::radians(skew.x); // 沿y轴错切角度x方向倾斜
float skewY = glm::radians(skew.y); // 沿x轴错切角度y方向倾斜
glm::mat4 skewMat = glm::mat4(1.0f);
skewMat[0][1] = tan(skewX); // x方向错切因子影响y轴
skewMat[1][0] = tan(skewY); // y方向错切因子影响x轴
// 旋转矩阵Rotation绕z轴旋转角度转弧度
float rotRad = glm::radians(rotation);
glm::mat4 rotMat = glm::rotate(glm::mat4(1.0f), rotRad, glm::vec3(0, 0, 1));
// 平移矩阵Translation
glm::mat4 transMat = glm::translate(glm::mat4(1.0f), glm::vec3(position, 0.0f));
// 组合变换矩阵:平移 × 旋转 × 错切 × 缩放(注意乘法顺序,从右向左应用)
return transMat * rotMat * skewMat * scaleMat;
}

View File

@@ -0,0 +1,26 @@
#pragma once
#include "math/Math.h"
#include <glm/glm.hpp>
#include <glm/ext/matrix_clip_space.hpp>
#include <glm/gtc/type_ptr.hpp>
class Y_Transform
{
public:
float rotation; ///< 旋转
glm::vec2 position; ///< 坐标
glm::vec2 scale; ///< 缩放
glm::vec2 skew; ///< 错切角度
public:
Y_Transform(/* args */);
bool IsFast() const
{
return skew.x == 0.f && skew.y == 0.f &&
scale.x == 1.f && scale.y == 1.f &&
rotation == 0.f;
}
Matrix3x2 ToMatrix() const;
glm::mat4 GetTransformMatrix() const;
};