Merge pull request #10167 from german77/motion_preview
yuzu: Add motion preview to controller input
This commit is contained in:
commit
9c9b4616c3
12 changed files with 165 additions and 6 deletions
|
@ -376,6 +376,7 @@ void EmulatedController::ReloadInput() {
|
|||
motion.accel = emulated_motion.GetAcceleration();
|
||||
motion.gyro = emulated_motion.GetGyroscope();
|
||||
motion.rotation = emulated_motion.GetRotations();
|
||||
motion.euler = emulated_motion.GetEulerAngles();
|
||||
motion.orientation = emulated_motion.GetOrientation();
|
||||
motion.is_at_rest = !emulated_motion.IsMoving(motion_sensitivity);
|
||||
}
|
||||
|
@ -980,14 +981,11 @@ void EmulatedController::SetMotion(const Common::Input::CallbackStatus& callback
|
|||
emulated.UpdateOrientation(raw_status.delta_timestamp);
|
||||
force_update_motion = raw_status.force_update;
|
||||
|
||||
if (is_configuring) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& motion = controller.motion_state[index];
|
||||
motion.accel = emulated.GetAcceleration();
|
||||
motion.gyro = emulated.GetGyroscope();
|
||||
motion.rotation = emulated.GetRotations();
|
||||
motion.euler = emulated.GetEulerAngles();
|
||||
motion.orientation = emulated.GetOrientation();
|
||||
motion.is_at_rest = !emulated.IsMoving(motion_sensitivity);
|
||||
}
|
||||
|
|
|
@ -106,6 +106,7 @@ struct ControllerMotion {
|
|||
Common::Vec3f accel{};
|
||||
Common::Vec3f gyro{};
|
||||
Common::Vec3f rotation{};
|
||||
Common::Vec3f euler{};
|
||||
std::array<Common::Vec3f, 3> orientation{};
|
||||
bool is_at_rest{};
|
||||
};
|
||||
|
|
|
@ -54,6 +54,7 @@ Common::Input::ButtonStatus TransformToButton(const Common::Input::CallbackStatu
|
|||
case Common::Input::InputType::Analog:
|
||||
status.value = TransformToTrigger(callback).pressed.value;
|
||||
status.toggle = callback.analog_status.properties.toggle;
|
||||
status.inverted = callback.analog_status.properties.inverted_button;
|
||||
break;
|
||||
case Common::Input::InputType::Trigger:
|
||||
status.value = TransformToTrigger(callback).pressed.value;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "common/math_util.h"
|
||||
#include "core/hid/motion_input.h"
|
||||
|
||||
|
@ -51,6 +53,20 @@ void MotionInput::SetQuaternion(const Common::Quaternion<f32>& quaternion) {
|
|||
quat = quaternion;
|
||||
}
|
||||
|
||||
void MotionInput::SetEulerAngles(const Common::Vec3f& euler_angles) {
|
||||
const float cr = std::cos(euler_angles.x * 0.5f);
|
||||
const float sr = std::sin(euler_angles.x * 0.5f);
|
||||
const float cp = std::cos(euler_angles.y * 0.5f);
|
||||
const float sp = std::sin(euler_angles.y * 0.5f);
|
||||
const float cy = std::cos(euler_angles.z * 0.5f);
|
||||
const float sy = std::sin(euler_angles.z * 0.5f);
|
||||
|
||||
quat.w = cr * cp * cy + sr * sp * sy;
|
||||
quat.xyz.x = sr * cp * cy - cr * sp * sy;
|
||||
quat.xyz.y = cr * sp * cy + sr * cp * sy;
|
||||
quat.xyz.z = cr * cp * sy - sr * sp * cy;
|
||||
}
|
||||
|
||||
void MotionInput::SetGyroBias(const Common::Vec3f& bias) {
|
||||
gyro_bias = bias;
|
||||
}
|
||||
|
@ -222,6 +238,26 @@ Common::Vec3f MotionInput::GetRotations() const {
|
|||
return rotations;
|
||||
}
|
||||
|
||||
Common::Vec3f MotionInput::GetEulerAngles() const {
|
||||
// roll (x-axis rotation)
|
||||
const float sinr_cosp = 2 * (quat.w * quat.xyz.x + quat.xyz.y * quat.xyz.z);
|
||||
const float cosr_cosp = 1 - 2 * (quat.xyz.x * quat.xyz.x + quat.xyz.y * quat.xyz.y);
|
||||
|
||||
// pitch (y-axis rotation)
|
||||
const float sinp = std::sqrt(1 + 2 * (quat.w * quat.xyz.y - quat.xyz.x * quat.xyz.z));
|
||||
const float cosp = std::sqrt(1 - 2 * (quat.w * quat.xyz.y - quat.xyz.x * quat.xyz.z));
|
||||
|
||||
// yaw (z-axis rotation)
|
||||
const float siny_cosp = 2 * (quat.w * quat.xyz.z + quat.xyz.x * quat.xyz.y);
|
||||
const float cosy_cosp = 1 - 2 * (quat.xyz.y * quat.xyz.y + quat.xyz.z * quat.xyz.z);
|
||||
|
||||
return {
|
||||
std::atan2(sinr_cosp, cosr_cosp),
|
||||
2 * std::atan2(sinp, cosp) - Common::PI / 2,
|
||||
std::atan2(siny_cosp, cosy_cosp),
|
||||
};
|
||||
}
|
||||
|
||||
void MotionInput::ResetOrientation() {
|
||||
if (!reset_enabled || only_accelerometer) {
|
||||
return;
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
void SetAcceleration(const Common::Vec3f& acceleration);
|
||||
void SetGyroscope(const Common::Vec3f& gyroscope);
|
||||
void SetQuaternion(const Common::Quaternion<f32>& quaternion);
|
||||
void SetEulerAngles(const Common::Vec3f& euler_angles);
|
||||
void SetGyroBias(const Common::Vec3f& bias);
|
||||
void SetGyroThreshold(f32 threshold);
|
||||
|
||||
|
@ -54,6 +55,7 @@ public:
|
|||
[[nodiscard]] Common::Vec3f GetGyroBias() const;
|
||||
[[nodiscard]] Common::Vec3f GetRotations() const;
|
||||
[[nodiscard]] Common::Quaternion<f32> GetQuaternion() const;
|
||||
[[nodiscard]] Common::Vec3f GetEulerAngles() const;
|
||||
|
||||
[[nodiscard]] bool IsMoving(f32 sensitivity) const;
|
||||
[[nodiscard]] bool IsCalibrated(f32 sensitivity) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue