2
0
Эх сурвалжийг харах

Merge pull request #53742 from DmitriySalnikov/exposed_sensor_setters

Rémi Verschelde 3 жил өмнө
parent
commit
c743649c0b

+ 4 - 0
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);

+ 4 - 0
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;

+ 32 - 0
doc/classes/Input.xml

@@ -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" />
@@ -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" />

+ 4 - 4
main/input_default.h

@@ -252,10 +252,10 @@ public:
 
 	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);