mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-07-11 02:16:39 +02:00
[hid_core, input_common] use std::numbers::pi{_v} instead of re-defining (#4160)
don't reinvent the wheel, simple as that. Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4160 Reviewed-by: MaranBr <maranbr@eden-emu.dev> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
This commit is contained in:
@@ -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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: 2013 Dolphin Emulator Project
|
// SPDX-FileCopyrightText: 2013 Dolphin Emulator Project
|
||||||
@@ -13,8 +13,6 @@
|
|||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
constexpr float PI = 3.1415926535f;
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct Rectangle {
|
struct Rectangle {
|
||||||
T left{};
|
T left{};
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <numbers>
|
||||||
|
|
||||||
#include "common/math_util.h"
|
#include "common/math_util.h"
|
||||||
#include "hid_core/frontend/motion_input.h"
|
#include "hid_core/frontend/motion_input.h"
|
||||||
@@ -145,7 +149,7 @@ void MotionInput::UpdateOrientation(u64 elapsed_time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto normal_accel = accel.Normalized();
|
const auto normal_accel = accel.Normalized();
|
||||||
auto rad_gyro = gyro * Common::PI * 2;
|
auto rad_gyro = gyro * std::numbers::pi_v<float> * 2.f;
|
||||||
const f32 swap = rad_gyro.x;
|
const f32 swap = rad_gyro.x;
|
||||||
rad_gyro.x = rad_gyro.y;
|
rad_gyro.x = rad_gyro.y;
|
||||||
rad_gyro.y = -swap;
|
rad_gyro.y = -swap;
|
||||||
@@ -272,7 +276,7 @@ Common::Vec3f MotionInput::GetEulerAngles() const {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
std::atan2(sinr_cosp, cosr_cosp),
|
std::atan2(sinr_cosp, cosr_cosp),
|
||||||
2 * std::atan2(sinp, cosp) - Common::PI / 2,
|
2 * std::atan2(sinp, cosp) - float(std::numbers::pi_v<float>) / 2,
|
||||||
std::atan2(siny_cosp, cosy_cosp),
|
std::atan2(siny_cosp, cosy_cosp),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#include <numbers>
|
||||||
#include "common/math_util.h"
|
#include "common/math_util.h"
|
||||||
#include "hid_core/resources/touch_screen/gesture_handler.h"
|
#include "hid_core/resources/touch_screen/gesture_handler.h"
|
||||||
|
|
||||||
@@ -214,7 +215,7 @@ void GestureHandler::UpdatePanEvent(GestureState& next_state, GestureType& type)
|
|||||||
if (std::abs(angle_between_two_lines) > AngleThreshold) {
|
if (std::abs(angle_between_two_lines) > AngleThreshold) {
|
||||||
type = GestureType::Rotate;
|
type = GestureType::Rotate;
|
||||||
next_state.scale = 0;
|
next_state.scale = 0;
|
||||||
next_state.rotation_angle = angle_between_two_lines * 180.0f / Common::PI;
|
next_state.rotation_angle = angle_between_two_lines * 180.0f / float(std::numbers::pi_v<float>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
// SPDX-FileCopyrightText: 2018 Citra Emulator Project
|
// SPDX-FileCopyrightText: 2018 Citra Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <numbers>
|
||||||
#include "common/logging.h"
|
#include "common/logging.h"
|
||||||
#include "common/math_util.h"
|
#include "common/math_util.h"
|
||||||
#include "common/param_package.h"
|
#include "common/param_package.h"
|
||||||
@@ -146,9 +148,9 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDL_SENSOR_GYRO: {
|
case SDL_SENSOR_GYRO: {
|
||||||
motion.gyro_x = event.data[0] / (Common::PI * 2);
|
motion.gyro_x = event.data[0] / (f32(std::numbers::pi_v<float>) * 2);
|
||||||
motion.gyro_y = -event.data[2] / (Common::PI * 2);
|
motion.gyro_y = -event.data[2] / (f32(std::numbers::pi_v<float>) * 2);
|
||||||
motion.gyro_z = event.data[1] / (Common::PI * 2);
|
motion.gyro_z = event.data[1] / (f32(std::numbers::pi_v<float>) * 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: 2017 Citra Emulator Project
|
// SPDX-FileCopyrightText: 2017 Citra Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <numbers>
|
||||||
#include "common/math_util.h"
|
#include "common/math_util.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "input_common/helpers/stick_from_buttons.h"
|
#include "input_common/helpers/stick_from_buttons.h"
|
||||||
@@ -15,9 +19,8 @@ public:
|
|||||||
// do not play nicely with the theoretical maximum range.
|
// do not play nicely with the theoretical maximum range.
|
||||||
// Using a value one lower from the maximum emulates real stick behavior.
|
// Using a value one lower from the maximum emulates real stick behavior.
|
||||||
static constexpr float MAX_RANGE = 32766.0f / 32767.0f;
|
static constexpr float MAX_RANGE = 32766.0f / 32767.0f;
|
||||||
static constexpr float TAU = Common::PI * 2.0f;
|
|
||||||
// Use wider angle to ease the transition.
|
// Use wider angle to ease the transition.
|
||||||
static constexpr float APERTURE = TAU * 0.15f;
|
static constexpr float APERTURE = float((std::numbers::pi_v<float> / 2.f)) * 0.15f;
|
||||||
|
|
||||||
using Button = std::unique_ptr<Common::Input::InputDevice>;
|
using Button = std::unique_ptr<Common::Input::InputDevice>;
|
||||||
|
|
||||||
@@ -66,13 +69,13 @@ public:
|
|||||||
bool IsAngleGreater(float old_angle, float new_angle) const {
|
bool IsAngleGreater(float old_angle, float new_angle) const {
|
||||||
const float top_limit = new_angle + APERTURE;
|
const float top_limit = new_angle + APERTURE;
|
||||||
return (old_angle > new_angle && old_angle <= top_limit) ||
|
return (old_angle > new_angle && old_angle <= top_limit) ||
|
||||||
(old_angle + TAU > new_angle && old_angle + TAU <= top_limit);
|
(old_angle + f32((std::numbers::pi_v<float> / 2.f)) > new_angle && old_angle + f32((std::numbers::pi_v<float> / 2.f)) <= top_limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsAngleSmaller(float old_angle, float new_angle) const {
|
bool IsAngleSmaller(float old_angle, float new_angle) const {
|
||||||
const float bottom_limit = new_angle - APERTURE;
|
const float bottom_limit = new_angle - APERTURE;
|
||||||
return (old_angle >= bottom_limit && old_angle < new_angle) ||
|
return (old_angle >= bottom_limit && old_angle < new_angle) ||
|
||||||
(old_angle - TAU >= bottom_limit && old_angle - TAU < new_angle);
|
(old_angle - f32((std::numbers::pi_v<float> / 2.f)) >= bottom_limit && old_angle - f32((std::numbers::pi_v<float> / 2.f)) < new_angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetAngle(std::chrono::time_point<std::chrono::steady_clock> now) const {
|
float GetAngle(std::chrono::time_point<std::chrono::steady_clock> now) const {
|
||||||
@@ -87,16 +90,16 @@ public:
|
|||||||
|
|
||||||
if (IsAngleGreater(new_angle, goal_angle)) {
|
if (IsAngleGreater(new_angle, goal_angle)) {
|
||||||
new_angle -= modifier_angle * time_difference;
|
new_angle -= modifier_angle * time_difference;
|
||||||
if (new_angle < 0) {
|
if (new_angle < 0.f) {
|
||||||
new_angle += TAU;
|
new_angle += f32((std::numbers::pi_v<float> / 2.f));
|
||||||
}
|
}
|
||||||
if (!IsAngleGreater(new_angle, goal_angle)) {
|
if (!IsAngleGreater(new_angle, goal_angle)) {
|
||||||
return goal_angle;
|
return goal_angle;
|
||||||
}
|
}
|
||||||
} else if (IsAngleSmaller(new_angle, goal_angle)) {
|
} else if (IsAngleSmaller(new_angle, goal_angle)) {
|
||||||
new_angle += modifier_angle * time_difference;
|
new_angle += modifier_angle * time_difference;
|
||||||
if (new_angle >= TAU) {
|
if (new_angle >= f32((std::numbers::pi_v<float> / 2.f))) {
|
||||||
new_angle -= TAU;
|
new_angle -= f32((std::numbers::pi_v<float> / 2.f));
|
||||||
}
|
}
|
||||||
if (!IsAngleSmaller(new_angle, goal_angle)) {
|
if (!IsAngleSmaller(new_angle, goal_angle)) {
|
||||||
return goal_angle;
|
return goal_angle;
|
||||||
@@ -108,45 +111,14 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SetGoalAngle(bool r, bool l, bool u, bool d) {
|
void SetGoalAngle(bool r, bool l, bool u, bool d) {
|
||||||
// Move to the right
|
if (r && !u && !d) goal_angle = f32(std::numbers::pi_v<float>) * 0.00f; //right
|
||||||
if (r && !u && !d) {
|
if (r && u && !d) goal_angle = f32(std::numbers::pi_v<float>) * 0.25f; //upper right
|
||||||
goal_angle = 0.0f;
|
if (u && !l && !r) goal_angle = f32(std::numbers::pi_v<float>) * 0.50f; //up
|
||||||
}
|
if (l && u && !d) goal_angle = f32(std::numbers::pi_v<float>) * 0.75f; //upper left
|
||||||
|
if (l && !u && !d) goal_angle = f32(std::numbers::pi_v<float>) * 1.00f; //left
|
||||||
// Move to the upper right
|
if (l && !u && d) goal_angle = f32(std::numbers::pi_v<float>) * 1.25f; //bottom left
|
||||||
if (r && u && !d) {
|
if (d && !l && !r) goal_angle = f32(std::numbers::pi_v<float>) * 1.50f; //down
|
||||||
goal_angle = Common::PI * 0.25f;
|
if (r && !u && d) goal_angle = f32(std::numbers::pi_v<float>) * 1.75f; //bottom right
|
||||||
}
|
|
||||||
|
|
||||||
// Move up
|
|
||||||
if (u && !l && !r) {
|
|
||||||
goal_angle = Common::PI * 0.5f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move to the upper left
|
|
||||||
if (l && u && !d) {
|
|
||||||
goal_angle = Common::PI * 0.75f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move to the left
|
|
||||||
if (l && !u && !d) {
|
|
||||||
goal_angle = Common::PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move to the bottom left
|
|
||||||
if (l && !u && d) {
|
|
||||||
goal_angle = Common::PI * 1.25f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move down
|
|
||||||
if (d && !l && !r) {
|
|
||||||
goal_angle = Common::PI * 1.5f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move to the bottom right
|
|
||||||
if (r && !u && d) {
|
|
||||||
goal_angle = Common::PI * 1.75f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateUpButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
void UpdateUpButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
||||||
|
|||||||
@@ -1612,7 +1612,7 @@ void PlayerControlPreview::DrawGCBody(QPainter& p, const QPointF center) {
|
|||||||
std::array<QPointF, gc_body.size()> qbody;
|
std::array<QPointF, gc_body.size()> qbody;
|
||||||
std::array<QPointF, 8> left_hex;
|
std::array<QPointF, 8> left_hex;
|
||||||
std::array<QPointF, 8> right_hex;
|
std::array<QPointF, 8> right_hex;
|
||||||
constexpr float angle = 2 * 3.1415f / 8;
|
constexpr float angle = 2.f * float(M_PI) / 8.f;
|
||||||
|
|
||||||
for (std::size_t point = 0; point < gc_left_body.size() / 2; ++point) {
|
for (std::size_t point = 0; point < gc_left_body.size() / 2; ++point) {
|
||||||
const float body_x = gc_left_body[point * 2 + 0];
|
const float body_x = gc_left_body[point * 2 + 0];
|
||||||
|
|||||||
Reference in New Issue
Block a user