You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently implementing gamepad support for the GUI of ESP Easy (OS for IoT). I know that there's a discussion regarding adding events for button presses etc. so I will not discuss that here. This is what I've done to get the direction of the joystick + its thrust (0...1).
thrust = function (x, y) {
x = Math.floor(x * 100)/100;
y = Math.floor(y * 100)/100;
if (x === 0 && y === 0) {
return NaN;
}
if (x === 0) {
return Math.abs(y);
}
if (y === 0) {
return Math.abs(x);
}
let xy = Math.sqrt(Math.pow(x,2) + Math.pow(y, 2));
xy = Math.floor(xy * 100)/100;
return (xy > 1 ? 1 : xy);
};
direction = function (x, y, zeroPoint) {
x = Math.floor(x * 100)/100;
y = Math.floor(y * 100)/100;
if (x === 0 && y === 0) {
return NaN;
}
let degree = (Math.atan2(y, x) > 0 ? Math.atan2(y, x) : (2*Math.PI + Math.atan2(y, x))) * 360 / (2*Math.PI);
if (zeroPoint === "up") {
degree = degree - 270;
return (degree < 0 ? degree + 360 : degree);
}
if (zeroPoint === "down") {
degree = degree - 90;
return (degree < 0 ? degree + 360 : degree);
}
if (zeroPoint === "left") {
degree = degree - 180;
return (degree < 0 ? degree + 360 : degree);
}
// right just return the degrees...
return degree;
};
It would be nice to get this info from the API. Perhaps also the 3D vector of the joystick position. Advanced data like acceleration and spin might also be of interest?
The text was updated successfully, but these errors were encountered:
I'm currently implementing gamepad support for the GUI of ESP Easy (OS for IoT). I know that there's a discussion regarding adding events for button presses etc. so I will not discuss that here. This is what I've done to get the direction of the joystick + its thrust (0...1).
It would be nice to get this info from the API. Perhaps also the 3D vector of the joystick position. Advanced data like acceleration and spin might also be of interest?
The text was updated successfully, but these errors were encountered: