1
0
forked from Clones/Controlify

✏️ Greatly improve gyro control

This commit is contained in:
isXander
2023-06-04 12:08:03 +01:00
parent 5669ea9b3a
commit daee2de327
8 changed files with 73 additions and 13 deletions

View File

@ -11,6 +11,8 @@ public class GamepadConfig extends ControllerConfig {
public float gyroLookSensitivity = 0f;
public boolean gyroRequiresButton = true;
public boolean flickStick = false;
public boolean invertGyroX = false;
public boolean invertGyroY = false;
public BuiltinGamepadTheme theme = BuiltinGamepadTheme.DEFAULT;

View File

@ -85,7 +85,9 @@ public class GamepadController extends AbstractController<GamepadState, GamepadC
}
}
GamepadState.GyroState gyroState = drivers.gyroDriver().getGyroState();
// todo: make this configurable
GamepadState.GyroState gyroState = drivers.gyroDriver().getGyroState().deadzone(0.05f);
this.absoluteGyro = this.absoluteGyro.add(gyroState);
state = new GamepadState(deadzoneAxesState, basicState.axes(), basicState.buttons(), gyroState, absoluteGyro);
}

View File

@ -209,5 +209,13 @@ public final class GamepadState implements ControllerState {
public GyroState add(GyroState other) {
return new GyroState(pitch + other.pitch, yaw + other.yaw, roll + other.roll);
}
public GyroState deadzone(float deadzone) {
return new GyroState(
Math.max(pitch - deadzone, 0) + Math.min(pitch + deadzone, 0),
Math.max(yaw - deadzone, 0) + Math.min(yaw + deadzone, 0),
Math.max(roll - deadzone, 0) + Math.min(roll + deadzone, 0)
);
}
}
}