mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-04 19:55:19 +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:
parent
d8b2434047
commit
14c31ee12a
1 changed files with 11 additions and 16 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue