From 00d3bf1e7fcbb83f0da502df6f6c357c39c73bbe Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Mon, 7 Oct 2013 22:07:02 +0200 Subject: [PATCH] [iOS] Cosmetic changes in joystick implementation --- src/SFML/Window/iOS/JoystickImpl.mm | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/SFML/Window/iOS/JoystickImpl.mm b/src/SFML/Window/iOS/JoystickImpl.mm index b4aafcb7c..b6f7720d7 100644 --- a/src/SFML/Window/iOS/JoystickImpl.mm +++ b/src/SFML/Window/iOS/JoystickImpl.mm @@ -144,41 +144,43 @@ JoystickState JoystickImpl::update() // Always connected state.connected = true; + CMMotionManager* manager = [SFAppDelegate getInstance].motionManager; + switch (m_index) { case Accelerometer: // Acceleration is given in G (reminder: 1G is regular earth gravity, 9.81 m/s^2), in range [-2, 2] (could be more on newer devices?) - state.axes[Joystick::X] = [SFAppDelegate getInstance].motionManager.accelerometerData.acceleration.x; - state.axes[Joystick::Y] = [SFAppDelegate getInstance].motionManager.accelerometerData.acceleration.y; - state.axes[Joystick::Z] = [SFAppDelegate getInstance].motionManager.accelerometerData.acceleration.z; + state.axes[Joystick::X] = manager.accelerometerData.acceleration.x; + state.axes[Joystick::Y] = manager.accelerometerData.acceleration.y; + state.axes[Joystick::Z] = manager.accelerometerData.acceleration.z; break; case Gyroscope: // Rotation rates are given in rad/s, in range [?, ?] - state.axes[Joystick::X] = [SFAppDelegate getInstance].motionManager.gyroData.rotationRate.x; - state.axes[Joystick::Y] = [SFAppDelegate getInstance].motionManager.gyroData.rotationRate.y; - state.axes[Joystick::Z] = [SFAppDelegate getInstance].motionManager.gyroData.rotationRate.z; + state.axes[Joystick::X] = manager.gyroData.rotationRate.x; + state.axes[Joystick::Y] = manager.gyroData.rotationRate.y; + state.axes[Joystick::Z] = manager.gyroData.rotationRate.z; break; case Magnetometer: // Magnetic field is given in microteslas, in range [?, ?] - state.axes[Joystick::X] = [SFAppDelegate getInstance].motionManager.magnetometerData.magneticField.x; - state.axes[Joystick::Y] = [SFAppDelegate getInstance].motionManager.magnetometerData.magneticField.y; - state.axes[Joystick::Z] = [SFAppDelegate getInstance].motionManager.magnetometerData.magneticField.z; + state.axes[Joystick::X] = manager.magnetometerData.magneticField.x; + state.axes[Joystick::Y] = manager.magnetometerData.magneticField.y; + state.axes[Joystick::Z] = manager.magnetometerData.magneticField.z; break; case UserAcceleration: // User acceleration (gravity removed), same unit and range as raw accelerometer values - state.axes[Joystick::X] = [SFAppDelegate getInstance].motionManager.deviceMotion.userAcceleration.x; - state.axes[Joystick::Y] = [SFAppDelegate getInstance].motionManager.deviceMotion.userAcceleration.y; - state.axes[Joystick::Z] = [SFAppDelegate getInstance].motionManager.deviceMotion.userAcceleration.z; + state.axes[Joystick::X] = manager.deviceMotion.userAcceleration.x; + state.axes[Joystick::Y] = manager.deviceMotion.userAcceleration.y; + state.axes[Joystick::Z] = manager.deviceMotion.userAcceleration.z; break; case AbsoluteOrientation: // Absolute rotation (Euler) angles are given in radians, in range [-PI, PI] - state.axes[Joystick::X] = [SFAppDelegate getInstance].motionManager.deviceMotion.attitude.yaw; - state.axes[Joystick::Y] = [SFAppDelegate getInstance].motionManager.deviceMotion.attitude.pitch; - state.axes[Joystick::Z] = [SFAppDelegate getInstance].motionManager.deviceMotion.attitude.roll; + state.axes[Joystick::X] = manager.deviceMotion.attitude.yaw; + state.axes[Joystick::Y] = manager.deviceMotion.attitude.pitch; + state.axes[Joystick::Z] = manager.deviceMotion.attitude.roll; break; default: