apple: acceleration should include gravity (#17467)

This commit is contained in:
Eric Warmenhoven 2025-01-24 12:05:32 -05:00 committed by GitHub
parent 81e443c4cf
commit 04cdf0aa4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -742,7 +742,6 @@ static int16_t cocoa_input_state(
static void cocoa_input_free(void *data)
{
unsigned i;
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
if (!apple || !data)
@ -782,6 +781,10 @@ static bool cocoa_input_set_sensor_state(void *data, unsigned port,
continue;
if (!controller.motion)
break;
if (action == RETRO_SENSOR_ACCELEROMETER_ENABLE && !controller.motion.hasGravityAndUserAcceleration)
break;
if (action == RETRO_SENSOR_GYROSCOPE_ENABLE && !controller.motion.hasAttitudeAndRotationRate)
break;
if (controller.motion.sensorsRequireManualActivation)
{
/* This is a bug, we assume if you turn on/off either
@ -827,7 +830,7 @@ static bool cocoa_input_set_sensor_state(void *data, unsigned port,
static float cocoa_input_get_sensor_input(void *data, unsigned port, unsigned id)
{
#ifdef HAVE_MFI
if (@available(iOS 14.0, *))
if (@available(iOS 14.0, macOS 11.0, tvOS 14.0, *))
{
for (GCController *controller in [GCController controllers])
{
@ -838,11 +841,11 @@ static float cocoa_input_get_sensor_input(void *data, unsigned port, unsigned id
switch (id)
{
case RETRO_SENSOR_ACCELEROMETER_X:
return controller.motion.userAcceleration.x;
return controller.motion.acceleration.x;
case RETRO_SENSOR_ACCELEROMETER_Y:
return controller.motion.userAcceleration.y;
return controller.motion.acceleration.y;
case RETRO_SENSOR_ACCELEROMETER_Z:
return controller.motion.userAcceleration.z;
return controller.motion.acceleration.z;
case RETRO_SENSOR_GYROSCOPE_X:
return controller.motion.rotationRate.x;
case RETRO_SENSOR_GYROSCOPE_Y:
@ -860,11 +863,11 @@ static float cocoa_input_get_sensor_input(void *data, unsigned port, unsigned id
switch (id)
{
case RETRO_SENSOR_ACCELEROMETER_X:
return motionManager.deviceMotion.userAcceleration.x;
return motionManager.deviceMotion.gravity.x + motionManager.deviceMotion.userAcceleration.x;
case RETRO_SENSOR_ACCELEROMETER_Y:
return motionManager.deviceMotion.userAcceleration.y;
return motionManager.deviceMotion.gravity.y + motionManager.deviceMotion.userAcceleration.y;
case RETRO_SENSOR_ACCELEROMETER_Z:
return motionManager.deviceMotion.userAcceleration.z;
return motionManager.deviceMotion.gravity.z + motionManager.deviceMotion.userAcceleration.z;
case RETRO_SENSOR_GYROSCOPE_X:
return motionManager.deviceMotion.rotationRate.x;
case RETRO_SENSOR_GYROSCOPE_Y: