mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-13 15:25:08 +01:00
- Joystick input is now processed using polar coordinates, resulting in better accuracy and fixing tons of issues (Fixes #135, #138, #186 & #180) - Camera movement is now way smoother by including the previous stick values in the calculation (Fixes #217 & #167) - updateMappings() is now called asyncronously (Closes #219)
24 lines
871 B
Java
24 lines
871 B
Java
package eu.midnightdust.midnightcontrols.client.util;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
public class MathUtil {
|
|
public static class PolarUtil {
|
|
public float polarX;
|
|
public float polarY;
|
|
public PolarUtil() {}
|
|
|
|
public void calculate(float x, float y, float speedFactor) {
|
|
calculate(x, y, speedFactor, 0);
|
|
}
|
|
public void calculate(float x, float y, float speedFactor, double deadZone) {
|
|
double inputR = Math.pow(x, 2) + Math.pow(y, 2);
|
|
inputR = (Math.abs(speedFactor * MathHelper.clamp(inputR,0.f,1.f)));
|
|
inputR = inputR < deadZone ? 0f : (inputR-deadZone) / (1f-deadZone);
|
|
double inputTheta = Math.atan2(y, x);
|
|
polarX = (float) (inputR *Math.cos(inputTheta));
|
|
polarY = (float) (inputR *Math.sin(inputTheta));
|
|
}
|
|
}
|
|
}
|