Improve accelerometer algorithm

This commit is contained in:
wheremyfoodat 2024-08-16 17:54:15 +03:00
parent c772b1c702
commit dbdf21b1ab
5 changed files with 39 additions and 24 deletions

View file

@ -2,7 +2,7 @@
#include <glad/gl.h>
#include "sdl_gyro.hpp"
#include "sdl_sensors.hpp"
FrontendSDL::FrontendSDL() : keyboardMappings(InputMappings::defaultKeyboardMappings()) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) {
@ -289,7 +289,7 @@ void FrontendSDL::run() {
case SDL_CONTROLLERSENSORUPDATE: {
if (event.csensor.sensor == SDL_SENSOR_GYRO) {
auto rotation = Gyro::SDL::convertRotation({
auto rotation = Sensors::SDL::convertRotation({
event.csensor.data[0],
event.csensor.data[1],
event.csensor.data[2],
@ -299,7 +299,8 @@ void FrontendSDL::run() {
hid.setRoll(s16(rotation.y));
hid.setYaw(s16(rotation.z));
} else if (event.csensor.sensor == SDL_SENSOR_ACCEL) {
hid.setAccel(s16(event.csensor.data[0]), s16(-event.csensor.data[1]), s16(event.csensor.data[2]));
auto accel = Sensors::SDL::convertAcceleration(event.csensor.data);
hid.setAccel(accel.x, accel.y, accel.z);
}
break;
}