diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/iphone/app_delegate.mm | 16 | ||||
-rw-r--r-- | platform/iphone/os_iphone.cpp | 4 | ||||
-rw-r--r-- | platform/iphone/os_iphone.h | 1 |
3 files changed, 15 insertions, 6 deletions
diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm index 4d05c4b19c..664683ad64 100644 --- a/platform/iphone/app_delegate.mm +++ b/platform/iphone/app_delegate.mm @@ -218,25 +218,29 @@ static int frame_count = 0; // a good thing when you're trying to get your user to move the screen in all directions and want consistent output ///@TODO Using [[UIApplication sharedApplication] statusBarOrientation] is a bit of a hack. Godot obviously knows the orientation so maybe we - // can use that instead? + // can use that instead? (note that left and right seem swapped) switch ([[UIApplication sharedApplication] statusBarOrientation]) { case UIDeviceOrientationLandscapeLeft: { - OSIPhone::get_singleton()->update_accelerometer(-(acceleration.y + gravity.y), acceleration.x + gravity.x, acceleration.z + gravity.z); + OSIPhone::get_singleton()->update_gravity(-gravity.y, gravity.x, gravity.z); + OSIPhone::get_singleton()->update_accelerometer(-(acceleration.y + gravity.y), (acceleration.x + gravity.x), acceleration.z + gravity.z); OSIPhone::get_singleton()->update_magnetometer(-magnetic.y, magnetic.x, magnetic.z); OSIPhone::get_singleton()->update_gyroscope(-rotation.y, rotation.x, rotation.z); }; break; case UIDeviceOrientationLandscapeRight: { - OSIPhone::get_singleton()->update_accelerometer(acceleration.y + gravity.y, acceleration.x + gravity.x, acceleration.z + gravity.z); - OSIPhone::get_singleton()->update_magnetometer(magnetic.y, magnetic.x, magnetic.z); - OSIPhone::get_singleton()->update_gyroscope(rotation.y, rotation.x, rotation.z); + OSIPhone::get_singleton()->update_gravity(gravity.y, -gravity.x, gravity.z); + OSIPhone::get_singleton()->update_accelerometer((acceleration.y + gravity.y), -(acceleration.x + gravity.x), acceleration.z + gravity.z); + OSIPhone::get_singleton()->update_magnetometer(magnetic.y, -magnetic.x, magnetic.z); + OSIPhone::get_singleton()->update_gyroscope(rotation.y, -rotation.x, rotation.z); }; break; case UIDeviceOrientationPortraitUpsideDown: { - OSIPhone::get_singleton()->update_accelerometer(-(acceleration.x + gravity.x), acceleration.y + gravity.y, acceleration.z + gravity.z); + OSIPhone::get_singleton()->update_gravity(-gravity.x, gravity.y, gravity.z); + OSIPhone::get_singleton()->update_accelerometer(-(acceleration.x + gravity.x), (acceleration.y + gravity.y), acceleration.z + gravity.z); OSIPhone::get_singleton()->update_magnetometer(-magnetic.x, magnetic.y, magnetic.z); OSIPhone::get_singleton()->update_gyroscope(-rotation.x, rotation.y, rotation.z); }; break; default: { // assume portrait + OSIPhone::get_singleton()->update_gravity(gravity.x, gravity.y, gravity.z); OSIPhone::get_singleton()->update_accelerometer(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z); OSIPhone::get_singleton()->update_magnetometer(magnetic.x, magnetic.y, magnetic.z); OSIPhone::get_singleton()->update_gyroscope(rotation.x, rotation.y, rotation.z); diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index 0ef6cd7c32..051c562b6a 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -323,6 +323,10 @@ void OSIPhone::touches_cancelled() { static const float ACCEL_RANGE = 1; +void OSIPhone::update_gravity(float p_x, float p_y, float p_z) { + input->set_gravity(Vector3(p_x, p_y, p_z)); +}; + void OSIPhone::update_accelerometer(float p_x, float p_y, float p_z) { // Found out the Z should not be negated! Pass as is! diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index 57e530f649..ab976edcba 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -152,6 +152,7 @@ public: int set_base_framebuffer(int p_fb); + void update_gravity(float p_x, float p_y, float p_z); void update_accelerometer(float p_x, float p_y, float p_z); void update_magnetometer(float p_x, float p_y, float p_z); void update_gyroscope(float p_x, float p_y, float p_z); |