mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 16:16:04 -04:00
Gyro controls: Use an actual gyro instead of Game Rotation Vector
This commit is contained in:
parent
c8ce24aae0
commit
2b7708fedc
@ -16,11 +16,9 @@ public class GyroControl implements SensorEventListener, GrabListener {
|
|||||||
private final Sensor mSensor;
|
private final Sensor mSensor;
|
||||||
private boolean mShouldHandleEvents;
|
private boolean mShouldHandleEvents;
|
||||||
|
|
||||||
private float mLastX, mLastY;
|
|
||||||
|
|
||||||
public GyroControl(Context context) {
|
public GyroControl(Context context) {
|
||||||
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||||
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GAME_ROTATION_VECTOR);
|
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enable() {
|
public void enable() {
|
||||||
@ -39,11 +37,9 @@ public class GyroControl implements SensorEventListener, GrabListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onSensorChanged(SensorEvent sensorEvent) {
|
public void onSensorChanged(SensorEvent sensorEvent) {
|
||||||
if(mShouldHandleEvents && sensorEvent.sensor == mSensor) {
|
if(mShouldHandleEvents && sensorEvent.sensor == mSensor) {
|
||||||
CallbackBridge.mouseX += (sensorEvent.values[0]-mLastX) * LauncherPreferences.PREF_GYRO_SENSITIVITY * 1000;
|
CallbackBridge.mouseX += sensorEvent.values[0] * LauncherPreferences.PREF_GYRO_SENSITIVITY * 10;
|
||||||
CallbackBridge.mouseY += (sensorEvent.values[1]-mLastY) * LauncherPreferences.PREF_GYRO_SENSITIVITY * 1000;
|
CallbackBridge.mouseY += sensorEvent.values[1] * LauncherPreferences.PREF_GYRO_SENSITIVITY * 10;
|
||||||
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY);
|
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||||
mLastX = sensorEvent.values[0];
|
|
||||||
mLastY = sensorEvent.values[1];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public class LauncherPreferenceControlFragment extends LauncherPreferenceFragmen
|
|||||||
|
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
if(context != null) {
|
if(context != null) {
|
||||||
mGyroAvailable = ((SensorManager)context.getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_GAME_ROTATION_VECTOR) != null;
|
mGyroAvailable = ((SensorManager)context.getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null;
|
||||||
}
|
}
|
||||||
SwitchPreference gyroSwitch = findPreference("enableGyro");
|
SwitchPreference gyroSwitch = findPreference("enableGyro");
|
||||||
gyroSwitch.setVisible(mGyroAvailable);
|
gyroSwitch.setVisible(mGyroAvailable);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user