mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-03 12:27:21 +12:00
Implement controller gyroscope in SDL
This commit is contained in:
parent
88e0782f71
commit
d208c24c0c
6 changed files with 54 additions and 1 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue