Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Exposed setters for sensor values in Input class #53742

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/os/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions core/os/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ class Input : public Object {
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;
Expand Down
32 changes: 32 additions & 0 deletions doc/classes/Input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@
Removes all mappings from the internal database that match the given GUID.
</description>
</method>
<method name="set_accelerometer">
<return type="void" />
<argument index="0" name="value" type="Vector3" />
<description>
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.
</description>
</method>
<method name="set_custom_mouse_cursor">
<return type="void" />
<argument index="0" name="image" type="Resource" />
Expand All @@ -311,6 +319,30 @@
[b]Note:[/b] This method generates an [InputEventMouseMotion] to update cursor immediately.
</description>
</method>
<method name="set_gravity">
<return type="void" />
<argument index="0" name="value" type="Vector3" />
<description>
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.
</description>
</method>
<method name="set_gyroscope">
<return type="void" />
<argument index="0" name="value" type="Vector3" />
<description>
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.
</description>
</method>
<method name="set_magnetometer">
<return type="void" />
<argument index="0" name="value" type="Vector3" />
<description>
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.
</description>
</method>
<method name="set_mouse_mode">
<return type="void" />
<argument index="0" name="mode" type="int" enum="Input.MouseMode" />
Expand Down
8 changes: 4 additions & 4 deletions main/input_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ class InputDefault : public Input {

virtual void parse_input_event(const Ref<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);
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);
Expand Down