diff options
author | Marcus Brummer <mbrlabs7@gmail.com> | 2021-03-16 21:08:55 +0100 |
---|---|---|
committer | Marcus Brummer <mbrlabs7@gmail.com> | 2021-03-17 14:05:05 +0100 |
commit | fda2743fef8fbcf0ba5fb4ac93a613ad61735fff (patch) | |
tree | 2f44bc567f7ebf2b46474610df0b5bd47d983638 /platform/iphone/godot_view.mm | |
parent | fbba496db5bf904d54993145f5bb52a1709f7364 (diff) | |
download | redot-engine-fda2743fef8fbcf0ba5fb4ac93a613ad61735fff.tar.gz |
Converted sensor acceleration units to m/s^2 on iOS and UWP
This is beacuse on Android these values are already in m/s^2 while on
iOS and UWP they are in g. This just makes the behaviour consistent on
all platforms.
Diffstat (limited to 'platform/iphone/godot_view.mm')
-rw-r--r-- | platform/iphone/godot_view.mm | 12 |
1 files changed, 11 insertions, 1 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; |