From 1b855efd5eb21ef802d15f6a531878754904ad4d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 26 Feb 2019 22:38:34 -0500 Subject: [PATCH] common/vector_math: Move Vec[x] types into the Common namespace These types are within the common library, so they should be using the Common namespace. --- src/common/color.h | 40 +++++++++---------- src/common/quaternion.h | 6 +-- src/common/vector_math.h | 4 +- src/core/frontend/input.h | 2 +- src/input_common/motion_emu.cpp | 22 +++++----- .../debugger/graphics/graphics_surface.cpp | 2 +- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/common/color.h b/src/common/color.h index 0379040be..3a2222077 100644 --- a/src/common/color.h +++ b/src/common/color.h @@ -55,36 +55,36 @@ constexpr u8 Convert8To6(u8 value) { /** * Decode a color stored in RGBA8 format * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4 + * @return Result color decoded as Common::Vec4 */ -inline Math::Vec4 DecodeRGBA8(const u8* bytes) { +inline Common::Vec4 DecodeRGBA8(const u8* bytes) { return {bytes[3], bytes[2], bytes[1], bytes[0]}; } /** * Decode a color stored in RGB8 format * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4 + * @return Result color decoded as Common::Vec4 */ -inline Math::Vec4 DecodeRGB8(const u8* bytes) { +inline Common::Vec4 DecodeRGB8(const u8* bytes) { return {bytes[2], bytes[1], bytes[0], 255}; } /** * Decode a color stored in RG8 (aka HILO8) format * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4 + * @return Result color decoded as Common::Vec4 */ -inline Math::Vec4 DecodeRG8(const u8* bytes) { +inline Common::Vec4 DecodeRG8(const u8* bytes) { return {bytes[1], bytes[0], 0, 255}; } /** * Decode a color stored in RGB565 format * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4 + * @return Result color decoded as Common::Vec4 */ -inline Math::Vec4 DecodeRGB565(const u8* bytes) { +inline Common::Vec4 DecodeRGB565(const u8* bytes) { u16_le pixel; std::memcpy(&pixel, bytes, sizeof(pixel)); return {Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F), @@ -94,9 +94,9 @@ inline Math::Vec4 DecodeRGB565(const u8* bytes) { /** * Decode a color stored in RGB5A1 format * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4 + * @return Result color decoded as Common::Vec4 */ -inline Math::Vec4 DecodeRGB5A1(const u8* bytes) { +inline Common::Vec4 DecodeRGB5A1(const u8* bytes) { u16_le pixel; std::memcpy(&pixel, bytes, sizeof(pixel)); return {Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F), @@ -106,9 +106,9 @@ inline Math::Vec4 DecodeRGB5A1(const u8* bytes) { /** * Decode a color stored in RGBA4 format * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4 + * @return Result color decoded as Common::Vec4 */ -inline Math::Vec4 DecodeRGBA4(const u8* bytes) { +inline Common::Vec4 DecodeRGBA4(const u8* bytes) { u16_le pixel; std::memcpy(&pixel, bytes, sizeof(pixel)); return {Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF), @@ -138,9 +138,9 @@ inline u32 DecodeD24(const u8* bytes) { /** * Decode a depth value and a stencil value stored in D24S8 format * @param bytes Pointer to encoded source values - * @return Resulting values stored as a Math::Vec2 + * @return Resulting values stored as a Common::Vec2 */ -inline Math::Vec2 DecodeD24S8(const u8* bytes) { +inline Common::Vec2 DecodeD24S8(const u8* bytes) { return {static_cast((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3]}; } @@ -149,7 +149,7 @@ inline Math::Vec2 DecodeD24S8(const u8* bytes) { * @param color Source color to encode * @param bytes Destination pointer to store encoded color */ -inline void EncodeRGBA8(const Math::Vec4& color, u8* bytes) { +inline void EncodeRGBA8(const Common::Vec4& color, u8* bytes) { bytes[3] = color.r(); bytes[2] = color.g(); bytes[1] = color.b(); @@ -161,7 +161,7 @@ inline void EncodeRGBA8(const Math::Vec4& color, u8* bytes) { * @param color Source color to encode * @param bytes Destination pointer to store encoded color */ -inline void EncodeRGB8(const Math::Vec4& color, u8* bytes) { +inline void EncodeRGB8(const Common::Vec4& color, u8* bytes) { bytes[2] = color.r(); bytes[1] = color.g(); bytes[0] = color.b(); @@ -172,7 +172,7 @@ inline void EncodeRGB8(const Math::Vec4& color, u8* bytes) { * @param color Source color to encode * @param bytes Destination pointer to store encoded color */ -inline void EncodeRG8(const Math::Vec4& color, u8* bytes) { +inline void EncodeRG8(const Common::Vec4& color, u8* bytes) { bytes[1] = color.r(); bytes[0] = color.g(); } @@ -181,7 +181,7 @@ inline void EncodeRG8(const Math::Vec4& color, u8* bytes) { * @param color Source color to encode * @param bytes Destination pointer to store encoded color */ -inline void EncodeRGB565(const Math::Vec4& color, u8* bytes) { +inline void EncodeRGB565(const Common::Vec4& color, u8* bytes) { const u16_le data = (Convert8To5(color.r()) << 11) | (Convert8To6(color.g()) << 5) | Convert8To5(color.b()); @@ -193,7 +193,7 @@ inline void EncodeRGB565(const Math::Vec4& color, u8* bytes) { * @param color Source color to encode * @param bytes Destination pointer to store encoded color */ -inline void EncodeRGB5A1(const Math::Vec4& color, u8* bytes) { +inline void EncodeRGB5A1(const Common::Vec4& color, u8* bytes) { const u16_le data = (Convert8To5(color.r()) << 11) | (Convert8To5(color.g()) << 6) | (Convert8To5(color.b()) << 1) | Convert8To1(color.a()); @@ -205,7 +205,7 @@ inline void EncodeRGB5A1(const Math::Vec4& color, u8* bytes) { * @param color Source color to encode * @param bytes Destination pointer to store encoded color */ -inline void EncodeRGBA4(const Math::Vec4& color, u8* bytes) { +inline void EncodeRGBA4(const Common::Vec4& color, u8* bytes) { const u16 data = (Convert8To4(color.r()) << 12) | (Convert8To4(color.g()) << 8) | (Convert8To4(color.b()) << 4) | Convert8To4(color.a()); diff --git a/src/common/quaternion.h b/src/common/quaternion.h index 1c304b048..370198ae0 100644 --- a/src/common/quaternion.h +++ b/src/common/quaternion.h @@ -11,7 +11,7 @@ namespace Common { template class Quaternion { public: - Math::Vec3 xyz; + Vec3 xyz; T w{}; Quaternion Inverse() const { @@ -38,11 +38,11 @@ public: }; template -auto QuaternionRotate(const Quaternion& q, const Math::Vec3& v) { +auto QuaternionRotate(const Quaternion& q, const Vec3& v) { return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w); } -inline Quaternion MakeQuaternion(const Math::Vec3& axis, float angle) { +inline Quaternion MakeQuaternion(const Vec3& axis, float angle) { return {axis * std::sin(angle / 2), std::cos(angle / 2)}; } diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 8feb49941..429485329 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -33,7 +33,7 @@ #include #include -namespace Math { +namespace Common { template class Vec2; @@ -690,4 +690,4 @@ constexpr Vec4 MakeVec(const T& x, const Vec3& yzw) { return MakeVec(x, yzw[0], yzw[1], yzw[2]); } -} // namespace Math +} // namespace Common diff --git a/src/core/frontend/input.h b/src/core/frontend/input.h index 16fdcd376..7c11d7546 100644 --- a/src/core/frontend/input.h +++ b/src/core/frontend/input.h @@ -124,7 +124,7 @@ using AnalogDevice = InputDevice>; * Orientation is determined by right-hand rule. * Units: deg/sec */ -using MotionDevice = InputDevice, Math::Vec3>>; +using MotionDevice = InputDevice, Common::Vec3>>; /** * A touch device is an input device that returns a tuple of two floats and a bool. The floats are diff --git a/src/input_common/motion_emu.cpp b/src/input_common/motion_emu.cpp index defb1a567..d5af05ee3 100644 --- a/src/input_common/motion_emu.cpp +++ b/src/input_common/motion_emu.cpp @@ -32,12 +32,12 @@ public: } void BeginTilt(int x, int y) { - mouse_origin = Math::MakeVec(x, y); + mouse_origin = Common::MakeVec(x, y); is_tilting = true; } void Tilt(int x, int y) { - auto mouse_move = Math::MakeVec(x, y) - mouse_origin; + auto mouse_move = Common::MakeVec(x, y) - mouse_origin; if (is_tilting) { std::lock_guard guard(tilt_mutex); if (mouse_move.x == 0 && mouse_move.y == 0) { @@ -56,7 +56,7 @@ public: is_tilting = false; } - std::tuple, Math::Vec3> GetStatus() { + std::tuple, Common::Vec3> GetStatus() { std::lock_guard guard(status_mutex); return status; } @@ -66,17 +66,17 @@ private: const std::chrono::steady_clock::duration update_duration; const float sensitivity; - Math::Vec2 mouse_origin; + Common::Vec2 mouse_origin; std::mutex tilt_mutex; - Math::Vec2 tilt_direction; + Common::Vec2 tilt_direction; float tilt_angle = 0; bool is_tilting = false; Common::Event shutdown_event; - std::tuple, Math::Vec3> status; + std::tuple, Common::Vec3> status; std::mutex status_mutex; // Note: always keep the thread declaration at the end so that other objects are initialized @@ -85,7 +85,7 @@ private: void MotionEmuThread() { auto update_time = std::chrono::steady_clock::now(); - Common::Quaternion q = Common::MakeQuaternion(Math::Vec3(), 0); + Common::Quaternion q = Common::MakeQuaternion(Common::Vec3(), 0); Common::Quaternion old_q; while (!shutdown_event.WaitUntil(update_time)) { @@ -96,14 +96,14 @@ private: std::lock_guard guard(tilt_mutex); // Find the quaternion describing current 3DS tilting - q = Common::MakeQuaternion(Math::MakeVec(-tilt_direction.y, 0.0f, tilt_direction.x), - tilt_angle); + q = Common::MakeQuaternion( + Common::MakeVec(-tilt_direction.y, 0.0f, tilt_direction.x), tilt_angle); } auto inv_q = q.Inverse(); // Set the gravity vector in world space - auto gravity = Math::MakeVec(0.0f, -1.0f, 0.0f); + auto gravity = Common::MakeVec(0.0f, -1.0f, 0.0f); // Find the angular rate vector in world space auto angular_rate = ((q - old_q) * inv_q).xyz * 2; @@ -131,7 +131,7 @@ public: device = std::make_shared(update_millisecond, sensitivity); } - std::tuple, Math::Vec3> GetStatus() const override { + std::tuple, Common::Vec3> GetStatus() const override { return device->GetStatus(); } diff --git a/src/yuzu/debugger/graphics/graphics_surface.cpp b/src/yuzu/debugger/graphics/graphics_surface.cpp index 209798521..71683da8e 100644 --- a/src/yuzu/debugger/graphics/graphics_surface.cpp +++ b/src/yuzu/debugger/graphics/graphics_surface.cpp @@ -398,7 +398,7 @@ void GraphicsSurfaceWidget::OnUpdate() { for (unsigned int y = 0; y < surface_height; ++y) { for (unsigned int x = 0; x < surface_width; ++x) { - Math::Vec4 color; + Common::Vec4 color; color[0] = texture_data[x + y * surface_width + 0]; color[1] = texture_data[x + y * surface_width + 1]; color[2] = texture_data[x + y * surface_width + 2];