You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-15 13:51:40 +00:00
Android gravity vector Godot 2.1
This commit is contained in:
@@ -216,6 +216,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
private SensorManager mSensorManager;
|
||||
private Sensor mAccelerometer;
|
||||
private Sensor mGravity;
|
||||
private Sensor mMagnetometer;
|
||||
private Sensor mGyroscope;
|
||||
|
||||
@@ -405,6 +406,8 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
|
||||
mSensorManager.registerListener(this, mGravity, 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);
|
||||
@@ -625,6 +628,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
mView.onResume();
|
||||
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);
|
||||
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);
|
||||
GodotLib.focusin();
|
||||
@@ -690,6 +694,9 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
if (typeOfSensor == event.sensor.TYPE_ACCELEROMETER) {
|
||||
GodotLib.accelerometer(x,y,z);
|
||||
}
|
||||
if (typeOfSensor == event.sensor.TYPE_GRAVITY) {
|
||||
GodotLib.gravity(x,y,z);
|
||||
}
|
||||
if (typeOfSensor == event.sensor.TYPE_MAGNETIC_FIELD) {
|
||||
GodotLib.magnetometer(x,y,z);
|
||||
}
|
||||
|
||||
@@ -33,37 +33,38 @@ package org.godotengine.godot;
|
||||
public class GodotLib {
|
||||
|
||||
|
||||
public static GodotIO io;
|
||||
public static GodotIO io;
|
||||
|
||||
static {
|
||||
static {
|
||||
System.loadLibrary("godot_android");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param width the current view width
|
||||
* @param height the current view height
|
||||
*/
|
||||
/**
|
||||
* @param width the current view width
|
||||
* @param height the current view height
|
||||
*/
|
||||
|
||||
public static native void initialize(Godot p_instance,boolean need_reload_hook,String[] p_cmdline,Object p_asset_manager);
|
||||
public static native void resize(int width, int height,boolean reload);
|
||||
public static native void newcontext(boolean p_32_bits);
|
||||
public static native void quit();
|
||||
public static native void step();
|
||||
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);
|
||||
public static native void joyhat(int p_device, int p_hat_x, int p_hat_y);
|
||||
public static native void joyconnectionchanged(int p_device, boolean p_connected, String p_name);
|
||||
public static native void focusin();
|
||||
public static native void focusout();
|
||||
public static native void audio();
|
||||
public static native void singleton(String p_name,Object p_object);
|
||||
public static native void method(String p_sname,String p_name,String p_ret,String[] p_params);
|
||||
public static native String getGlobal(String p_key);
|
||||
public static native void initialize(Godot p_instance,boolean need_reload_hook,String[] p_cmdline,Object p_asset_manager);
|
||||
public static native void resize(int width, int height,boolean reload);
|
||||
public static native void newcontext(boolean p_32_bits);
|
||||
public static native void quit();
|
||||
public static native void step();
|
||||
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 gravity(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);
|
||||
public static native void joyhat(int p_device, int p_hat_x, int p_hat_y);
|
||||
public static native void joyconnectionchanged(int p_device, boolean p_connected, String p_name);
|
||||
public static native void focusin();
|
||||
public static native void focusout();
|
||||
public static native void audio();
|
||||
public static native void singleton(String p_name,Object p_object);
|
||||
public static native void method(String p_sname,String p_name,String p_ret,String[] p_params);
|
||||
public static native String getGlobal(String p_key);
|
||||
public static native void callobject(int p_ID, String p_method, Object[] p_params);
|
||||
public static native void calldeferred(int p_ID, String p_method, Object[] p_params);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user