Fixed Gyro not working

This commit is contained in:
MelonSpeedruns 2022-03-22 11:13:17 -04:00 committed by Kenix3
parent 2a33fe7254
commit ae05072191
1 changed files with 7 additions and 32 deletions

View File

@ -63,38 +63,9 @@ namespace Ship {
if (Conf[ConfSection]["GUID"].compare("") == 0 || Conf[ConfSection]["GUID"].compare(INVALID_SDL_CONTROLLER_GUID) == 0 || Conf[ConfSection]["GUID"].compare(NewGuid) == 0) { if (Conf[ConfSection]["GUID"].compare("") == 0 || Conf[ConfSection]["GUID"].compare(INVALID_SDL_CONTROLLER_GUID) == 0 || Conf[ConfSection]["GUID"].compare(NewGuid) == 0) {
auto NewCont = SDL_GameControllerOpen(i); auto NewCont = SDL_GameControllerOpen(i);
if (SDL_GameControllerHasSensor(Cont, SDL_SENSOR_GYRO)){ if (SDL_GameControllerHasSensor(NewCont, SDL_SENSOR_GYRO))
float gyroData[3]; {
SDL_GameControllerGetSensorData(Cont, SDL_SENSOR_GYRO, gyroData, 3); SDL_GameControllerSetSensorEnabled(NewCont, SDL_SENSOR_GYRO, SDL_TRUE);
const char* contName = SDL_GameControllerName(Cont);
const int isSpecialController = strcmp("PS5 Controller", contName);
const float gyroSensitivity = Game::Settings.controller.gyro_sensitivity;
if (gyroDriftX == 0) {
if (isSpecialController == 0) {
gyroDriftX = gyroData[2];
}
else {
gyroDriftX = gyroData[0];
}
}
if (gyroDriftY == 0) {
gyroDriftY = gyroData[1];
}
if (isSpecialController == 0) {
wGyroX = gyroData[2] - gyroDriftX;
}
else {
wGyroX = gyroData[0] - gyroDriftX;
}
wGyroY = gyroData[1] - gyroDriftY;
wGyroX *= gyroSensitivity;
wGyroY *= gyroSensitivity;
} }
// We failed to load the controller. Go to next. // We failed to load the controller. Go to next.
@ -216,6 +187,7 @@ namespace Ship {
const char* contName = SDL_GameControllerName(Cont); const char* contName = SDL_GameControllerName(Cont);
const int isSpecialController = strcmp("PS5 Controller", contName); const int isSpecialController = strcmp("PS5 Controller", contName);
const float gyroSensitivity = Game::Settings.controller.gyro_sensitivity;
if (gyroDriftX == 0) { if (gyroDriftX == 0) {
if (isSpecialController == 0) { if (isSpecialController == 0) {
@ -238,6 +210,9 @@ namespace Ship {
} }
wGyroY = gyroData[1] - gyroDriftY; wGyroY = gyroData[1] - gyroDriftY;
wGyroX *= gyroSensitivity;
wGyroY *= gyroSensitivity;
} }
for (int32_t i = SDL_CONTROLLER_BUTTON_A; i < SDL_CONTROLLER_BUTTON_MAX; i++) { for (int32_t i = SDL_CONTROLLER_BUTTON_A; i < SDL_CONTROLLER_BUTTON_MAX; i++) {