From 3b004e7a4b9810447e2dc936c18c1ad08e8f6295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 27 Sep 2023 11:29:42 +0200 Subject: [PATCH] Remove the last use of accelerometer axis events (calibration) --- Core/TiltEventProcessor.cpp | 7 +++++++ Core/TiltEventProcessor.h | 4 ++++ UI/TiltAnalogSettingsScreen.cpp | 16 +--------------- UI/TiltAnalogSettingsScreen.h | 1 - 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Core/TiltEventProcessor.cpp b/Core/TiltEventProcessor.cpp index 14486e84bd..571f58f84f 100644 --- a/Core/TiltEventProcessor.cpp +++ b/Core/TiltEventProcessor.cpp @@ -19,6 +19,12 @@ static u32 tiltButtonsDown = 0; float rawTiltAnalogX; float rawTiltAnalogY; +float g_currentYAngle = 0.0f; + +float GetCurrentYAngle() { + return g_currentYAngle; +} + // These functions generate tilt events given the current Tilt amount, // and the deadzone radius. void GenerateAnalogStickEvent(float analogX, float analogY); @@ -73,6 +79,7 @@ void ProcessTilt(bool landscape, float calibrationAngle, float x, float y, float Lin::Vec3 down = Lin::Vec3(x, y, z).normalized(); float angleAroundX = atan2(down.z, down.y); + g_currentYAngle = angleAroundX; // TODO: Should smooth this out over time a bit. float yAngle = angleAroundX - calibrationAngle; float xAngle = asinf(down.x); diff --git a/Core/TiltEventProcessor.h b/Core/TiltEventProcessor.h index 3eda969e17..d16f0020d6 100644 --- a/Core/TiltEventProcessor.h +++ b/Core/TiltEventProcessor.h @@ -1,5 +1,7 @@ #pragma once +#include "Common/Math/lin/vec3.h" + namespace TiltEventProcessor { // generates a tilt in the correct coordinate system based on @@ -7,6 +9,8 @@ namespace TiltEventProcessor { void ProcessTilt(bool landscape, const float calibrationAngle, float x, float y, float z, bool invertX, bool invertY, float xSensitivity, float ySensitivity); void ResetTiltEvents(); +float GetCurrentYAngle(); + // Lets you preview the amount of tilt in TiltAnalogSettingsScreen. extern float rawTiltAnalogX; extern float rawTiltAnalogY; diff --git a/UI/TiltAnalogSettingsScreen.cpp b/UI/TiltAnalogSettingsScreen.cpp index 716baf5289..af4456a545 100644 --- a/UI/TiltAnalogSettingsScreen.cpp +++ b/UI/TiltAnalogSettingsScreen.cpp @@ -137,22 +137,8 @@ void TiltAnalogSettingsScreen::CreateViews() { settings->Add(new Choice(di->T("Back")))->OnClick.Handle(this, &UIScreen::OnBack); } -void TiltAnalogSettingsScreen::axis(const AxisInput &axis) { - UIDialogScreenWithGameBackground::axis(axis); - - if (axis.deviceId == DEVICE_ID_ACCELEROMETER) { - switch (axis.axisId) { - case JOYSTICK_AXIS_ACCELEROMETER_X: down_.x = axis.value; break; - case JOYSTICK_AXIS_ACCELEROMETER_Y: down_.y = axis.value; break; - case JOYSTICK_AXIS_ACCELEROMETER_Z: down_.z = axis.value; break; - default: break; - } - } -} - UI::EventReturn TiltAnalogSettingsScreen::OnCalibrate(UI::EventParams &e) { - Lin::Vec3 down = down_.normalized(); - g_Config.fTiltBaseAngleY = atan2(down.z, down.x); + g_Config.fTiltBaseAngleY = TiltEventProcessor::GetCurrentYAngle(); return UI::EVENT_DONE; } diff --git a/UI/TiltAnalogSettingsScreen.h b/UI/TiltAnalogSettingsScreen.h index 1c338e5e94..b1416cfb69 100644 --- a/UI/TiltAnalogSettingsScreen.h +++ b/UI/TiltAnalogSettingsScreen.h @@ -29,7 +29,6 @@ public: TiltAnalogSettingsScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {} void CreateViews() override; - void axis(const AxisInput &axis) override; void update() override; const char *tag() const override { return "TiltAnalogSettings"; }