From 4de6cac0b7a08f2ed052cf5f006ce3594c1d4f2a Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Mon, 24 Jul 2023 20:58:19 -0600 Subject: [PATCH] update input qt --- simple64-input-qt/main.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/simple64-input-qt/main.cpp b/simple64-input-qt/main.cpp index 20bfba6..1a26187 100644 --- a/simple64-input-qt/main.cpp +++ b/simple64-input-qt/main.cpp @@ -555,6 +555,20 @@ EXPORT void CALL ControllerCommand(int Control, unsigned char *Command) } } +void boundAxis(double* x, double* y) { + double radius = 95.0; // this is roughly the maxium diagonal distance of the controller + + // Calculate the distance from the origin (0, 0) + double distance = sqrt((*x) * (*x) + (*y) * (*y)); + + // If the distance is greater than the radius, scale the coordinates + if (distance > radius) { + double scaleFactor = radius / distance; + *x *= scaleFactor; + *y *= scaleFactor; + } +} + int modifyAxisValue(int axis_value, int Control, int direction) { axis_value = ((abs(axis_value) - controller[Control].deadzone) * MAX_AXIS_VALUE) / controller[Control].range; @@ -744,6 +758,12 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys ) setAxis(Control, 0/*X_AXIS*/, Keys, "AxisRight", 1); setAxis(Control, 1/*Y_AXIS*/, Keys, "AxisUp", 1); setAxis(Control, 1/*Y_AXIS*/, Keys, "AxisDown", -1); + + double boundX = Keys->X_AXIS; + double boundY = Keys->Y_AXIS; + boundAxis(&boundX, &boundY); + Keys->X_AXIS = round(boundX); + Keys->Y_AXIS = round(boundY); } static int setupVosk()