From 5fe800bae6961ef95542e29d938c1c67b9cc5175 Mon Sep 17 00:00:00 2001 From: lizzie Date: Mon, 31 Aug 2026 19:26:09 +0000 Subject: [PATCH] [common] remove unused vector_math.h fluff Signed-off-by: lizzie --- src/common/CMakeLists.txt | 1 - src/common/quaternion.h | 79 --- src/common/vector_math.h | 645 +++--------------- src/hid_core/frontend/emulated_console.h | 1 - src/hid_core/frontend/motion_input.h | 4 +- .../resources/six_axis/seven_six_axis.h | 2 +- src/input_common/drivers/mouse.cpp | 25 +- .../configure_input_player_widget.cpp | 10 +- 8 files changed, 107 insertions(+), 660 deletions(-) delete mode 100644 src/common/quaternion.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index d90190e6a0..3a6d2acf8a 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -89,7 +89,6 @@ add_library( param_package.h parent_of_member.h point.h - quaternion.h range_map.h range_mutex.h range_sets.h diff --git a/src/common/quaternion.h b/src/common/quaternion.h deleted file mode 100644 index 5bb5f2af08..0000000000 --- a/src/common/quaternion.h +++ /dev/null @@ -1,79 +0,0 @@ -// SPDX-FileCopyrightText: 2016 Citra Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include "common/vector_math.h" - -namespace Common { - -template -class Quaternion { -public: - Vec3 xyz; - T w{}; - - [[nodiscard]] Quaternion Inverse() const { - return {-xyz, w}; - } - - [[nodiscard]] Quaternion operator+(const Quaternion& other) const { - return {xyz + other.xyz, w + other.w}; - } - - [[nodiscard]] Quaternion operator-(const Quaternion& other) const { - return {xyz - other.xyz, w - other.w}; - } - - [[nodiscard]] Quaternion operator*( - const Quaternion& other) const { - return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz), - w * other.w - Dot(xyz, other.xyz)}; - } - - [[nodiscard]] Quaternion Normalized() const { - T length = std::sqrt(xyz.Length2() + w * w); - return {xyz / length, w / length}; - } - - [[nodiscard]] std::array ToMatrix() const { - const T x2 = xyz[0] * xyz[0]; - const T y2 = xyz[1] * xyz[1]; - const T z2 = xyz[2] * xyz[2]; - - const T xy = xyz[0] * xyz[1]; - const T wz = w * xyz[2]; - const T xz = xyz[0] * xyz[2]; - const T wy = w * xyz[1]; - const T yz = xyz[1] * xyz[2]; - const T wx = w * xyz[0]; - - return {1.0f - 2.0f * (y2 + z2), - 2.0f * (xy + wz), - 2.0f * (xz - wy), - 0.0f, - 2.0f * (xy - wz), - 1.0f - 2.0f * (x2 + z2), - 2.0f * (yz + wx), - 0.0f, - 2.0f * (xz + wy), - 2.0f * (yz - wx), - 1.0f - 2.0f * (x2 + y2), - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f}; - } -}; - -template -[[nodiscard]] auto QuaternionRotate(const Quaternion& q, const Vec3& v) { - return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w); -} - -[[nodiscard]] inline Quaternion MakeQuaternion(const Vec3& axis, float angle) { - return {axis * std::sin(angle / 2), std::cos(angle / 2)}; -} - -} // namespace Common diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 829a79ce5a..6624b01e7e 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: 2014 Tony Wasserka @@ -21,7 +21,7 @@ class Vec2; template class Vec3; template -class Vec4; +class Quaternion; template class Vec2 { @@ -30,141 +30,82 @@ public: T y{}; constexpr Vec2() = default; - constexpr Vec2(const T& x_, const T& y_) : x(x_), y(y_) {} + constexpr Vec2(const T& x_, const T& y_) noexcept : x(x_), y(y_) {} - template - [[nodiscard]] constexpr Vec2 Cast() const { - return Vec2(static_cast(x), static_cast(y)); - } - - [[nodiscard]] static constexpr Vec2 AssignToAll(const T& f) { - return Vec2{f, f}; - } - - [[nodiscard]] constexpr Vec2 operator+(const Vec2& other) const { + [[nodiscard]] constexpr Vec2 operator+(const Vec2& other) const noexcept { return {x + other.x, y + other.y}; } - constexpr Vec2& operator+=(const Vec2& other) { + constexpr Vec2& operator+=(const Vec2& other) noexcept { x += other.x; y += other.y; return *this; } - [[nodiscard]] constexpr Vec2 operator-(const Vec2& other) const { + [[nodiscard]] constexpr Vec2 operator-(const Vec2& other) const noexcept { return {x - other.x, y - other.y}; } - constexpr Vec2& operator-=(const Vec2& other) { + constexpr Vec2& operator-=(const Vec2& other) noexcept { x -= other.x; y -= other.y; return *this; } template - [[nodiscard]] constexpr Vec2, U>> operator-() const { + [[nodiscard]] constexpr Vec2, U>> operator-() const noexcept { return {-x, -y}; } - [[nodiscard]] constexpr Vec2 operator*(const Vec2& other) const { + [[nodiscard]] constexpr Vec2 operator*(const Vec2& other) const noexcept { return {x * other.x, y * other.y}; } template - [[nodiscard]] constexpr Vec2 operator*(const V& f) const { + [[nodiscard]] constexpr Vec2 operator*(const V& f) const noexcept { using TV = decltype(T{} * V{}); using C = std::common_type_t; - return { - static_cast(static_cast(x) * static_cast(f)), - static_cast(static_cast(y) * static_cast(f)), + TV(C(x) * C(f)), + TV(C(y) * C(f)), }; } template - constexpr Vec2& operator*=(const V& f) { - *this = *this * f; - return *this; + constexpr Vec2& operator*=(const V& f) noexcept { + return *this = *this * f; } template - [[nodiscard]] constexpr Vec2 operator/(const V& f) const { + [[nodiscard]] constexpr Vec2 operator/(const V& f) const noexcept { using TV = decltype(T{} / V{}); using C = std::common_type_t; - return { - static_cast(static_cast(x) / static_cast(f)), - static_cast(static_cast(y) / static_cast(f)), + TV(C(x) / C(f)), + TV(C(y) / C(f)), }; } template - constexpr Vec2& operator/=(const V& f) { - *this = *this / f; - return *this; + constexpr Vec2& operator/=(const V& f) noexcept { + return *this = *this / f; } - [[nodiscard]] constexpr T Length2() const { + [[nodiscard]] constexpr T Length2() const noexcept { return x * x + y * y; } // Only implemented for T=float [[nodiscard]] float Length() const; - [[nodiscard]] float Normalize(); // returns the previous length, which is often useful - [[nodiscard]] constexpr T& operator[](std::size_t i) { + [[nodiscard]] constexpr T& operator[](std::size_t i) noexcept { return *((&x) + i); } - [[nodiscard]] constexpr const T& operator[](std::size_t i) const { + [[nodiscard]] constexpr const T& operator[](std::size_t i) const noexcept { return *((&x) + i); } - - constexpr void SetZero() { - x = 0; - y = 0; - } - - // Common aliases: UV (texel coordinates), ST (texture coordinates) - [[nodiscard]] constexpr T& u() { - return x; - } - [[nodiscard]] constexpr T& v() { - return y; - } - [[nodiscard]] constexpr T& s() { - return x; - } - [[nodiscard]] constexpr T& t() { - return y; - } - - [[nodiscard]] constexpr const T& u() const { - return x; - } - [[nodiscard]] constexpr const T& v() const { - return y; - } - [[nodiscard]] constexpr const T& s() const { - return x; - } - [[nodiscard]] constexpr const T& t() const { - return y; - } - - // swizzlers - create a subvector of specific components - [[nodiscard]] constexpr Vec2 yx() const { - return Vec2(y, x); - } - [[nodiscard]] constexpr Vec2 vu() const { - return Vec2(y, x); - } - [[nodiscard]] constexpr Vec2 ts() const { - return Vec2(y, x); - } }; template -[[nodiscard]] constexpr Vec2 operator*(const V& f, const Vec2& vec) { +[[nodiscard]] constexpr Vec2 operator*(const V& f, const Vec2& vec) noexcept { using C = std::common_type_t; - - return Vec2(static_cast(static_cast(f) * static_cast(vec.x)), - static_cast(static_cast(f) * static_cast(vec.y))); + return Vec2(T(C(f) * C(vec.x)), T(C(f) * C(vec.y))); } using Vec2f = Vec2; @@ -174,13 +115,6 @@ inline float Vec2::Length() const { return std::sqrt(x * x + y * y); } -template <> -inline float Vec2::Normalize() { - float length = Length(); - *this /= length; - return length; -} - template class Vec3 { public: @@ -189,33 +123,24 @@ public: T z{}; constexpr Vec3() = default; - constexpr Vec3(const T& x_, const T& y_, const T& z_) : x(x_), y(y_), z(z_) {} + constexpr Vec3(const T& x_, const T& y_, const T& z_) noexcept : x(x_), y(y_), z(z_) {} - template - [[nodiscard]] constexpr Vec3 Cast() const { - return Vec3(static_cast(x), static_cast(y), static_cast(z)); - } - - [[nodiscard]] static constexpr Vec3 AssignToAll(const T& f) { - return Vec3(f, f, f); - } - - [[nodiscard]] constexpr Vec3 operator+(const Vec3& other) const { + [[nodiscard]] constexpr Vec3 operator+(const Vec3& other) const noexcept { return {x + other.x, y + other.y, z + other.z}; } - constexpr Vec3& operator+=(const Vec3& other) { + constexpr Vec3 operator+=(const Vec3& other) noexcept { x += other.x; y += other.y; z += other.z; return *this; } - [[nodiscard]] constexpr Vec3 operator-(const Vec3& other) const { + [[nodiscard]] constexpr Vec3 operator-(const Vec3& other) const noexcept { return {x - other.x, y - other.y, z - other.z}; } - constexpr Vec3& operator-=(const Vec3& other) { + constexpr Vec3 operator-=(const Vec3& other) noexcept { x -= other.x; y -= other.y; z -= other.z; @@ -223,177 +148,68 @@ public: } template - [[nodiscard]] constexpr Vec3, U>> operator-() const { + [[nodiscard]] constexpr Vec3, U>> operator-() const noexcept { return {-x, -y, -z}; } - [[nodiscard]] constexpr Vec3 operator*(const Vec3& other) const { + [[nodiscard]] constexpr Vec3 operator*(const Vec3& other) const noexcept { return {x * other.x, y * other.y, z * other.z}; } template - [[nodiscard]] constexpr Vec3 operator*(const V& f) const { + [[nodiscard]] constexpr Vec3 operator*(const V& f) const noexcept { using TV = decltype(T{} * V{}); using C = std::common_type_t; return { - static_cast(static_cast(x) * static_cast(f)), - static_cast(static_cast(y) * static_cast(f)), - static_cast(static_cast(z) * static_cast(f)), + TV(C(x) * C(f)), + TV(C(y) * C(f)), + TV(C(z) * C(f)), }; } template - constexpr Vec3& operator*=(const V& f) { - *this = *this * f; - return *this; + constexpr Vec3 operator*=(const V& f) noexcept { + return *this = *this * f; } template - [[nodiscard]] constexpr Vec3 operator/(const V& f) const { + [[nodiscard]] constexpr Vec3 operator/(const V& f) const noexcept { using TV = decltype(T{} / V{}); using C = std::common_type_t; return { - static_cast(static_cast(x) / static_cast(f)), - static_cast(static_cast(y) / static_cast(f)), - static_cast(static_cast(z) / static_cast(f)), + TV(C(x) / C(f)), + TV(C(y) / C(f)), + TV(C(z) / C(f)), }; } template - constexpr Vec3& operator/=(const V& f) { - *this = *this / f; - return *this; + constexpr Vec3& operator/=(const V& f) noexcept { + return *this = *this / f; } - void RotateFromOrigin(float roll, float pitch, float yaw) { - float temp = y; - y = std::cos(roll) * y - std::sin(roll) * z; - z = std::sin(roll) * temp + std::cos(roll) * z; - - temp = x; - x = std::cos(pitch) * x + std::sin(pitch) * z; - z = -std::sin(pitch) * temp + std::cos(pitch) * z; - - temp = x; - x = std::cos(yaw) * x - std::sin(yaw) * y; - y = std::sin(yaw) * temp + std::cos(yaw) * y; - } - - [[nodiscard]] constexpr T Length2() const { + [[nodiscard]] constexpr T Length2() const noexcept { return x * x + y * y + z * z; } // Only implemented for T=float [[nodiscard]] float Length() const; [[nodiscard]] Vec3 Normalized() const; - [[nodiscard]] float Normalize(); // returns the previous length, which is often useful - [[nodiscard]] constexpr T& operator[](std::size_t i) { + [[nodiscard]] constexpr T& operator[](std::size_t i) noexcept { return *((&x) + i); } - [[nodiscard]] constexpr const T& operator[](std::size_t i) const { + [[nodiscard]] constexpr const T& operator[](std::size_t i) const noexcept { return *((&x) + i); } - - constexpr void SetZero() { - x = 0; - y = 0; - z = 0; - } - - // Common aliases: UVW (texel coordinates), RGB (colors), STQ (texture coordinates) - [[nodiscard]] constexpr T& u() { - return x; - } - [[nodiscard]] constexpr T& v() { - return y; - } - [[nodiscard]] constexpr T& w() { - return z; - } - - [[nodiscard]] constexpr T& r() { - return x; - } - [[nodiscard]] constexpr T& g() { - return y; - } - [[nodiscard]] constexpr T& b() { - return z; - } - - [[nodiscard]] constexpr T& s() { - return x; - } - [[nodiscard]] constexpr T& t() { - return y; - } - [[nodiscard]] constexpr T& q() { - return z; - } - - [[nodiscard]] constexpr const T& u() const { - return x; - } - [[nodiscard]] constexpr const T& v() const { - return y; - } - [[nodiscard]] constexpr const T& w() const { - return z; - } - - [[nodiscard]] constexpr const T& r() const { - return x; - } - [[nodiscard]] constexpr const T& g() const { - return y; - } - [[nodiscard]] constexpr const T& b() const { - return z; - } - - [[nodiscard]] constexpr const T& s() const { - return x; - } - [[nodiscard]] constexpr const T& t() const { - return y; - } - [[nodiscard]] constexpr const T& q() const { - return z; - } - -// swizzlers - create a subvector of specific components -// e.g. Vec2 uv() { return Vec2(x,y); } -// _DEFINE_SWIZZLER2 defines a single such function, DEFINE_SWIZZLER2 defines all of them for all -// component names (x<->r) and permutations (xy<->yx) -#define _DEFINE_SWIZZLER2(a, b, name) \ - [[nodiscard]] constexpr Vec2 name() const { return Vec2(a, b); } -#define DEFINE_SWIZZLER2(a, b, a2, b2, a3, b3, a4, b4) \ - _DEFINE_SWIZZLER2(a, b, a##b); \ - _DEFINE_SWIZZLER2(a, b, a2##b2); \ - _DEFINE_SWIZZLER2(a, b, a3##b3); \ - _DEFINE_SWIZZLER2(a, b, a4##b4); \ - _DEFINE_SWIZZLER2(b, a, b##a); \ - _DEFINE_SWIZZLER2(b, a, b2##a2); \ - _DEFINE_SWIZZLER2(b, a, b3##a3); \ - _DEFINE_SWIZZLER2(b, a, b4##a4) - - DEFINE_SWIZZLER2(x, y, r, g, u, v, s, t); - DEFINE_SWIZZLER2(x, z, r, b, u, w, s, q); - DEFINE_SWIZZLER2(y, z, g, b, v, w, t, q); -#undef DEFINE_SWIZZLER2 -#undef _DEFINE_SWIZZLER2 }; template -[[nodiscard]] constexpr Vec3 operator*(const V& f, const Vec3& vec) { +[[nodiscard]] constexpr Vec3 operator*(const V& f, const Vec3& vec) noexcept { using C = std::common_type_t; - - return Vec3(static_cast(static_cast(f) * static_cast(vec.x)), - static_cast(static_cast(f) * static_cast(vec.y)), - static_cast(static_cast(f) * static_cast(vec.z))); + return Vec3(T(C(f) * C(vec.x)), T(C(f) * C(vec.y)), T(C(f) * C(vec.z))); } template <> @@ -406,353 +222,62 @@ inline Vec3 Vec3::Normalized() const { return *this / Length(); } -template <> -inline float Vec3::Normalize() { - float length = Length(); - *this /= length; - return length; -} - using Vec3f = Vec3; template -class Vec4 { +class Quaternion { public: - T x{}; - T y{}; - T z{}; + Vec3 xyz; T w{}; - constexpr Vec4() = default; - constexpr Vec4(const T& x_, const T& y_, const T& z_, const T& w_) - : x(x_), y(y_), z(z_), w(w_) {} - - template - [[nodiscard]] constexpr Vec4 Cast() const { - return Vec4(static_cast(x), static_cast(y), static_cast(z), - static_cast(w)); + [[nodiscard]] Quaternion operator+(const Quaternion& other) const noexcept { + return {xyz + other.xyz, w + other.w}; } - [[nodiscard]] static constexpr Vec4 AssignToAll(const T& f) { - return Vec4(f, f, f, f); + [[nodiscard]] Quaternion operator-(const Quaternion& other) const noexcept { + return {xyz - other.xyz, w - other.w}; } - [[nodiscard]] constexpr Vec4 operator+(const Vec4& other) const { - return {x + other.x, y + other.y, z + other.z, w + other.w}; + [[nodiscard]] Quaternion operator*(const Quaternion& other) const noexcept { + return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz), w * other.w - Dot(xyz, other.xyz)}; } - constexpr Vec4& operator+=(const Vec4& other) { - x += other.x; - y += other.y; - z += other.z; - w += other.w; - return *this; + [[nodiscard]] Quaternion Normalized() const noexcept { + T length = std::sqrt(xyz.Length2() + w * w); + return {xyz / length, w / length}; } - [[nodiscard]] constexpr Vec4 operator-(const Vec4& other) const { - return {x - other.x, y - other.y, z - other.z, w - other.w}; - } + [[nodiscard]] std::array ToMatrix() const { + const T x2 = xyz[0] * xyz[0]; + const T y2 = xyz[1] * xyz[1]; + const T z2 = xyz[2] * xyz[2]; - constexpr Vec4& operator-=(const Vec4& other) { - x -= other.x; - y -= other.y; - z -= other.z; - w -= other.w; - return *this; - } - - template - [[nodiscard]] constexpr Vec4, U>> operator-() const { - return {-x, -y, -z, -w}; - } - - [[nodiscard]] constexpr Vec4 operator*(const Vec4& other) const { - return {x * other.x, y * other.y, z * other.z, w * other.w}; - } - - template - [[nodiscard]] constexpr Vec4 operator*(const V& f) const { - using TV = decltype(T{} * V{}); - using C = std::common_type_t; + const T xy = xyz[0] * xyz[1]; + const T wz = w * xyz[2]; + const T xz = xyz[0] * xyz[2]; + const T wy = w * xyz[1]; + const T yz = xyz[1] * xyz[2]; + const T wx = w * xyz[0]; return { - static_cast(static_cast(x) * static_cast(f)), - static_cast(static_cast(y) * static_cast(f)), - static_cast(static_cast(z) * static_cast(f)), - static_cast(static_cast(w) * static_cast(f)), + 1.0f - 2.0f * (y2 + z2), + 2.0f * (xy + wz), + 2.0f * (xz - wy), + 0.0f, + 2.0f * (xy - wz), + 1.0f - 2.0f * (x2 + z2), + 2.0f * (yz + wx), + 0.0f, + 2.0f * (xz + wy), + 2.0f * (yz - wx), + 1.0f - 2.0f * (x2 + y2), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f }; } - - template - constexpr Vec4& operator*=(const V& f) { - *this = *this * f; - return *this; - } - - template - [[nodiscard]] constexpr Vec4 operator/(const V& f) const { - using TV = decltype(T{} / V{}); - using C = std::common_type_t; - - return { - static_cast(static_cast(x) / static_cast(f)), - static_cast(static_cast(y) / static_cast(f)), - static_cast(static_cast(z) / static_cast(f)), - static_cast(static_cast(w) / static_cast(f)), - }; - } - - template - constexpr Vec4& operator/=(const V& f) { - *this = *this / f; - return *this; - } - - [[nodiscard]] constexpr T Length2() const { - return x * x + y * y + z * z + w * w; - } - - [[nodiscard]] constexpr T& operator[](std::size_t i) { - return *((&x) + i); - } - - [[nodiscard]] constexpr const T& operator[](std::size_t i) const { - return *((&x) + i); - } - - constexpr void SetZero() { - x = 0; - y = 0; - z = 0; - w = 0; - } - - // Common alias: RGBA (colors) - [[nodiscard]] constexpr T& r() { - return x; - } - [[nodiscard]] constexpr T& g() { - return y; - } - [[nodiscard]] constexpr T& b() { - return z; - } - [[nodiscard]] constexpr T& a() { - return w; - } - - [[nodiscard]] constexpr const T& r() const { - return x; - } - [[nodiscard]] constexpr const T& g() const { - return y; - } - [[nodiscard]] constexpr const T& b() const { - return z; - } - [[nodiscard]] constexpr const T& a() const { - return w; - } - -// Swizzlers - Create a subvector of specific components -// e.g. Vec2 uv() { return Vec2(x,y); } - -// _DEFINE_SWIZZLER2 defines a single such function -// DEFINE_SWIZZLER2_COMP1 defines one-component functions for all component names (x<->r) -// DEFINE_SWIZZLER2_COMP2 defines two component functions for all component names (x<->r) and -// permutations (xy<->yx) -#define _DEFINE_SWIZZLER2(a, b, name) \ - [[nodiscard]] constexpr Vec2 name() const { return Vec2(a, b); } -#define DEFINE_SWIZZLER2_COMP1(a, a2) \ - _DEFINE_SWIZZLER2(a, a, a##a); \ - _DEFINE_SWIZZLER2(a, a, a2##a2) -#define DEFINE_SWIZZLER2_COMP2(a, b, a2, b2) \ - _DEFINE_SWIZZLER2(a, b, a##b); \ - _DEFINE_SWIZZLER2(a, b, a2##b2); \ - _DEFINE_SWIZZLER2(b, a, b##a); \ - _DEFINE_SWIZZLER2(b, a, b2##a2) - - DEFINE_SWIZZLER2_COMP2(x, y, r, g); - DEFINE_SWIZZLER2_COMP2(x, z, r, b); - DEFINE_SWIZZLER2_COMP2(x, w, r, a); - DEFINE_SWIZZLER2_COMP2(y, z, g, b); - DEFINE_SWIZZLER2_COMP2(y, w, g, a); - DEFINE_SWIZZLER2_COMP2(z, w, b, a); - DEFINE_SWIZZLER2_COMP1(x, r); - DEFINE_SWIZZLER2_COMP1(y, g); - DEFINE_SWIZZLER2_COMP1(z, b); - DEFINE_SWIZZLER2_COMP1(w, a); -#undef DEFINE_SWIZZLER2_COMP1 -#undef DEFINE_SWIZZLER2_COMP2 -#undef _DEFINE_SWIZZLER2 - -#define _DEFINE_SWIZZLER3(a, b, c, name) \ - [[nodiscard]] constexpr Vec3 name() const { return Vec3(a, b, c); } -#define DEFINE_SWIZZLER3_COMP1(a, a2) \ - _DEFINE_SWIZZLER3(a, a, a, a##a##a); \ - _DEFINE_SWIZZLER3(a, a, a, a2##a2##a2) -#define DEFINE_SWIZZLER3_COMP3(a, b, c, a2, b2, c2) \ - _DEFINE_SWIZZLER3(a, b, c, a##b##c); \ - _DEFINE_SWIZZLER3(a, c, b, a##c##b); \ - _DEFINE_SWIZZLER3(b, a, c, b##a##c); \ - _DEFINE_SWIZZLER3(b, c, a, b##c##a); \ - _DEFINE_SWIZZLER3(c, a, b, c##a##b); \ - _DEFINE_SWIZZLER3(c, b, a, c##b##a); \ - _DEFINE_SWIZZLER3(a, b, c, a2##b2##c2); \ - _DEFINE_SWIZZLER3(a, c, b, a2##c2##b2); \ - _DEFINE_SWIZZLER3(b, a, c, b2##a2##c2); \ - _DEFINE_SWIZZLER3(b, c, a, b2##c2##a2); \ - _DEFINE_SWIZZLER3(c, a, b, c2##a2##b2); \ - _DEFINE_SWIZZLER3(c, b, a, c2##b2##a2) - - DEFINE_SWIZZLER3_COMP3(x, y, z, r, g, b); - DEFINE_SWIZZLER3_COMP3(x, y, w, r, g, a); - DEFINE_SWIZZLER3_COMP3(x, z, w, r, b, a); - DEFINE_SWIZZLER3_COMP3(y, z, w, g, b, a); - DEFINE_SWIZZLER3_COMP1(x, r); - DEFINE_SWIZZLER3_COMP1(y, g); - DEFINE_SWIZZLER3_COMP1(z, b); - DEFINE_SWIZZLER3_COMP1(w, a); -#undef DEFINE_SWIZZLER3_COMP1 -#undef DEFINE_SWIZZLER3_COMP3 -#undef _DEFINE_SWIZZLER3 }; -template -[[nodiscard]] constexpr Vec4 operator*(const V& f, const Vec4& vec) { - using TV = decltype(V{} * T{}); - using C = std::common_type_t; - - return { - static_cast(static_cast(f) * static_cast(vec.x)), - static_cast(static_cast(f) * static_cast(vec.y)), - static_cast(static_cast(f) * static_cast(vec.z)), - static_cast(static_cast(f) * static_cast(vec.w)), - }; -} - -using Vec4f = Vec4; - -template -constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec2& a, const Vec2& b) { - return a.x * b.x + a.y * b.y; -} - -template -[[nodiscard]] constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec3& a, const Vec3& b) { - return a.x * b.x + a.y * b.y + a.z * b.z; -} - -template -[[nodiscard]] constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec4& a, const Vec4& b) { - return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; -} - -template <> -[[nodiscard]] inline float Dot(const Vec4& a, const Vec4& b) { -#ifdef __ARM_NEON - float32x4_t va = vld1q_f32(&a.x); - float32x4_t vb = vld1q_f32(&b.x); - float32x4_t result = vmulq_f32(va, vb); -#if defined(__aarch64__) // Use vaddvq_f32 in ARMv8 architectures - return vaddvq_f32(result); -#else // Use manual addition for older architectures - float32x2_t sum2 = vadd_f32(vget_high_f32(result), vget_low_f32(result)); - return vget_lane_f32(vpadd_f32(sum2, sum2), 0); -#endif -#else - return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; -#endif -} - -template -[[nodiscard]] constexpr Vec3 Cross(const Vec3& a, - const Vec3& b) { - return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; -} - -// linear interpolation via float: 0.0=begin, 1.0=end -template -[[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end, - const float t) { - return begin * (1.f - t) + end * t; -} - -// linear interpolation via int: 0=begin, base=end -template -[[nodiscard]] constexpr decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begin, - const X& end, - const int t) { - return (begin * (base - t) + end * t) / base; -} - -// bilinear interpolation. s is for interpolating x00-x01 and x10-x11, and t is for the second -// interpolation. -template -[[nodiscard]] constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& x11, - const float s, const float t) { - auto y0 = Lerp(x00, x01, s); - auto y1 = Lerp(x10, x11, s); - return Lerp(y0, y1, t); -} - -// Utility vector factories -template -[[nodiscard]] constexpr Vec2 MakeVec(const T& x, const T& y) { - return Vec2{x, y}; -} - -template -[[nodiscard]] constexpr Vec3 MakeVec(const T& x, const T& y, const T& z) { - return Vec3{x, y, z}; -} - -template -[[nodiscard]] constexpr Vec4 MakeVec(const T& x, const T& y, const Vec2& zw) { - return MakeVec(x, y, zw[0], zw[1]); -} - -template -[[nodiscard]] constexpr Vec3 MakeVec(const Vec2& xy, const T& z) { - return MakeVec(xy[0], xy[1], z); -} - -template -[[nodiscard]] constexpr Vec3 MakeVec(const T& x, const Vec2& yz) { - return MakeVec(x, yz[0], yz[1]); -} - -template -[[nodiscard]] constexpr Vec4 MakeVec(const T& x, const T& y, const T& z, const T& w) { - return Vec4{x, y, z, w}; -} - -template -[[nodiscard]] constexpr Vec4 MakeVec(const Vec2& xy, const T& z, const T& w) { - return MakeVec(xy[0], xy[1], z, w); -} - -template -[[nodiscard]] constexpr Vec4 MakeVec(const T& x, const Vec2& yz, const T& w) { - return MakeVec(x, yz[0], yz[1], w); -} - -// NOTE: This has priority over "Vec2> MakeVec(const Vec2& x, const Vec2& y)". -// Even if someone wanted to use an odd object like Vec2>, the compiler would error -// out soon enough due to misuse of the returned structure. -template -[[nodiscard]] constexpr Vec4 MakeVec(const Vec2& xy, const Vec2& zw) { - return MakeVec(xy[0], xy[1], zw[0], zw[1]); -} - -template -[[nodiscard]] constexpr Vec4 MakeVec(const Vec3& xyz, const T& w) { - return MakeVec(xyz[0], xyz[1], xyz[2], w); -} - -template -[[nodiscard]] constexpr Vec4 MakeVec(const T& x, const Vec3& yzw) { - return MakeVec(x, yzw[0], yzw[1], yzw[2]); -} - } // namespace Common diff --git a/src/hid_core/frontend/emulated_console.h b/src/hid_core/frontend/emulated_console.h index ca7d7dd8fc..1b3ec8a87b 100644 --- a/src/hid_core/frontend/emulated_console.h +++ b/src/hid_core/frontend/emulated_console.h @@ -18,7 +18,6 @@ #include "common/input.h" #include "common/param_package.h" #include "common/point.h" -#include "common/quaternion.h" #include "common/vector_math.h" #include "hid_core/frontend/motion_input.h" #include "hid_core/hid_types.h" diff --git a/src/hid_core/frontend/motion_input.h b/src/hid_core/frontend/motion_input.h index c902a3a6e5..212f51c83d 100644 --- a/src/hid_core/frontend/motion_input.h +++ b/src/hid_core/frontend/motion_input.h @@ -1,10 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include "common/common_types.h" -#include "common/quaternion.h" #include "common/vector_math.h" namespace Core::HID { diff --git a/src/hid_core/resources/six_axis/seven_six_axis.h b/src/hid_core/resources/six_axis/seven_six_axis.h index 00afb8c00b..d106f0bfc0 100644 --- a/src/hid_core/resources/six_axis/seven_six_axis.h +++ b/src/hid_core/resources/six_axis/seven_six_axis.h @@ -7,7 +7,7 @@ #pragma once #include "common/common_types.h" -#include "common/quaternion.h" +#include "common/vector_math.h" #include "common/typed_address.h" #include "hid_core/resources/controller_base.h" #include "hid_core/resources/ring_lifo.h" diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp index 00b7220c1e..d306ae7e29 100644 --- a/src/input_common/drivers/mouse.cpp +++ b/src/input_common/drivers/mouse.cpp @@ -135,32 +135,25 @@ void Mouse::UpdateMotionInput() { void Mouse::Move(int x, int y, int center_x, int center_y) { if (IsMousePanningEnabled()) { - const auto mouse_change = - (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast(); - const float x_sensitivity = - Settings::values.mouse_panning_x_sensitivity.GetValue() * default_panning_sensitivity; - const float y_sensitivity = - Settings::values.mouse_panning_y_sensitivity.GetValue() * default_panning_sensitivity; - const float deadzone_counterweight = - Settings::values.mouse_panning_deadzone_counterweight.GetValue() * - default_deadzone_counterweight; - + auto const mouse_change_int = Common::Vec2(x, y) - Common::Vec2(center_x, center_y); + auto const mouse_change = Common::Vec2(float(mouse_change_int.x), float(mouse_change_int.y)); + auto const x_sensitivity = Settings::values.mouse_panning_x_sensitivity.GetValue() * default_panning_sensitivity; + auto const y_sensitivity = Settings::values.mouse_panning_y_sensitivity.GetValue() * default_panning_sensitivity; + auto const deadzone_cw = Settings::values.mouse_panning_deadzone_counterweight.GetValue() * default_deadzone_counterweight; last_motion_change += {-mouse_change.y * x_sensitivity, -mouse_change.x * y_sensitivity, 0}; last_mouse_change.x += mouse_change.x * x_sensitivity; last_mouse_change.y += mouse_change.y * y_sensitivity; - - // Bind the mouse change to [0 <= deadzone_counterweight <= 1.0] + // Bind the mouse change to [0 <= deadzone_cw <= 1.0] const float length = last_mouse_change.Length(); - if (length < deadzone_counterweight && length != 0.0f) { + if (length < deadzone_cw && length != 0.0f) { last_mouse_change /= length; - last_mouse_change *= deadzone_counterweight; + last_mouse_change *= deadzone_cw; } - return; } if (button_pressed) { - const auto mouse_move = Common::MakeVec(x, y) - mouse_origin; + const auto mouse_move = Common::Vec2(x, y) - mouse_origin; const float x_sensitivity = Settings::values.mouse_panning_x_sensitivity.GetValue() * default_stick_sensitivity; const float y_sensitivity = diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp index a6be2a1dd4..4891536322 100644 --- a/src/yuzu/configuration/configure_input_player_widget.cpp +++ b/src/yuzu/configuration/configure_input_player_widget.cpp @@ -2950,7 +2950,15 @@ void PlayerControlPreview::Draw3dCube(QPainter& p, QPointF center, const Common: }; for (Common::Vec3f& point : cube) { - point.RotateFromOrigin(euler.x, euler.y, euler.z); + float temp = point.y; + point.y = std::cos(euler.x) * point.y - std::sin(euler.x) * point.z; + point.z = std::sin(euler.x) * temp + std::cos(euler.x) * point.z; + temp = point.x; + point.x = std::cos(euler.y) * point.x + std::sin(euler.y) * point.z; + point.z = -std::sin(euler.y) * temp + std::cos(euler.y) * point.z; + temp = point.x; + point.x = std::cos(euler.z) * point.x - std::sin(euler.z) * point.y; + point.y = std::sin(euler.z) * temp + std::cos(euler.z) * point.y; point *= size; }