Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Add Input.get_device_orientation() returning hardware-fused quaternion

lxduabd410922a327
diff --git a/core/input/input.cpp b/core/input/input.cpp
index f411f0332a2..cb7be65a980 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -168,6 +168,7 @@ 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("get_device_orientation"), &Input::get_device_orientation);
ClassDB::bind_method(D_METHOD("get_joy_accelerometer", "device"), &Input::get_joy_accelerometer);
ClassDB::bind_method(D_METHOD("get_joy_gravity", "device"), &Input::get_joy_gravity);
ClassDB::bind_method(D_METHOD("get_joy_gyroscope", "device"), &Input::get_joy_gyroscope);
@@ -192,6 +193,7 @@ void Input::_bind_methods() {
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("set_device_orientation", "value"), &Input::set_device_orientation);
ClassDB::bind_method(D_METHOD("set_joy_light", "device", "color"), &Input::set_joy_light);
ClassDB::bind_method(D_METHOD("has_joy_light", "device"), &Input::has_joy_light);
ClassDB::bind_method(D_METHOD("get_last_mouse_velocity"), &Input::get_last_mouse_velocity);
@@ -807,6 +809,18 @@ Vector3 Input::get_gyroscope() const {
return gyroscope;
}
+Quaternion Input::get_device_orientation() const {
+ _THREAD_SAFE_METHOD_
+
+#if defined(DEBUG_ENABLED) && defined(ANDROID_ENABLED)
+ if (!device_orientation_enabled) {
+ WARN_PRINT_ONCE("`input_devices/sensors/enable_device_orientation` is not enabled in project settings.");
+ }
+#endif
+
+ return device_orientation;
+}
+
Vector2 Input::get_joy_touchpad_finger_position(int p_device, int p_finger, int p_touchpad) const {
_THREAD_SAFE_METHOD_
const TouchpadInfo *touch = joy_touch.getptr(p_device);
@@ -1440,6 +1454,12 @@ void Input::set_gyroscope(const Vector3 &p_gyroscope) {
gyroscope = p_gyroscope;
}
+void Input::set_device_orientation(const Quaternion &p_orientation) {
+ _THREAD_SAFE_METHOD_
+
+ device_orientation = p_orientation;
+}
+
void Input::set_mouse_position(const Point2 &p_posf) {
mouse_pos = p_posf;
}
@@ -2482,6 +2502,7 @@ Input::Input() {
gravity_enabled = GLOBAL_DEF_RST_BASIC("input_devices/sensors/enable_gravity", false);
gyroscope_enabled = GLOBAL_DEF_RST_BASIC("input_devices/sensors/enable_gyroscope", false);
magnetometer_enabled = GLOBAL_DEF_RST_BASIC("input_devices/sensors/enable_magnetometer", false);
+ device_orientation_enabled = GLOBAL_DEF_RST_BASIC("input_devices/sensors/enable_device_orientation", false);
ignore_joypad_on_unfocused_application = GLOBAL_DEF_RST_BASIC("input_devices/joypads/ignore_joypad_on_unfocused_application", false);
}
diff --git a/core/input/input.h b/core/input/input.h
index 60376aa4dac..5ce56ed232a 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -124,6 +124,8 @@ private:
Vector3 magnetometer;
bool gyroscope_enabled = false;
Vector3 gyroscope;
+ bool device_orientation_enabled = false;
+ Quaternion device_orientation;
Vector2 mouse_pos;
int64_t mouse_window = 0;
bool legacy_just_pressed_behavior = false;
@@ -400,6 +402,7 @@ public:
Vector3 get_accelerometer() const;
Vector3 get_magnetometer() const;
Vector3 get_gyroscope() const;
+ Quaternion get_device_orientation() const;
int get_joy_num_touchpads(int p_device) const;
@@ -417,6 +420,7 @@ public:
void set_accelerometer(const Vector3 &p_accel);
void set_magnetometer(const Vector3 &p_magnetometer);
void set_gyroscope(const Vector3 &p_gyroscope);
+ void set_device_orientation(const Quaternion &p_orientation);
void set_joy_axis(int p_device, JoyAxis p_axis, float p_value);
void set_joy_features(int p_device, JoypadFeatures *p_features);
diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml
index c7d6c82973a..67a8c15944a 100644
--- a/doc/classes/Input.xml
+++ b/doc/classes/Input.xml
@@ -104,6 +104,20 @@
Returns the currently assigned cursor shape.
</description>
</method>
+ <method name="get_device_orientation" qualifiers="const" experimental="">
+ <return type="Quaternion" />
+ <description>
+ Returns the device's orientation as a [Quaternion], using hardware-level sensor fusion for stable, drift-free results. If the device does not support orientation sensing, the method returns [constant Quaternion.IDENTITY].
+ The returned quaternion represents the rotation from the device coordinate frame to the world coordinate frame. In portrait mode, the device's coordinate system is: X right, Y up, Z towards viewer.
+ [b]Note:[/b] This method only works on Android and iOS. On other platforms, it always returns [constant Quaternion.IDENTITY].
+ [b]Note:[/b] For Android, [member ProjectSettings.input_devices/sensors/enable_device_orientation] must be enabled.
+ [codeblock]
+ var orientation := Input.get_device_orientation()
+ var euler := orientation.get_euler()
+ var roll := euler.z # Device roll angle in radians.
+ [/codeblock]
+ </description>
+ </method>
<method name="get_gravity" qualifiers="const">
<return type="Vector3" />
<description>
@@ -647,6 +661,14 @@
[b]Note:[/b] This method generates an [InputEventMouseMotion] to update cursor immediately.
</description>
</method>
+ <method name="set_device_orientation">
+ <return type="void" />
+ <param index="0" name="value" type="Quaternion" />
+ <description>
+ Sets the device orientation quaternion. 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_gravity">
<return type="void" />
<param index="0" name="value" type="Vector3" />
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 8b13889bce0..96452536532 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -1714,6 +1714,10 @@
<member name="input_devices/sensors/enable_accelerometer" type="bool" setter="" getter="" default="false">
If [code]true[/code], the accelerometer sensor is enabled and [method Input.get_accelerometer] returns valid data.
</member>
+ <member name="input_devices/sensors/enable_device_orientation" type="bool" setter="" getter="" default="false">
+ If [code]true[/code], the device orientation sensor is enabled and [method Input.get_device_orientation] returns valid data. This uses hardware-level sensor fusion (rotation vector on Android, [code]CMDeviceMotion.attitude[/code] on iOS) to provide a stable device orientation quaternion without drift.
+ [b]Note:[/b] On Android, this registers [code]TYPE_GAME_ROTATION_VECTOR[/code] (preferred, no magnetometer) or [code]TYPE_ROTATION_VECTOR[/code] (fallback). On iOS, the attitude is read from the already-active [code]CMMotionManager.deviceMotion[/code].
+ </member>
<member name="input_devices/sensors/enable_gravity" type="bool" setter="" getter="" default="false">
If [code]true[/code], the gravity sensor is enabled and [method Input.get_gravity] returns valid data.
</member>
diff --git a/drivers/apple_embedded/display_server_apple_embedded.h b/drivers/apple_embedded/display_server_apple_embedded.h
index 925d9da66cd..2eae222f071 100644
--- a/drivers/apple_embedded/display_server_apple_embedded.h
+++ b/drivers/apple_embedded/display_server_apple_embedded.h
@@ -146,6 +146,7 @@ public:
void update_accelerometer(const Vector3 &p_accelerometer);
void update_magnetometer(const Vector3 &p_magnetometer);
void update_gyroscope(const Vector3 &p_gyroscope);
+ void update_device_orientation(const Quaternion &p_orientation);
// MARK: -
diff --git a/drivers/apple_embedded/display_server_apple_embedded.mm b/drivers/apple_embedded/display_server_apple_embedded.mm
index 38e45156033..b220be60b1c 100644
--- a/drivers/apple_embedded/display_server_apple_embedded.mm
+++ b/drivers/apple_embedded/display_server_apple_embedded.mm
@@ -352,6 +352,10 @@ void DisplayServerAppleEmbedded::update_gyroscope(const Vector3 &p_gyroscope) {
Input::get_singleton()->set_gyroscope(p_gyroscope);
}
+void DisplayServerAppleEmbedded::update_device_orientation(const Quaternion &p_orientation) {
+ Input::get_singleton()->set_device_orientation(p_orientation);
+}
+
// MARK: -
bool DisplayServerAppleEmbedded::has_feature(DisplayServerEnums::Feature p_feature) const {
diff --git a/drivers/apple_embedded/godot_view_apple_embedded.mm b/drivers/apple_embedded/godot_view_apple_embedded.mm
index 89983aec0a3..f2ceaff4c2b 100644
--- a/drivers/apple_embedded/godot_view_apple_embedded.mm
+++ b/drivers/apple_embedded/godot_view_apple_embedded.mm
@@ -428,6 +428,10 @@ static const float earth_gravity = 9.80665;
/// best
CMRotationRate rotation = self.motionManager.deviceMotion.rotationRate;
+ // Device orientation (attitude) as quaternion.
+ CMQuaternion att = self.motionManager.deviceMotion.attitude.quaternion;
+ Quaternion device_orientation(att.x, att.y, att.z, att.w);
+
// Adjust for screen orientation.
// [[UIDevice currentDevice] orientation] changes even if we've fixed
// our orientation which is not a good thing when you're trying to get
@@ -445,24 +449,28 @@ static const float earth_gravity = 9.80665;
DisplayServerAppleEmbedded::get_singleton()->update_accelerometer(Vector3(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z).rotated(Vector3(0, 0, 1), -Math::PI * 0.5));
DisplayServerAppleEmbedded::get_singleton()->update_magnetometer(Vector3(magnetic.x, magnetic.y, magnetic.z).rotated(Vector3(0, 0, 1), -Math::PI * 0.5));
DisplayServerAppleEmbedded::get_singleton()->update_gyroscope(Vector3(rotation.x, rotation.y, rotation.z).rotated(Vector3(0, 0, 1), -Math::PI * 0.5));
+ DisplayServerAppleEmbedded::get_singleton()->update_device_orientation(Quaternion(Vector3(0, 0, 1), -Math::PI * 0.5) * device_orientation);
} break;
case UIInterfaceOrientationLandscapeRight: {
DisplayServerAppleEmbedded::get_singleton()->update_gravity(Vector3(gravity.x, gravity.y, gravity.z).rotated(Vector3(0, 0, 1), Math::PI * 0.5));
DisplayServerAppleEmbedded::get_singleton()->update_accelerometer(Vector3(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z).rotated(Vector3(0, 0, 1), Math::PI * 0.5));
DisplayServerAppleEmbedded::get_singleton()->update_magnetometer(Vector3(magnetic.x, magnetic.y, magnetic.z).rotated(Vector3(0, 0, 1), Math::PI * 0.5));
DisplayServerAppleEmbedded::get_singleton()->update_gyroscope(Vector3(rotation.x, rotation.y, rotation.z).rotated(Vector3(0, 0, 1), Math::PI * 0.5));
+ DisplayServerAppleEmbedded::get_singleton()->update_device_orientation(Quaternion(Vector3(0, 0, 1), Math::PI * 0.5) * device_orientation);
} break;
case UIInterfaceOrientationPortraitUpsideDown: {
DisplayServerAppleEmbedded::get_singleton()->update_gravity(Vector3(gravity.x, gravity.y, gravity.z).rotated(Vector3(0, 0, 1), Math::PI));
DisplayServerAppleEmbedded::get_singleton()->update_accelerometer(Vector3(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z).rotated(Vector3(0, 0, 1), Math::PI));
DisplayServerAppleEmbedded::get_singleton()->update_magnetometer(Vector3(magnetic.x, magnetic.y, magnetic.z).rotated(Vector3(0, 0, 1), Math::PI));
DisplayServerAppleEmbedded::get_singleton()->update_gyroscope(Vector3(rotation.x, rotation.y, rotation.z).rotated(Vector3(0, 0, 1), Math::PI));
+ DisplayServerAppleEmbedded::get_singleton()->update_device_orientation(Quaternion(Vector3(0, 0, 1), Math::PI) * device_orientation);
} break;
default: { // assume portrait
DisplayServerAppleEmbedded::get_singleton()->update_gravity(Vector3(gravity.x, gravity.y, gravity.z));
DisplayServerAppleEmbedded::get_singleton()->update_accelerometer(Vector3(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z));
DisplayServerAppleEmbedded::get_singleton()->update_magnetometer(Vector3(magnetic.x, magnetic.y, magnetic.z));
DisplayServerAppleEmbedded::get_singleton()->update_gyroscope(Vector3(rotation.x, rotation.y, rotation.z));
+ DisplayServerAppleEmbedded::get_singleton()->update_device_orientation(device_orientation);
} break;
}
}
diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp
index 6a2b7b5c8ac..b818d433278 100644
--- a/platform/android/display_server_android.cpp
+++ b/platform/android/display_server_android.cpp
@@ -879,6 +879,10 @@ void DisplayServerAndroid::process_gyroscope(const Vector3 &p_gyroscope) {
Input::get_singleton()->set_gyroscope(p_gyroscope);
}
+void DisplayServerAndroid::process_device_orientation(const Quaternion &p_orientation) {
+ Input::get_singleton()->set_device_orientation(p_orientation);
+}
+
void DisplayServerAndroid::_mouse_update_mode() {
DisplayServerEnums::MouseMode wanted_mouse_mode = mouse_mode_override_enabled
? mouse_mode_override
diff --git a/platform/android/display_server_android.h b/platform/android/display_server_android.h
index 953093ea62c..682dde11728 100644
--- a/platform/android/display_server_android.h
+++ b/platform/android/display_server_android.h
@@ -231,6 +231,7 @@ public:
void process_gravity(const Vector3 &p_gravity);
void process_magnetometer(const Vector3 &p_magnetometer);
void process_gyroscope(const Vector3 &p_gyroscope);
+ void process_device_orientation(const Quaternion &p_orientation);
void _cursor_set_shape_helper(DisplayServerEnums::CursorShape p_shape, bool force = false);
virtual void cursor_set_shape(DisplayServerEnums::CursorShape p_shape) override;
diff --git a/platform/android/java/lib/src/main/java/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/main/java/org/godotengine/godot/Godot.kt
index dba04e36d12..6319973bdf5 100644
--- a/platform/android/java/lib/src/main/java/org/godotengine/godot/Godot.kt
+++ b/platform/android/java/lib/src/main/java/org/godotengine/godot/Godot.kt
@@ -144,6 +144,12 @@ class Godot private constructor(val context: Context) {
private val gyroscopeEnabled = AtomicBoolean(false)
private val mGyroscope: Sensor? by lazy { mSensorManager?.getDefaultSensor(Sensor.TYPE_GYROSCOPE) }
+ private val deviceOrientationEnabled = AtomicBoolean(false)
+ private val rotationVector: Sensor? by lazy {
+ mSensorManager?.getDefaultSensor(Sensor.TYPE_GAME_ROTATION_VECTOR)
+ ?: mSensorManager?.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)
+ }
+
val isXrRuntime: Boolean by lazy { hasFeature("xr_runtime") }
val tts = GodotTTS(context)
@@ -714,6 +720,9 @@ class Godot private constructor(val context: Context) {
if (gyroscopeEnabled.get() && mGyroscope != null) {
mSensorManager?.registerListener(godotInputHandler, mGyroscope, SensorManager.SENSOR_DELAY_GAME)
}
+ if (deviceOrientationEnabled.get() && rotationVector != null) {
+ mSensorManager?.registerListener(godotInputHandler, rotationVector, SensorManager.SENSOR_DELAY_GAME)
+ }
}
internal fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) {
@@ -867,6 +876,7 @@ class Godot private constructor(val context: Context) {
gravityEnabled.set(java.lang.Boolean.parseBoolean(GodotLib.getGlobal("input_devices/sensors/enable_gravity")))
gyroscopeEnabled.set(java.lang.Boolean.parseBoolean(GodotLib.getGlobal("input_devices/sensors/enable_gyroscope")))
magnetometerEnabled.set(java.lang.Boolean.parseBoolean(GodotLib.getGlobal("input_devices/sensors/enable_magnetometer")))
+ deviceOrientationEnabled.set(java.lang.Boolean.parseBoolean(GodotLib.getGlobal("input_devices/sensors/enable_device_orientation")))
runOnHostThread {
registerSensorsIfNeeded()
diff --git a/platform/android/java/lib/src/main/java/org/godotengine/godot/GodotLib.java b/platform/android/java/lib/src/main/java/org/godotengine/godot/GodotLib.java
index 1f7299fa149..7ea45bbf6d4 100644
--- a/platform/android/java/lib/src/main/java/org/godotengine/godot/GodotLib.java
+++ b/platform/android/java/lib/src/main/java/org/godotengine/godot/GodotLib.java
@@ -146,6 +146,12 @@ public class GodotLib {
*/
public static native void gyroscope(float x, float y, float z);
+ /**
+ * Forward device orientation (rotation vector) events as a quaternion.
+ * @see android.hardware.SensorEventListener#onSensorChanged(SensorEvent)
+ */
+ public static native void deviceOrientation(float x, float y, float z, float w);
+
/**
* Forward regular key events.
*/
diff --git a/platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java b/platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java
index 43e467ccf6c..8d19d1144ab 100644
--- a/platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java
+++ b/platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java
@@ -41,6 +41,7 @@ import android.content.res.Configuration;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
import android.hardware.input.InputManager;
import android.os.Build;
import android.util.Log;
@@ -799,10 +800,16 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
}
}
+ // Scratch buffer reused by onSensorChanged() to avoid per-event allocations
+ // on the sensor callback, which can fire at 50-200 Hz. Sensor events are
+ // dispatched serially to a single listener, so this does not need to be
+ // synchronized.
+ private final float[] orientationQuaternion = new float[4];
+
@Override
public void onSensorChanged(SensorEvent event) {
final float[] values = event.values;
- if (values == null || values.length != 3) {
+ if (values == null) {
return;
}
@@ -815,6 +822,38 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
updateCachedRotation();
}
+ int sensorType = event.sensor.getType();
+
+ // Rotation vector sensors return 4~5 values (quaternion), handle before the length==3 check.
+ if (sensorType == Sensor.TYPE_GAME_ROTATION_VECTOR || sensorType == Sensor.TYPE_ROTATION_VECTOR) {
+ if (values.length < 4) {
+ return;
+ }
+ SensorManager.getQuaternionFromVector(orientationQuaternion, values);
+ // quaternion from Android: [w, x, y, z], expressed in the device's
+ // natural frame. Identity pose per Android's reference frame:
+ // device lying flat, screen up, with the long edge pointing toward
+ // magnetic north. Holding the device upright is therefore *not*
+ // identity; callers should not be surprised if the quaternion is
+ // non-trivial even when the device feels "still".
+ //
+ // Deliberately NOT remapped for the current display rotation. The
+ // quaternion stays in the device's physical frame, matching iOS
+ // CMDeviceMotion.attitude (which is likewise independent of the UI
+ // orientation), so both platforms report the same orientation for
+ // the same physical pose regardless of auto-rotate.
+
+ // Pass to JNI as (x, y, z, w) matching Godot's Quaternion constructor order.
+ runnable.setOrientationEvent(orientationQuaternion[1], orientationQuaternion[2], orientationQuaternion[3], orientationQuaternion[0]);
+ godot.runOnRenderThread(runnable);
+ return;
+ }
+
+ // 3-component sensors (accelerometer, gravity, magnetometer, gyroscope).
+ if (values.length != 3) {
+ return;
+ }
+
float rotatedValue0 = 0f;
float rotatedValue1 = 0f;
float rotatedValue2 = 0f;
diff --git a/platform/android/java/lib/src/main/java/org/godotengine/godot/input/InputEventRunnable.java b/platform/android/java/lib/src/main/java/org/godotengine/godot/input/InputEventRunnable.java
index a282791b2e2..051071a64aa 100644
--- a/platform/android/java/lib/src/main/java/org/godotengine/godot/input/InputEventRunnable.java
+++ b/platform/android/java/lib/src/main/java/org/godotengine/godot/input/InputEventRunnable.java
@@ -113,7 +113,8 @@ final class InputEventRunnable implements Runnable {
JOYSTICK_HAT,
JOYSTICK_CONNECTION_CHANGED,
KEY,
- SENSOR
+ SENSOR,
+ DEVICE_ORIENTATION
}
private EventType currentEventType = null;
@@ -257,6 +258,19 @@ final class InputEventRunnable implements Runnable {
this.rotatedValue2 = rotatedValue2;
}
+ // Device orientation event fields and setter
+ private float orientX;
+ private float orientY;
+ private float orientZ;
+ private float orientW;
+ void setOrientationEvent(float x, float y, float z, float w) {
+ this.currentEventType = EventType.DEVICE_ORIENTATION;
+ this.orientX = x;
+ this.orientY = y;
+ this.orientZ = z;
+ this.orientW = w;
+ }
+
@Override
public void run() {
try {
@@ -337,6 +351,10 @@ final class InputEventRunnable implements Runnable {
break;
}
break;
+
+ case DEVICE_ORIENTATION:
+ GodotLib.deviceOrientation(orientX, orientY, orientZ, orientW);
+ break;
}
} finally {
recycle();
diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp
index e0ce2d82bca..7663ad3d032 100644
--- a/platform/android/java_godot_lib_jni.cpp
+++ b/platform/android/java_godot_lib_jni.cpp
@@ -89,6 +89,7 @@ static Vector3 accelerometer;
static Vector3 gravity;
static Vector3 magnetometer;
static Vector3 gyroscope;
+static Quaternion device_orientation;
static void _terminate(JNIEnv *env, bool p_restart = false) {
if (step.get() == STEP_TERMINATED) {
@@ -346,6 +347,7 @@ JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env,
dsa->process_gravity(gravity);
dsa->process_magnetometer(magnetometer);
dsa->process_gyroscope(gyroscope);
+ dsa->process_device_orientation(device_orientation);
}
bool should_swap_buffers = false;
@@ -497,6 +499,10 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env
gyroscope = Vector3(x, y, z);
}
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_deviceOrientation(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z, jfloat w) {
+ device_orientation = Quaternion(x, y, z, w);
+}
+
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jclass clazz) {
if (step.get() <= STEP_SETUP) {
return;
diff --git a/platform/android/java_godot_lib_jni.h b/platform/android/java_godot_lib_jni.h
index 2fea1a2e2bf..1c30e793d1c 100644
--- a/platform/android/java_godot_lib_jni.h
+++ b/platform/android/java_godot_lib_jni.h
@@ -57,6 +57,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gravity(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnetometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_deviceOrientation(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z, jfloat w);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jclass clazz);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jclass clazz);
JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv *env, jclass clazz, jstring path);