diff options
| -rw-r--r-- | src/common/input.h | 2 | ||||
| -rw-r--r-- | src/common/vector_math.h | 14 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 6 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 1 | ||||
| -rw-r--r-- | src/core/hid/input_converter.cpp | 1 | ||||
| -rw-r--r-- | src/core/hid/motion_input.cpp | 36 | ||||
| -rw-r--r-- | src/core/hid/motion_input.h | 2 | ||||
| -rw-r--r-- | src/input_common/input_engine.cpp | 2 | ||||
| -rw-r--r-- | src/input_common/input_poller.cpp | 1 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 10 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player_widget.cpp | 91 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player_widget.h | 5 |
12 files changed, 165 insertions, 6 deletions
diff --git a/src/common/input.h b/src/common/input.h index 51b277c1f..66fb15f0a 100644 --- a/src/common/input.h +++ b/src/common/input.h | |||
| @@ -111,6 +111,8 @@ struct AnalogProperties { | |||
| 111 | float offset{}; | 111 | float offset{}; |
| 112 | // Invert direction of the sensor data | 112 | // Invert direction of the sensor data |
| 113 | bool inverted{}; | 113 | bool inverted{}; |
| 114 | // Invert the state if it's converted to a button | ||
| 115 | bool inverted_button{}; | ||
| 114 | // Press once to activate, press again to release | 116 | // Press once to activate, press again to release |
| 115 | bool toggle{}; | 117 | bool toggle{}; |
| 116 | }; | 118 | }; |
diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 0e2095c45..b4885835d 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h | |||
| @@ -259,6 +259,20 @@ public: | |||
| 259 | return *this; | 259 | return *this; |
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | void RotateFromOrigin(float roll, float pitch, float yaw) { | ||
| 263 | float temp = y; | ||
| 264 | y = std::cos(roll) * y - std::sin(roll) * z; | ||
| 265 | z = std::sin(roll) * temp + std::cos(roll) * z; | ||
| 266 | |||
| 267 | temp = x; | ||
| 268 | x = std::cos(pitch) * x + std::sin(pitch) * z; | ||
| 269 | z = -std::sin(pitch) * temp + std::cos(pitch) * z; | ||
| 270 | |||
| 271 | temp = x; | ||
| 272 | x = std::cos(yaw) * x - std::sin(yaw) * y; | ||
| 273 | y = std::sin(yaw) * temp + std::cos(yaw) * y; | ||
| 274 | } | ||
| 275 | |||
| 262 | [[nodiscard]] constexpr T Length2() const { | 276 | [[nodiscard]] constexpr T Length2() const { |
| 263 | return x * x + y * y + z * z; | 277 | return x * x + y * y + z * z; |
| 264 | } | 278 | } |
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index db71f1c19..ecab85893 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -376,6 +376,7 @@ void EmulatedController::ReloadInput() { | |||
| 376 | motion.accel = emulated_motion.GetAcceleration(); | 376 | motion.accel = emulated_motion.GetAcceleration(); |
| 377 | motion.gyro = emulated_motion.GetGyroscope(); | 377 | motion.gyro = emulated_motion.GetGyroscope(); |
| 378 | motion.rotation = emulated_motion.GetRotations(); | 378 | motion.rotation = emulated_motion.GetRotations(); |
| 379 | motion.euler = emulated_motion.GetEulerAngles(); | ||
| 379 | motion.orientation = emulated_motion.GetOrientation(); | 380 | motion.orientation = emulated_motion.GetOrientation(); |
| 380 | motion.is_at_rest = !emulated_motion.IsMoving(motion_sensitivity); | 381 | motion.is_at_rest = !emulated_motion.IsMoving(motion_sensitivity); |
| 381 | } | 382 | } |
| @@ -980,14 +981,11 @@ void EmulatedController::SetMotion(const Common::Input::CallbackStatus& callback | |||
| 980 | emulated.UpdateOrientation(raw_status.delta_timestamp); | 981 | emulated.UpdateOrientation(raw_status.delta_timestamp); |
| 981 | force_update_motion = raw_status.force_update; | 982 | force_update_motion = raw_status.force_update; |
| 982 | 983 | ||
| 983 | if (is_configuring) { | ||
| 984 | return; | ||
| 985 | } | ||
| 986 | |||
| 987 | auto& motion = controller.motion_state[index]; | 984 | auto& motion = controller.motion_state[index]; |
| 988 | motion.accel = emulated.GetAcceleration(); | 985 | motion.accel = emulated.GetAcceleration(); |
| 989 | motion.gyro = emulated.GetGyroscope(); | 986 | motion.gyro = emulated.GetGyroscope(); |
| 990 | motion.rotation = emulated.GetRotations(); | 987 | motion.rotation = emulated.GetRotations(); |
| 988 | motion.euler = emulated.GetEulerAngles(); | ||
| 991 | motion.orientation = emulated.GetOrientation(); | 989 | motion.orientation = emulated.GetOrientation(); |
| 992 | motion.is_at_rest = !emulated.IsMoving(motion_sensitivity); | 990 | motion.is_at_rest = !emulated.IsMoving(motion_sensitivity); |
| 993 | } | 991 | } |
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index 429655355..6e01f4e12 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -106,6 +106,7 @@ struct ControllerMotion { | |||
| 106 | Common::Vec3f accel{}; | 106 | Common::Vec3f accel{}; |
| 107 | Common::Vec3f gyro{}; | 107 | Common::Vec3f gyro{}; |
| 108 | Common::Vec3f rotation{}; | 108 | Common::Vec3f rotation{}; |
| 109 | Common::Vec3f euler{}; | ||
| 109 | std::array<Common::Vec3f, 3> orientation{}; | 110 | std::array<Common::Vec3f, 3> orientation{}; |
| 110 | bool is_at_rest{}; | 111 | bool is_at_rest{}; |
| 111 | }; | 112 | }; |
diff --git a/src/core/hid/input_converter.cpp b/src/core/hid/input_converter.cpp index 7cee39a53..a38e3bb3f 100644 --- a/src/core/hid/input_converter.cpp +++ b/src/core/hid/input_converter.cpp | |||
| @@ -54,6 +54,7 @@ Common::Input::ButtonStatus TransformToButton(const Common::Input::CallbackStatu | |||
| 54 | case Common::Input::InputType::Analog: | 54 | case Common::Input::InputType::Analog: |
| 55 | status.value = TransformToTrigger(callback).pressed.value; | 55 | status.value = TransformToTrigger(callback).pressed.value; |
| 56 | status.toggle = callback.analog_status.properties.toggle; | 56 | status.toggle = callback.analog_status.properties.toggle; |
| 57 | status.inverted = callback.analog_status.properties.inverted_button; | ||
| 57 | break; | 58 | break; |
| 58 | case Common::Input::InputType::Trigger: | 59 | case Common::Input::InputType::Trigger: |
| 59 | status.value = TransformToTrigger(callback).pressed.value; | 60 | status.value = TransformToTrigger(callback).pressed.value; |
diff --git a/src/core/hid/motion_input.cpp b/src/core/hid/motion_input.cpp index 0dd66c1cc..b60478dbb 100644 --- a/src/core/hid/motion_input.cpp +++ b/src/core/hid/motion_input.cpp | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include <cmath> | ||
| 5 | |||
| 4 | #include "common/math_util.h" | 6 | #include "common/math_util.h" |
| 5 | #include "core/hid/motion_input.h" | 7 | #include "core/hid/motion_input.h" |
| 6 | 8 | ||
| @@ -51,6 +53,20 @@ void MotionInput::SetQuaternion(const Common::Quaternion<f32>& quaternion) { | |||
| 51 | quat = quaternion; | 53 | quat = quaternion; |
| 52 | } | 54 | } |
| 53 | 55 | ||
| 56 | void MotionInput::SetEulerAngles(const Common::Vec3f& euler_angles) { | ||
| 57 | const float cr = std::cos(euler_angles.x * 0.5f); | ||
| 58 | const float sr = std::sin(euler_angles.x * 0.5f); | ||
| 59 | const float cp = std::cos(euler_angles.y * 0.5f); | ||
| 60 | const float sp = std::sin(euler_angles.y * 0.5f); | ||
| 61 | const float cy = std::cos(euler_angles.z * 0.5f); | ||
| 62 | const float sy = std::sin(euler_angles.z * 0.5f); | ||
| 63 | |||
| 64 | quat.w = cr * cp * cy + sr * sp * sy; | ||
| 65 | quat.xyz.x = sr * cp * cy - cr * sp * sy; | ||
| 66 | quat.xyz.y = cr * sp * cy + sr * cp * sy; | ||
| 67 | quat.xyz.z = cr * cp * sy - sr * sp * cy; | ||
| 68 | } | ||
| 69 | |||
| 54 | void MotionInput::SetGyroBias(const Common::Vec3f& bias) { | 70 | void MotionInput::SetGyroBias(const Common::Vec3f& bias) { |
| 55 | gyro_bias = bias; | 71 | gyro_bias = bias; |
| 56 | } | 72 | } |
| @@ -222,6 +238,26 @@ Common::Vec3f MotionInput::GetRotations() const { | |||
| 222 | return rotations; | 238 | return rotations; |
| 223 | } | 239 | } |
| 224 | 240 | ||
| 241 | Common::Vec3f MotionInput::GetEulerAngles() const { | ||
| 242 | // roll (x-axis rotation) | ||
| 243 | const float sinr_cosp = 2 * (quat.w * quat.xyz.x + quat.xyz.y * quat.xyz.z); | ||
| 244 | const float cosr_cosp = 1 - 2 * (quat.xyz.x * quat.xyz.x + quat.xyz.y * quat.xyz.y); | ||
| 245 | |||
| 246 | // pitch (y-axis rotation) | ||
| 247 | const float sinp = std::sqrt(1 + 2 * (quat.w * quat.xyz.y - quat.xyz.x * quat.xyz.z)); | ||
| 248 | const float cosp = std::sqrt(1 - 2 * (quat.w * quat.xyz.y - quat.xyz.x * quat.xyz.z)); | ||
| 249 | |||
| 250 | // yaw (z-axis rotation) | ||
| 251 | const float siny_cosp = 2 * (quat.w * quat.xyz.z + quat.xyz.x * quat.xyz.y); | ||
| 252 | const float cosy_cosp = 1 - 2 * (quat.xyz.y * quat.xyz.y + quat.xyz.z * quat.xyz.z); | ||
| 253 | |||
| 254 | return { | ||
| 255 | std::atan2(sinr_cosp, cosr_cosp), | ||
| 256 | 2 * std::atan2(sinp, cosp) - Common::PI / 2, | ||
| 257 | std::atan2(siny_cosp, cosy_cosp), | ||
| 258 | }; | ||
| 259 | } | ||
| 260 | |||
| 225 | void MotionInput::ResetOrientation() { | 261 | void MotionInput::ResetOrientation() { |
| 226 | if (!reset_enabled || only_accelerometer) { | 262 | if (!reset_enabled || only_accelerometer) { |
| 227 | return; | 263 | return; |
diff --git a/src/core/hid/motion_input.h b/src/core/hid/motion_input.h index 9f3fc1cf7..482719359 100644 --- a/src/core/hid/motion_input.h +++ b/src/core/hid/motion_input.h | |||
| @@ -35,6 +35,7 @@ public: | |||
| 35 | void SetAcceleration(const Common::Vec3f& acceleration); | 35 | void SetAcceleration(const Common::Vec3f& acceleration); |
| 36 | void SetGyroscope(const Common::Vec3f& gyroscope); | 36 | void SetGyroscope(const Common::Vec3f& gyroscope); |
| 37 | void SetQuaternion(const Common::Quaternion<f32>& quaternion); | 37 | void SetQuaternion(const Common::Quaternion<f32>& quaternion); |
| 38 | void SetEulerAngles(const Common::Vec3f& euler_angles); | ||
| 38 | void SetGyroBias(const Common::Vec3f& bias); | 39 | void SetGyroBias(const Common::Vec3f& bias); |
| 39 | void SetGyroThreshold(f32 threshold); | 40 | void SetGyroThreshold(f32 threshold); |
| 40 | 41 | ||
| @@ -54,6 +55,7 @@ public: | |||
| 54 | [[nodiscard]] Common::Vec3f GetGyroBias() const; | 55 | [[nodiscard]] Common::Vec3f GetGyroBias() const; |
| 55 | [[nodiscard]] Common::Vec3f GetRotations() const; | 56 | [[nodiscard]] Common::Vec3f GetRotations() const; |
| 56 | [[nodiscard]] Common::Quaternion<f32> GetQuaternion() const; | 57 | [[nodiscard]] Common::Quaternion<f32> GetQuaternion() const; |
| 58 | [[nodiscard]] Common::Vec3f GetEulerAngles() const; | ||
| 57 | 59 | ||
| 58 | [[nodiscard]] bool IsMoving(f32 sensitivity) const; | 60 | [[nodiscard]] bool IsMoving(f32 sensitivity) const; |
| 59 | [[nodiscard]] bool IsCalibrated(f32 sensitivity) const; | 61 | [[nodiscard]] bool IsCalibrated(f32 sensitivity) const; |
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp index 91aa96aa7..49f5e7f54 100644 --- a/src/input_common/input_engine.cpp +++ b/src/input_common/input_engine.cpp | |||
| @@ -58,6 +58,8 @@ void InputEngine::SetHatButton(const PadIdentifier& identifier, int button, u8 v | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | void InputEngine::SetAxis(const PadIdentifier& identifier, int axis, f32 value) { | 60 | void InputEngine::SetAxis(const PadIdentifier& identifier, int axis, f32 value) { |
| 61 | value /= 2.0f; | ||
| 62 | value -= 0.5f; | ||
| 61 | { | 63 | { |
| 62 | std::scoped_lock lock{mutex}; | 64 | std::scoped_lock lock{mutex}; |
| 63 | ControllerData& controller = controller_list.at(identifier); | 65 | ControllerData& controller = controller_list.at(identifier); |
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 8c6a6521a..5c2c4a463 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -939,6 +939,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateAnalogDevice( | |||
| 939 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), | 939 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), |
| 940 | .offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f), | 940 | .offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f), |
| 941 | .inverted = params.Get("invert", "+") == "-", | 941 | .inverted = params.Get("invert", "+") == "-", |
| 942 | .inverted_button = params.Get("inverted", false) != 0, | ||
| 942 | .toggle = params.Get("toggle", false) != 0, | 943 | .toggle = params.Get("toggle", false) != 0, |
| 943 | }; | 944 | }; |
| 944 | input_engine->PreSetController(identifier); | 945 | input_engine->PreSetController(identifier); |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 50b62293e..54f42e0c9 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -206,7 +206,7 @@ QString ConfigureInputPlayer::ButtonToText(const Common::ParamPackage& param) { | |||
| 206 | } | 206 | } |
| 207 | if (param.Has("axis")) { | 207 | if (param.Has("axis")) { |
| 208 | const QString axis = QString::fromStdString(param.Get("axis", "")); | 208 | const QString axis = QString::fromStdString(param.Get("axis", "")); |
| 209 | return QObject::tr("%1%2Axis %3").arg(toggle, invert, axis); | 209 | return QObject::tr("%1%2%3Axis %4").arg(toggle, inverted, invert, axis); |
| 210 | } | 210 | } |
| 211 | if (param.Has("axis_x") && param.Has("axis_y") && param.Has("axis_z")) { | 211 | if (param.Has("axis_x") && param.Has("axis_y") && param.Has("axis_z")) { |
| 212 | const QString axis_x = QString::fromStdString(param.Get("axis_x", "")); | 212 | const QString axis_x = QString::fromStdString(param.Get("axis_x", "")); |
| @@ -229,7 +229,7 @@ QString ConfigureInputPlayer::ButtonToText(const Common::ParamPackage& param) { | |||
| 229 | return QObject::tr("%1%2%3Hat %4").arg(turbo, toggle, inverted, button_name); | 229 | return QObject::tr("%1%2%3Hat %4").arg(turbo, toggle, inverted, button_name); |
| 230 | } | 230 | } |
| 231 | if (param.Has("axis")) { | 231 | if (param.Has("axis")) { |
| 232 | return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name); | 232 | return QObject::tr("%1%2%3Axis %4").arg(toggle, inverted, invert, button_name); |
| 233 | } | 233 | } |
| 234 | if (param.Has("motion")) { | 234 | if (param.Has("motion")) { |
| 235 | return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name); | 235 | return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name); |
| @@ -410,6 +410,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 410 | button_map[button_id]->setText(ButtonToText(param)); | 410 | button_map[button_id]->setText(ButtonToText(param)); |
| 411 | emulated_controller->SetButtonParam(button_id, param); | 411 | emulated_controller->SetButtonParam(button_id, param); |
| 412 | }); | 412 | }); |
| 413 | context_menu.addAction(tr("Invert button"), [&] { | ||
| 414 | const bool invert_value = !param.Get("inverted", false); | ||
| 415 | param.Set("inverted", invert_value); | ||
| 416 | button_map[button_id]->setText(ButtonToText(param)); | ||
| 417 | emulated_controller->SetButtonParam(button_id, param); | ||
| 418 | }); | ||
| 413 | context_menu.addAction(tr("Set threshold"), [&] { | 419 | context_menu.addAction(tr("Set threshold"), [&] { |
| 414 | const int button_threshold = | 420 | const int button_threshold = |
| 415 | static_cast<int>(param.Get("threshold", 0.5f) * 100.0f); | 421 | static_cast<int>(param.Get("threshold", 0.5f) * 100.0f); |
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp index c287220fc..fe1ee2289 100644 --- a/src/yuzu/configuration/configure_input_player_widget.cpp +++ b/src/yuzu/configuration/configure_input_player_widget.cpp | |||
| @@ -180,6 +180,10 @@ void PlayerControlPreview::ControllerUpdate(Core::HID::ControllerTriggerType typ | |||
| 180 | battery_values = controller->GetBatteryValues(); | 180 | battery_values = controller->GetBatteryValues(); |
| 181 | needs_redraw = true; | 181 | needs_redraw = true; |
| 182 | break; | 182 | break; |
| 183 | case Core::HID::ControllerTriggerType::Motion: | ||
| 184 | motion_values = controller->GetMotions(); | ||
| 185 | needs_redraw = true; | ||
| 186 | break; | ||
| 183 | default: | 187 | default: |
| 184 | break; | 188 | break; |
| 185 | } | 189 | } |
| @@ -313,6 +317,15 @@ void PlayerControlPreview::DrawLeftController(QPainter& p, const QPointF center) | |||
| 313 | DrawRawJoystick(p, center + QPointF(-140, 90), QPointF(0, 0)); | 317 | DrawRawJoystick(p, center + QPointF(-140, 90), QPointF(0, 0)); |
| 314 | } | 318 | } |
| 315 | 319 | ||
| 320 | { | ||
| 321 | // Draw motion cubes | ||
| 322 | using namespace Settings::NativeMotion; | ||
| 323 | p.setPen(colors.outline); | ||
| 324 | p.setBrush(colors.transparent); | ||
| 325 | Draw3dCube(p, center + QPointF(-140, 90), | ||
| 326 | motion_values[Settings::NativeMotion::MotionLeft].euler, 20.0f); | ||
| 327 | } | ||
| 328 | |||
| 316 | using namespace Settings::NativeButton; | 329 | using namespace Settings::NativeButton; |
| 317 | 330 | ||
| 318 | // D-pad constants | 331 | // D-pad constants |
| @@ -435,6 +448,15 @@ void PlayerControlPreview::DrawRightController(QPainter& p, const QPointF center | |||
| 435 | DrawRawJoystick(p, QPointF(0, 0), center + QPointF(140, 90)); | 448 | DrawRawJoystick(p, QPointF(0, 0), center + QPointF(140, 90)); |
| 436 | } | 449 | } |
| 437 | 450 | ||
| 451 | { | ||
| 452 | // Draw motion cubes | ||
| 453 | using namespace Settings::NativeMotion; | ||
| 454 | p.setPen(colors.outline); | ||
| 455 | p.setBrush(colors.transparent); | ||
| 456 | Draw3dCube(p, center + QPointF(140, 90), | ||
| 457 | motion_values[Settings::NativeMotion::MotionRight].euler, 20.0f); | ||
| 458 | } | ||
| 459 | |||
| 438 | using namespace Settings::NativeButton; | 460 | using namespace Settings::NativeButton; |
| 439 | 461 | ||
| 440 | // Face buttons constants | 462 | // Face buttons constants |
| @@ -555,6 +577,17 @@ void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center) | |||
| 555 | DrawRawJoystick(p, center + QPointF(-180, 90), center + QPointF(180, 90)); | 577 | DrawRawJoystick(p, center + QPointF(-180, 90), center + QPointF(180, 90)); |
| 556 | } | 578 | } |
| 557 | 579 | ||
| 580 | { | ||
| 581 | // Draw motion cubes | ||
| 582 | using namespace Settings::NativeMotion; | ||
| 583 | p.setPen(colors.outline); | ||
| 584 | p.setBrush(colors.transparent); | ||
| 585 | Draw3dCube(p, center + QPointF(-180, -5), | ||
| 586 | motion_values[Settings::NativeMotion::MotionLeft].euler, 20.0f); | ||
| 587 | Draw3dCube(p, center + QPointF(180, -5), | ||
| 588 | motion_values[Settings::NativeMotion::MotionRight].euler, 20.0f); | ||
| 589 | } | ||
| 590 | |||
| 558 | using namespace Settings::NativeButton; | 591 | using namespace Settings::NativeButton; |
| 559 | 592 | ||
| 560 | // Face buttons constants | 593 | // Face buttons constants |
| @@ -647,6 +680,15 @@ void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF cen | |||
| 647 | DrawRawJoystick(p, center + QPointF(-50, 0), center + QPointF(50, 0)); | 680 | DrawRawJoystick(p, center + QPointF(-50, 0), center + QPointF(50, 0)); |
| 648 | } | 681 | } |
| 649 | 682 | ||
| 683 | { | ||
| 684 | // Draw motion cubes | ||
| 685 | using namespace Settings::NativeMotion; | ||
| 686 | p.setPen(colors.outline); | ||
| 687 | p.setBrush(colors.transparent); | ||
| 688 | Draw3dCube(p, center + QPointF(0, -115), | ||
| 689 | motion_values[Settings::NativeMotion::MotionLeft].euler, 15.0f); | ||
| 690 | } | ||
| 691 | |||
| 650 | using namespace Settings::NativeButton; | 692 | using namespace Settings::NativeButton; |
| 651 | 693 | ||
| 652 | // Face buttons constants | 694 | // Face buttons constants |
| @@ -750,6 +792,15 @@ void PlayerControlPreview::DrawProController(QPainter& p, const QPointF center) | |||
| 750 | DrawRawJoystick(p, center + QPointF(-50, 105), center + QPointF(50, 105)); | 792 | DrawRawJoystick(p, center + QPointF(-50, 105), center + QPointF(50, 105)); |
| 751 | } | 793 | } |
| 752 | 794 | ||
| 795 | { | ||
| 796 | // Draw motion cubes | ||
| 797 | using namespace Settings::NativeMotion; | ||
| 798 | p.setPen(colors.button); | ||
| 799 | p.setBrush(colors.transparent); | ||
| 800 | Draw3dCube(p, center + QPointF(0, -100), | ||
| 801 | motion_values[Settings::NativeMotion::MotionLeft].euler, 15.0f); | ||
| 802 | } | ||
| 803 | |||
| 753 | using namespace Settings::NativeButton; | 804 | using namespace Settings::NativeButton; |
| 754 | 805 | ||
| 755 | // Face buttons constants | 806 | // Face buttons constants |
| @@ -2871,6 +2922,46 @@ void PlayerControlPreview::DrawArrow(QPainter& p, const QPointF center, const Di | |||
| 2871 | DrawPolygon(p, arrow_symbol); | 2922 | DrawPolygon(p, arrow_symbol); |
| 2872 | } | 2923 | } |
| 2873 | 2924 | ||
| 2925 | // Draw motion functions | ||
| 2926 | void PlayerControlPreview::Draw3dCube(QPainter& p, QPointF center, const Common::Vec3f& euler, | ||
| 2927 | float size) { | ||
| 2928 | std::array<Common::Vec3f, 8> cube{ | ||
| 2929 | Common::Vec3f{-1, -1, -1}, | ||
| 2930 | {-1, 1, -1}, | ||
| 2931 | {1, 1, -1}, | ||
| 2932 | {1, -1, -1}, | ||
| 2933 | {-1, -1, 1}, | ||
| 2934 | {-1, 1, 1}, | ||
| 2935 | {1, 1, 1}, | ||
| 2936 | {1, -1, 1}, | ||
| 2937 | }; | ||
| 2938 | |||
| 2939 | for (Common::Vec3f& point : cube) { | ||
| 2940 | point.RotateFromOrigin(euler.x, euler.y, euler.z); | ||
| 2941 | point *= size; | ||
| 2942 | } | ||
| 2943 | |||
| 2944 | const std::array<QPointF, 4> front_face{ | ||
| 2945 | center + QPointF{cube[0].x, cube[0].y}, | ||
| 2946 | center + QPointF{cube[1].x, cube[1].y}, | ||
| 2947 | center + QPointF{cube[2].x, cube[2].y}, | ||
| 2948 | center + QPointF{cube[3].x, cube[3].y}, | ||
| 2949 | }; | ||
| 2950 | const std::array<QPointF, 4> back_face{ | ||
| 2951 | center + QPointF{cube[4].x, cube[4].y}, | ||
| 2952 | center + QPointF{cube[5].x, cube[5].y}, | ||
| 2953 | center + QPointF{cube[6].x, cube[6].y}, | ||
| 2954 | center + QPointF{cube[7].x, cube[7].y}, | ||
| 2955 | }; | ||
| 2956 | |||
| 2957 | DrawPolygon(p, front_face); | ||
| 2958 | DrawPolygon(p, back_face); | ||
| 2959 | p.drawLine(center + QPointF{cube[0].x, cube[0].y}, center + QPointF{cube[4].x, cube[4].y}); | ||
| 2960 | p.drawLine(center + QPointF{cube[1].x, cube[1].y}, center + QPointF{cube[5].x, cube[5].y}); | ||
| 2961 | p.drawLine(center + QPointF{cube[2].x, cube[2].y}, center + QPointF{cube[6].x, cube[6].y}); | ||
| 2962 | p.drawLine(center + QPointF{cube[3].x, cube[3].y}, center + QPointF{cube[7].x, cube[7].y}); | ||
| 2963 | } | ||
| 2964 | |||
| 2874 | template <size_t N> | 2965 | template <size_t N> |
| 2875 | void PlayerControlPreview::DrawPolygon(QPainter& p, const std::array<QPointF, N>& polygon) { | 2966 | void PlayerControlPreview::DrawPolygon(QPainter& p, const std::array<QPointF, N>& polygon) { |
| 2876 | p.drawPolygon(polygon.data(), static_cast<int>(polygon.size())); | 2967 | p.drawPolygon(polygon.data(), static_cast<int>(polygon.size())); |
diff --git a/src/yuzu/configuration/configure_input_player_widget.h b/src/yuzu/configuration/configure_input_player_widget.h index 267d134de..a16943c3c 100644 --- a/src/yuzu/configuration/configure_input_player_widget.h +++ b/src/yuzu/configuration/configure_input_player_widget.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | #include "common/input.h" | 10 | #include "common/input.h" |
| 11 | #include "common/settings_input.h" | 11 | #include "common/settings_input.h" |
| 12 | #include "common/vector_math.h" | ||
| 12 | #include "core/hid/emulated_controller.h" | 13 | #include "core/hid/emulated_controller.h" |
| 13 | #include "core/hid/hid_types.h" | 14 | #include "core/hid/hid_types.h" |
| 14 | 15 | ||
| @@ -193,6 +194,9 @@ private: | |||
| 193 | void DrawSymbol(QPainter& p, QPointF center, Symbol symbol, float icon_size); | 194 | void DrawSymbol(QPainter& p, QPointF center, Symbol symbol, float icon_size); |
| 194 | void DrawArrow(QPainter& p, QPointF center, Direction direction, float size); | 195 | void DrawArrow(QPainter& p, QPointF center, Direction direction, float size); |
| 195 | 196 | ||
| 197 | // Draw motion functions | ||
| 198 | void Draw3dCube(QPainter& p, QPointF center, const Common::Vec3f& euler, float size); | ||
| 199 | |||
| 196 | // Draw primitive types | 200 | // Draw primitive types |
| 197 | template <size_t N> | 201 | template <size_t N> |
| 198 | void DrawPolygon(QPainter& p, const std::array<QPointF, N>& polygon); | 202 | void DrawPolygon(QPainter& p, const std::array<QPointF, N>& polygon); |
| @@ -222,4 +226,5 @@ private: | |||
| 222 | Core::HID::SticksValues stick_values{}; | 226 | Core::HID::SticksValues stick_values{}; |
| 223 | Core::HID::TriggerValues trigger_values{}; | 227 | Core::HID::TriggerValues trigger_values{}; |
| 224 | Core::HID::BatteryValues battery_values{}; | 228 | Core::HID::BatteryValues battery_values{}; |
| 229 | Core::HID::MotionState motion_values{}; | ||
| 225 | }; | 230 | }; |