From 5cf898b8971861ea3f25ee40b4662209322a6fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=A1=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= Date: Tue, 12 Oct 2021 23:09:30 +0300 Subject: [PATCH] Exposed setters for sensor values in Input class --- core/os/input.cpp | 4 ++++ core/os/input.h | 4 ++++ doc/classes/Input.xml | 32 ++++++++++++++++++++++++++++++++ main/input_default.h | 8 ++++---- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/core/os/input.cpp b/core/os/input.cpp index 42816200dc..7d81a86695 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -85,6 +85,10 @@ void Input::_bind_methods() { ClassDB::bind_method(D_METHOD("get_accelerometer"), &Input::get_accelerometer); ClassDB::bind_method(D_METHOD("get_magnetometer"), &Input::get_magnetometer); ClassDB::bind_method(D_METHOD("get_gyroscope"), &Input::get_gyroscope); + ClassDB::bind_method(D_METHOD("set_gravity", "value"), &Input::set_gravity); + ClassDB::bind_method(D_METHOD("set_accelerometer", "value"), &Input::set_accelerometer); + ClassDB::bind_method(D_METHOD("set_magnetometer", "value"), &Input::set_magnetometer); + ClassDB::bind_method(D_METHOD("set_gyroscope", "value"), &Input::set_gyroscope); //ClassDB::bind_method(D_METHOD("get_mouse_position"),&Input::get_mouse_position); - this is not the function you want ClassDB::bind_method(D_METHOD("get_last_mouse_speed"), &Input::get_last_mouse_speed); ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &Input::get_mouse_button_mask); diff --git a/core/os/input.h b/core/os/input.h index 738d0481fb..8489fcb78d 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -116,6 +116,10 @@ public: virtual Vector3 get_accelerometer() const = 0; virtual Vector3 get_magnetometer() const = 0; virtual Vector3 get_gyroscope() const = 0; + virtual void set_gravity(const Vector3 &p_gravity) = 0; + virtual void set_accelerometer(const Vector3 &p_accel) = 0; + virtual void set_magnetometer(const Vector3 &p_magnetometer) = 0; + virtual void set_gyroscope(const Vector3 &p_gyroscope) = 0; virtual void action_press(const StringName &p_action, float p_strength = 1.f) = 0; virtual void action_release(const StringName &p_action) = 0; diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml index 25371c6f0a..37e8839cef 100644 --- a/doc/classes/Input.xml +++ b/doc/classes/Input.xml @@ -289,6 +289,14 @@ Removes all mappings from the internal database that match the given GUID. + + + + + Sets the acceleration value of the accelerometer sensor. Can be used for debugging on devices without a hardware sensor, for example in an editor on a PC. + [b]Note:[/b] This value can be immediately overwritten by the hardware sensor value on Android and iOS. + + @@ -311,6 +319,30 @@ [b]Note:[/b] This method generates an [InputEventMouseMotion] to update cursor immediately. + + + + + Sets the gravity value of the accelerometer sensor. Can be used for debugging on devices without a hardware sensor, for example in an editor on a PC. + [b]Note:[/b] This value can be immediately overwritten by the hardware sensor value on Android and iOS. + + + + + + + Sets the value of the rotation rate of the gyroscope sensor. Can be used for debugging on devices without a hardware sensor, for example in an editor on a PC. + [b]Note:[/b] This value can be immediately overwritten by the hardware sensor value on Android and iOS. + + + + + + + Sets the value of the magnetic field of the magnetometer sensor. Can be used for debugging on devices without a hardware sensor, for example in an editor on a PC. + [b]Note:[/b] This value can be immediately overwritten by the hardware sensor value on Android and iOS. + + diff --git a/main/input_default.h b/main/input_default.h index ed4144f31a..7efa0450b4 100644 --- a/main/input_default.h +++ b/main/input_default.h @@ -252,10 +252,10 @@ public: virtual void parse_input_event(const Ref &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); + virtual void set_gravity(const Vector3 &p_gravity); + virtual void set_accelerometer(const Vector3 &p_accel); + virtual void set_magnetometer(const Vector3 &p_magnetometer); + virtual void set_gyroscope(const Vector3 &p_gyroscope); void set_joy_axis(int p_device, int p_axis, float p_value); virtual void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0);