Implement controller gyroscope in SDL
This commit is contained in:
@@ -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
20
include/sdl_gyro.hpp
Normal 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
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user