Implement controller gyroscope in SDL

This commit is contained in:
wheremyfoodat 2024-08-14 22:35:02 +03:00
parent 88e0782f71
commit d208c24c0c
6 changed files with 54 additions and 1 deletions

View file

@ -37,4 +37,6 @@ class FrontendSDL {
// And so the user can still use the keyboard to control the analog
bool keyboardAnalogX = false;
bool keyboardAnalogY = false;
void setupControllerSensors(SDL_GameController* controller);
};

20
include/sdl_gyro.hpp Normal file
View file

@ -0,0 +1,20 @@
#pragma once
#include <glm/glm.hpp>
#include <numbers>
#include "services/hid.hpp"
namespace Gyro::SDL {
// Convert the rotation data we get from SDL sensor events to rotation data we can feed right to HID
// Returns [pitch, roll, yaw]
static glm::vec3 convertRotation(glm::vec3 rotation) {
// Flip axes
glm::vec3 ret = -rotation;
// Convert from radians/s to deg/s and scale by the gyroscope coefficient from the HID service
ret *= 180.f / std::numbers::pi;
ret *= HIDService::gyroscopeCoeff;
return ret;
}
} // namespace Gyro::SDL

View file

@ -88,6 +88,8 @@ class HIDService {
}
public:
static constexpr float gyroscopeCoeff = 14.375f; // Same as retail 3DS
HIDService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {}
void reset();
void handleSyncRequest(u32 messagePointer);