diff options
-rw-r--r-- | core/os/input.cpp | 1 | ||||
-rw-r--r-- | core/os/input.h | 1 | ||||
-rw-r--r-- | main/input_default.cpp | 14 | ||||
-rw-r--r-- | main/input_default.h | 3 | ||||
-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 |
7 files changed, 34 insertions, 6 deletions
diff --git a/core/os/input.cpp b/core/os/input.cpp index d2bd433ed9..2ae5834bde 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -70,6 +70,7 @@ void Input::_bind_methods() { ClassDB::bind_method(_MD("get_joy_axis_index_from_string", "axis"), &Input::get_joy_axis_index_from_string); ClassDB::bind_method(_MD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration, DEFVAL(0)); ClassDB::bind_method(_MD("stop_joy_vibration", "device"), &Input::stop_joy_vibration); + ClassDB::bind_method(_MD("get_gravity"),&Input::get_gravity); ClassDB::bind_method(_MD("get_accelerometer"),&Input::get_accelerometer); ClassDB::bind_method(_MD("get_magnetometer"),&Input::get_magnetometer); ClassDB::bind_method(_MD("get_gyroscope"),&Input::get_gyroscope); diff --git a/core/os/input.h b/core/os/input.h index c365894f46..b12ad9b55d 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -82,6 +82,7 @@ public: virtual void warp_mouse_pos(const Vector2& p_to)=0; + virtual Vector3 get_gravity() const=0; virtual Vector3 get_accelerometer() const=0; virtual Vector3 get_magnetometer() const=0; virtual Vector3 get_gyroscope() const=0; diff --git a/main/input_default.cpp b/main/input_default.cpp index 6f27bcdc5a..c2c4e28854 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -277,6 +277,12 @@ void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_ emit_signal("joy_connection_changed", p_idx, p_connected); }; +Vector3 InputDefault::get_gravity() const{ + + _THREAD_SAFE_METHOD_ + return gravity; +} + Vector3 InputDefault::get_accelerometer() const{ _THREAD_SAFE_METHOD_ @@ -423,6 +429,14 @@ void InputDefault::stop_joy_vibration(int p_device) { joy_vibration[p_device] = vibration; } +void InputDefault::set_gravity(const Vector3& p_gravity) { + + _THREAD_SAFE_METHOD_ + + gravity=p_gravity; + +} + void InputDefault::set_accelerometer(const Vector3& p_accel) { _THREAD_SAFE_METHOD_ diff --git a/main/input_default.h b/main/input_default.h index 33a852ab10..fe7e89d771 100644 --- a/main/input_default.h +++ b/main/input_default.h @@ -44,6 +44,7 @@ class InputDefault : public Input { Set<int> joy_buttons_pressed; Map<int,float> _joy_axis; //Map<StringName,int> custom_action_press; + Vector3 gravity; Vector3 accelerometer; Vector3 magnetometer; Vector3 gyroscope; @@ -191,6 +192,7 @@ public: void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid = ""); void parse_joypad_mapping(String p_mapping, bool p_update_existing); + virtual Vector3 get_gravity() const; virtual Vector3 get_accelerometer() const; virtual Vector3 get_magnetometer() const; virtual Vector3 get_gyroscope() const; @@ -203,6 +205,7 @@ public: void parse_input_event(const InputEvent& p_event); + void set_gravity(const Vector3& p_gravity); void set_accelerometer(const Vector3& p_accel); void set_magnetometer(const Vector3& p_magnetometer); void set_gyroscope(const Vector3& p_gyroscope); 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); |