diff options
| author | Rémi Verschelde <remi@verschelde.fr> | 2021-03-17 14:27:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-17 14:27:23 +0100 |
| commit | 7b223e8eec068a21d42eff5815c05a7006e21c2f (patch) | |
| tree | e5a72d87368ea73731dcea88a1be646094610bb3 /platform | |
| parent | a851b72354c67af2693f02e636b75ffb67df66fd (diff) | |
| parent | fda2743fef8fbcf0ba5fb4ac93a613ad61735fff (diff) | |
| download | redot-engine-7b223e8eec068a21d42eff5815c05a7006e21c2f.tar.gz | |
Merge pull request #47080 from mbrlabs/ios-sensor-conversion
Converted sensor acceleration units to m/s² on iOS and UWP
Diffstat (limited to 'platform')
| -rw-r--r-- | platform/iphone/godot_view.mm | 12 | ||||
| -rw-r--r-- | platform/uwp/os_uwp.cpp | 8 |
2 files changed, 16 insertions, 4 deletions
diff --git a/platform/iphone/godot_view.mm b/platform/iphone/godot_view.mm index 887297848e..468fa2928a 100644 --- a/platform/iphone/godot_view.mm +++ b/platform/iphone/godot_view.mm @@ -39,6 +39,7 @@ #import <CoreMotion/CoreMotion.h> static const int max_touches = 8; +static const float earth_gravity = 9.80665; @interface GodotView () { UITouch *godot_touches[max_touches]; @@ -402,10 +403,19 @@ static const int max_touches = 8; // https://developer.apple.com/reference/coremotion/cmmotionmanager?language=objc // Apple splits our accelerometer date into a gravity and user movement - // component. We add them back together + // component. We add them back together. CMAcceleration gravity = self.motionManager.deviceMotion.gravity; CMAcceleration acceleration = self.motionManager.deviceMotion.userAcceleration; + // To be consistent with Android we convert the unit of measurement from g (Earth's gravity) + // to m/s^2. + gravity.x *= earth_gravity; + gravity.y *= earth_gravity; + gravity.z *= earth_gravity; + acceleration.x *= earth_gravity; + acceleration.y *= earth_gravity; + acceleration.z *= earth_gravity; + ///@TODO We don't seem to be getting data here, is my device broken or /// is this code incorrect? CMMagneticField magnetic = self.motionManager.deviceMotion.magneticField.field; diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index fa97948395..33992069f9 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -62,6 +62,8 @@ using namespace Windows::Devices::Sensors; using namespace Windows::ApplicationModel::DataTransfer; using namespace concurrency; +static const float earth_gravity = 9.80665; + int OS_UWP::get_video_driver_count() const { return 2; } @@ -372,9 +374,9 @@ void OS_UWP::ManagedType::on_accelerometer_reading_changed(Accelerometer ^ sende AccelerometerReading ^ reading = args->Reading; os->input->set_accelerometer(Vector3( - reading->AccelerationX, - reading->AccelerationY, - reading->AccelerationZ)); + reading->AccelerationX * earth_gravity, + reading->AccelerationY * earth_gravity, + reading->AccelerationZ * earth_gravity)); } void OS_UWP::ManagedType::on_magnetometer_reading_changed(Magnetometer ^ sender, MagnetometerReadingChangedEventArgs ^ args) { |
