You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Added gyroscope support to Godot and Android
This commit is contained in:
@@ -217,6 +217,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
private SensorManager mSensorManager;
|
||||
private Sensor mAccelerometer;
|
||||
private Sensor mMagnetometer;
|
||||
private Sensor mGyroscope;
|
||||
|
||||
public FrameLayout layout;
|
||||
public RelativeLayout adLayout;
|
||||
@@ -387,6 +388,8 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
||||
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
|
||||
mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);
|
||||
|
||||
result_callback = null;
|
||||
|
||||
@@ -604,6 +607,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
mView.onResume();
|
||||
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);
|
||||
GodotLib.focusin();
|
||||
if(use_immersive && Build.VERSION.SDK_INT >= 19.0){ // check if the application runs on an android 4.4+
|
||||
Window window = getWindow();
|
||||
@@ -670,6 +674,9 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
if (typeOfSensor == event.sensor.TYPE_MAGNETIC_FIELD) {
|
||||
GodotLib.magnetometer(x,y,z);
|
||||
}
|
||||
if (typeOfSensor == event.sensor.TYPE_GYROSCOPE) {
|
||||
GodotLib.gyroscope(x,y,z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public final void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
|
||||
@@ -52,6 +52,7 @@ public class GodotLib {
|
||||
public static native void touch(int what,int pointer,int howmany, int[] arr);
|
||||
public static native void accelerometer(float x, float y, float z);
|
||||
public static native void magnetometer(float x, float y, float z);
|
||||
public static native void gyroscope(float x, float y, float z);
|
||||
public static native void key(int p_scancode, int p_unicode_char, boolean p_pressed);
|
||||
public static native void joybutton(int p_device, int p_but, boolean p_pressed);
|
||||
public static native void joyaxis(int p_device, int p_axis, float p_value);
|
||||
|
||||
Reference in New Issue
Block a user