From 447e7b38440c405e0e6c91d9e4317d520d0d42fb Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Tue, 18 Jun 2024 12:59:36 -0600 Subject: [PATCH] Replace `static_cast`s with vector operations --- src/SFML/Window/iOS/SensorImpl.mm | 39 ++++++++++++------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/SFML/Window/iOS/SensorImpl.mm b/src/SFML/Window/iOS/SensorImpl.mm index 1c86983b7..b720beab9 100644 --- a/src/SFML/Window/iOS/SensorImpl.mm +++ b/src/SFML/Window/iOS/SensorImpl.mm @@ -127,51 +127,42 @@ void SensorImpl::close() //////////////////////////////////////////////////////////// Vector3f SensorImpl::update() { - Vector3f value; CMMotionManager* const manager = [SFAppDelegate getInstance].motionManager; switch (m_sensor) { case Sensor::Type::Accelerometer: // Acceleration is given in G, convert to m/s^2 - value.x = static_cast(manager.accelerometerData.acceleration.x * 9.81); - value.y = static_cast(manager.accelerometerData.acceleration.y * 9.81); - value.z = static_cast(manager.accelerometerData.acceleration.z * 9.81); - break; + return Vector3f(9.81 * Vector3(manager.accelerometerData.acceleration.x, + manager.accelerometerData.acceleration.y, + manager.accelerometerData.acceleration.z)); case Sensor::Type::Gyroscope: // Rotation rates are given in rad/s - value.x = static_cast(manager.gyroData.rotationRate.x); - value.y = static_cast(manager.gyroData.rotationRate.y); - value.z = static_cast(manager.gyroData.rotationRate.z); - break; + return Vector3f( + Vector3(manager.gyroData.rotationRate.x, manager.gyroData.rotationRate.y, manager.gyroData.rotationRate.z)); case Sensor::Type::Magnetometer: // Magnetic field is given in microteslas - value.x = static_cast(manager.magnetometerData.magneticField.x); - value.y = static_cast(manager.magnetometerData.magneticField.y); - value.z = static_cast(manager.magnetometerData.magneticField.z); - break; + return Vector3f(Vector3(manager.magnetometerData.magneticField.x, + manager.magnetometerData.magneticField.y, + manager.magnetometerData.magneticField.z)); case Sensor::Type::UserAcceleration: // User acceleration is given in G, convert to m/s^2 - value.x = static_cast(manager.deviceMotion.userAcceleration.x * 9.81); - value.y = static_cast(manager.deviceMotion.userAcceleration.y * 9.81); - value.z = static_cast(manager.deviceMotion.userAcceleration.z * 9.81); - break; + return Vector3f(9.81 * Vector3(manager.deviceMotion.userAcceleration.x, + manager.deviceMotion.userAcceleration.y, + manager.deviceMotion.userAcceleration.z)); case Sensor::Type::Orientation: // Absolute rotation (Euler) angles are given in radians - value.x = static_cast(manager.deviceMotion.attitude.yaw); - value.y = static_cast(manager.deviceMotion.attitude.pitch); - value.z = static_cast(manager.deviceMotion.attitude.roll); - break; + return Vector3f(Vector3(manager.deviceMotion.attitude.yaw, + manager.deviceMotion.attitude.pitch, + manager.deviceMotion.attitude.roll)); default: - break; + return {}; } - - return value; }