Disable deadzone scaling because it's pretty broken

This commit is contained in:
Cameron Gutman 2015-01-25 17:02:00 -05:00
parent 52e5817327
commit 6de5cf8925

View File

@ -3,8 +3,6 @@ package com.limelight.nvstream.input;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import com.limelight.utils.Vector2d;
public class ControllerPacket extends InputPacket { public class ControllerPacket extends InputPacket {
public static final byte[] HEADER = public static final byte[] HEADER =
{ {
@ -48,11 +46,11 @@ public class ControllerPacket extends InputPacket {
public static final short PACKET_LENGTH = PAYLOAD_LENGTH + public static final short PACKET_LENGTH = PAYLOAD_LENGTH +
InputPacket.HEADER_LENGTH; InputPacket.HEADER_LENGTH;
// This is the highest value that is read as zero on the PC
public static final short MIN_MAGNITUDE = 7000;
// Set this flag if you want ControllerPacket to handle scaling for you // Set this flag if you want ControllerPacket to handle scaling for you
// Note: You MUST properly handle deadzones to use this flag // You MUST properly handle deadzones to use this flag
//
// Note: This flag does nothing right now. It causes some controllers
// to behave badly.
public static boolean enableAxisScaling = false; public static boolean enableAxisScaling = false;
short buttonFlags; short buttonFlags;
@ -73,46 +71,11 @@ public class ControllerPacket extends InputPacket {
this.leftTrigger = leftTrigger; this.leftTrigger = leftTrigger;
this.rightTrigger = rightTrigger; this.rightTrigger = rightTrigger;
Vector2d leftStick = handleDeadZone(leftStickX, leftStickY); this.leftStickX = leftStickX;
this.leftStickX = (short) leftStick.getX(); this.leftStickY = leftStickY;
this.leftStickY = (short) leftStick.getY();
Vector2d rightStick = handleDeadZone(rightStickX, rightStickY); this.rightStickX = rightStickX;
this.rightStickX = (short) rightStick.getX(); this.rightStickY = rightStickY;
this.rightStickY = (short) rightStick.getY();
}
private static Vector2d inputVector = new Vector2d();
private static Vector2d normalizedInputVector = new Vector2d();
// This function is NOT THREAD SAFE!
private static Vector2d handleDeadZone(short x, short y) {
// Get out fast if we're in the dead zone
if (x == 0 && y == 0) {
return Vector2d.ZERO;
}
// Reinitialize our cached Vector2d object
inputVector.initialize(x, y);
if (enableAxisScaling) {
// Remember our original magnitude for scaling later
double magnitude = inputVector.getMagnitude();
// Scale to hit a minimum magnitude
inputVector.getNormalized(normalizedInputVector);
normalizedInputVector.setX(normalizedInputVector.getX() * MIN_MAGNITUDE);
normalizedInputVector.setY(normalizedInputVector.getY() * MIN_MAGNITUDE);
// Now scale the rest of the way
normalizedInputVector.scalarMultiply((32766.0 / MIN_MAGNITUDE) / (32768.0 / magnitude));
return normalizedInputVector;
}
else {
return inputVector;
}
} }
@Override @Override