mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-28 07:45:22 +00:00
Fixed reading the controller accelerometer on Apple platforms
DualShock and DualSense controllers no longer have hasGravityAndUserAcceleration set, but we can still get the combined user + gravity acceleration values from those controllers, which is what we want.
This commit is contained in:
@@ -946,8 +946,6 @@ static bool IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
GCMotion *motion = controller.motion;
|
||||
if (motion && motion.hasRotationRate) {
|
||||
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 0.0f);
|
||||
}
|
||||
if (motion && motion.hasGravityAndUserAcceleration) {
|
||||
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 0.0f);
|
||||
}
|
||||
}
|
||||
@@ -1198,20 +1196,17 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
|
||||
if (motion && motion.sensorsActive) {
|
||||
float data[3];
|
||||
|
||||
if (motion.hasRotationRate) {
|
||||
GCRotationRate rate = motion.rotationRate;
|
||||
data[0] = rate.x;
|
||||
data[1] = rate.z;
|
||||
data[2] = -rate.y;
|
||||
SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, timestamp, data, 3);
|
||||
}
|
||||
if (motion.hasGravityAndUserAcceleration) {
|
||||
GCAcceleration accel = motion.acceleration;
|
||||
data[0] = -accel.x * SDL_STANDARD_GRAVITY;
|
||||
data[1] = -accel.y * SDL_STANDARD_GRAVITY;
|
||||
data[2] = -accel.z * SDL_STANDARD_GRAVITY;
|
||||
SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, timestamp, data, 3);
|
||||
}
|
||||
GCRotationRate rate = motion.rotationRate;
|
||||
data[0] = rate.x;
|
||||
data[1] = rate.z;
|
||||
data[2] = -rate.y;
|
||||
SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, timestamp, data, 3);
|
||||
|
||||
GCAcceleration accel = motion.acceleration;
|
||||
data[0] = -accel.x * SDL_STANDARD_GRAVITY;
|
||||
data[1] = -accel.y * SDL_STANDARD_GRAVITY;
|
||||
data[2] = -accel.z * SDL_STANDARD_GRAVITY;
|
||||
SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, timestamp, data, 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user