mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-13 23:00:45 -04:00
Better deadzones for self calibrating devices
This commit is contained in:
parent
a81441d60a
commit
4c71e66f48
@ -46,7 +46,6 @@ public class Gamepad {
|
|||||||
private float lastVerticalValue = 0.0f;
|
private float lastVerticalValue = 0.0f;
|
||||||
|
|
||||||
private final double mouseMaxAcceleration = 2f;
|
private final double mouseMaxAcceleration = 2f;
|
||||||
private double acceleration = 0.0f;
|
|
||||||
|
|
||||||
private double mouseMagnitude;
|
private double mouseMagnitude;
|
||||||
private double mouseAngle;
|
private double mouseAngle;
|
||||||
|
@ -20,7 +20,7 @@ public class GamepadJoystick {
|
|||||||
public static final int DIRECTION_SOUTH = 6;
|
public static final int DIRECTION_SOUTH = 6;
|
||||||
public static final int DIRECTION_SOUTH_EAST = 7;
|
public static final int DIRECTION_SOUTH_EAST = 7;
|
||||||
|
|
||||||
private float deadzone;
|
private final InputDevice device;
|
||||||
|
|
||||||
private final int verticalAxis;
|
private final int verticalAxis;
|
||||||
private final int horizontalAxis;
|
private final int horizontalAxis;
|
||||||
@ -28,13 +28,9 @@ public class GamepadJoystick {
|
|||||||
public GamepadJoystick(int horizontalAxis, int verticalAxis, InputDevice device){
|
public GamepadJoystick(int horizontalAxis, int verticalAxis, InputDevice device){
|
||||||
this.verticalAxis = verticalAxis;
|
this.verticalAxis = verticalAxis;
|
||||||
this.horizontalAxis = horizontalAxis;
|
this.horizontalAxis = horizontalAxis;
|
||||||
|
this.device = device;
|
||||||
|
|
||||||
//Some controllers aren't recognized as such by android, so we fallback to a default value of 0.2
|
|
||||||
//And some others don't report their MotionRange. This was the case with the xbox one series S controller.
|
|
||||||
|
|
||||||
//try { deadzone = Math.max(device.getMotionRange(verticalAxis).getFlat(), device.getMotionRange(horizontalAxis).getFlat()) * 1.9f; }
|
|
||||||
//catch (NullPointerException e){ deadzone = 0.2f; }
|
|
||||||
deadzone = 0.2f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getAngleRadian(MotionEvent event){
|
public double getAngleRadian(MotionEvent event){
|
||||||
@ -71,6 +67,7 @@ public class GamepadJoystick {
|
|||||||
//to make it seem like there was no deadzone in the first place
|
//to make it seem like there was no deadzone in the first place
|
||||||
|
|
||||||
double magnitude = getMagnitude(event);
|
double magnitude = getMagnitude(event);
|
||||||
|
float deadzone = getDeadzone();
|
||||||
if (magnitude < deadzone) return 0;
|
if (magnitude < deadzone) return 0;
|
||||||
|
|
||||||
return (float) ( (event.getAxisValue(axis) / magnitude) * ((magnitude - deadzone) / (1 - deadzone)) );
|
return (float) ( (event.getAxisValue(axis) / magnitude) * ((magnitude - deadzone) / (1 - deadzone)) );
|
||||||
@ -83,12 +80,20 @@ public class GamepadJoystick {
|
|||||||
|
|
||||||
|
|
||||||
public int getHeightDirection(MotionEvent event){
|
public int getHeightDirection(MotionEvent event){
|
||||||
if(getMagnitude(event) <= deadzone) return DIRECTION_NONE;
|
if(getMagnitude(event) <= getDeadzone()) return DIRECTION_NONE;
|
||||||
return ((int) ((getAngleDegree(event)+22.5)/45)) % 8;
|
return ((int) ((getAngleDegree(event)+22.5)/45)) % 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the dedzone from the Input device linked to this joystick
|
||||||
|
* Some controller aren't supported, fallback to 0.2 if that the case.
|
||||||
|
* @return the deadzone of the joystick
|
||||||
|
*/
|
||||||
public float getDeadzone() {
|
public float getDeadzone() {
|
||||||
return deadzone;
|
try{
|
||||||
|
return Math.max(device.getMotionRange(horizontalAxis).getFlat() * 1.5f, 0.15f);
|
||||||
|
}catch (Exception e){
|
||||||
|
return 0.2f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user