From 4d45bfc242691e28702a80198b2db7a5f8201435 Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Sat, 6 Sep 2025 09:36:19 +0800 Subject: [PATCH] [Feat] (MG_Util/Math): Enhance vector types. --- MobileGL/MG_Util/Math/VectorTypes.h | 53 ++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/MobileGL/MG_Util/Math/VectorTypes.h b/MobileGL/MG_Util/Math/VectorTypes.h index 9ba894d8..5b2fd4fb 100644 --- a/MobileGL/MG_Util/Math/VectorTypes.h +++ b/MobileGL/MG_Util/Math/VectorTypes.h @@ -89,6 +89,11 @@ namespace MobileGL { const T& x() const { return (*this)[0]; } const T& y() const { return (*this)[1]; } + T& r() { return (*this)[0]; } + T& g() { return (*this)[1]; } + const T& r() const { return (*this)[0]; } + const T& g() const { return (*this)[1]; } + T Cross(const Vec2& rhs) const { return x() * rhs.y() - y() * rhs.x(); } Vec2 Rotated(T angle) const { @@ -113,10 +118,21 @@ namespace MobileGL { const T& y() const { return (*this)[1]; } const T& z() const { return (*this)[2]; } + T& r() { return (*this)[0]; } + T& g() { return (*this)[1]; } + T& b() { return (*this)[2]; } + const T& r() const { return (*this)[0]; } + const T& g() const { return (*this)[1]; } + const T& b() const { return (*this)[2]; } + Vec2 xy() const { return {x(), y()}; } Vec2 xz() const { return {x(), z()}; } Vec2 yz() const { return {y(), z()}; } + Vec2 rg() const { return {x(), y()}; } + Vec2 rb() const { return {x(), z()}; } + Vec2 gb() const { return {y(), z()}; } + Vec3 Cross(const Vec3& rhs) const { return {y() * rhs.z() - z() * rhs.y(), z() * rhs.x() - x() * rhs.z(), x() * rhs.y() - y() * rhs.x()}; } @@ -134,12 +150,44 @@ namespace MobileGL { T& y() { return (*this)[1]; } T& z() { return (*this)[2]; } T& w() { return (*this)[3]; } + + Vec2 xy() const { return {x(), y()}; } + Vec2 xz() const { return {x(), z()}; } + Vec2 xw() const { return {x(), w()}; } + Vec2 yz() const { return {y(), z()}; } + Vec2 yw() const { return {y(), w()}; } + Vec2 zw() const { return {z(), w()}; } + Vec3 xyz() const { return {x(), y(), z()}; } + Vec3 xyw() const { return {x(), y(), w()}; } + Vec3 xzw() const { return {x(), z(), w()}; } + Vec3 yzw() const { return {y(), z(), w()}; } + + T& r() { return (*this)[0]; } + T& g() { return (*this)[1]; } + T& b() { return (*this)[2]; } + T& a() { return (*this)[3]; } + + Vec2 rg() const { return {x(), y()}; } + Vec2 rb() const { return {x(), z()}; } + Vec2 ra() const { return {x(), w()}; } + Vec2 gb() const { return {y(), z()}; } + Vec2 ga() const { return {y(), w()}; } + Vec2 ba() const { return {z(), w()}; } + Vec3 rgb() const { return {x(), y(), z()}; } + Vec3 rga() const { return {x(), y(), w()}; } + Vec3 rba() const { return {x(), z(), w()}; } + Vec3 gba() const { return {y(), z(), w()}; } + const T& x() const { return (*this)[0]; } const T& y() const { return (*this)[1]; } const T& z() const { return (*this)[2]; } const T& w() const { return (*this)[3]; } - Vec3 xyz() const { return {x(), y(), z()}; } + const T& r() const { return (*this)[0]; } + const T& g() const { return (*this)[1]; } + const T& b() const { return (*this)[2]; } + const T& a() const { return (*this)[3]; } + Vec3 Homogenized() const { return (w() != 0) ? xyz() / w() : xyz(); } }; @@ -152,6 +200,9 @@ namespace MobileGL { using FloatVec2 = Vec2; using FloatVec3 = Vec3; using FloatVec4 = Vec4; + using BoolVec2 = Vec2; + using BoolVec3 = Vec3; + using BoolVec4 = Vec4; using Size2D = IntVec2; using Size3D = IntVec3;