mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2025-06-15 01:57:58 -05:00
core: hid: Restore motion state on refresh and clamp motion values
This commit is contained in:
@ -10,6 +10,8 @@ MotionInput::MotionInput() {
|
||||
// Initialize PID constants with default values
|
||||
SetPID(0.3f, 0.005f, 0.0f);
|
||||
SetGyroThreshold(ThresholdStandard);
|
||||
ResetQuaternion();
|
||||
ResetRotations();
|
||||
}
|
||||
|
||||
void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) {
|
||||
@ -20,11 +22,19 @@ void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) {
|
||||
|
||||
void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) {
|
||||
accel = acceleration;
|
||||
|
||||
accel.x = std::clamp(accel.x, -AccelMaxValue, AccelMaxValue);
|
||||
accel.y = std::clamp(accel.y, -AccelMaxValue, AccelMaxValue);
|
||||
accel.z = std::clamp(accel.z, -AccelMaxValue, AccelMaxValue);
|
||||
}
|
||||
|
||||
void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) {
|
||||
gyro = gyroscope - gyro_bias;
|
||||
|
||||
gyro.x = std::clamp(gyro.x, -GyroMaxValue, GyroMaxValue);
|
||||
gyro.y = std::clamp(gyro.y, -GyroMaxValue, GyroMaxValue);
|
||||
gyro.z = std::clamp(gyro.z, -GyroMaxValue, GyroMaxValue);
|
||||
|
||||
// Auto adjust drift to minimize drift
|
||||
if (!IsMoving(IsAtRestRelaxed)) {
|
||||
gyro_bias = (gyro_bias * 0.9999f) + (gyroscope * 0.0001f);
|
||||
@ -61,6 +71,10 @@ void MotionInput::ResetRotations() {
|
||||
rotations = {};
|
||||
}
|
||||
|
||||
void MotionInput::ResetQuaternion() {
|
||||
quat = {{0.0f, 0.0f, -1.0f}, 0.0f};
|
||||
}
|
||||
|
||||
bool MotionInput::IsMoving(f32 sensitivity) const {
|
||||
return gyro.Length() >= sensitivity || accel.Length() <= 0.9f || accel.Length() >= 1.1f;
|
||||
}
|
||||
|
Reference in New Issue
Block a user