private static float GetDeltaTriggers(GamepadModel model) { var lTrigger = ScalingUtils.ByteToFloat(model.LeftTrigger); var rTrigger = ScalingUtils.ByteToFloat(model.RightTrigger); var deltaTriggers = rTrigger - lTrigger; return(ScalingUtils.SymmetricalConstrain(deltaTriggers, 1.0f) * 800.0f); // -800:800 range }
public static byte PerformLookup(byte value) { if (_lookupTable is null) { CalculateLookups(); } // Can safely cast to byte, cause of the constrain of 255 return((byte)ScalingUtils.ConstrainNonnegative(_lookupTable[value], 255)); }
private static void CalculateLookups() { var lut = new short[OutputRange + 1]; const double coefficientA = -CoefficientB; var coefficientC = Math.Log((OutputRange - coefficientA) / CoefficientB) / OutputRange; for (var i = 0; i < OutputRange + 1; i++) { lut[i] = (short)Math.Ceiling(coefficientA + CoefficientB * Math.Exp(coefficientC * i)); lut[i] = ScalingUtils.ConstrainNonnegative(lut[i], OutputRange); } _lookupTable = lut; }
private static float GetDirection(GamepadModel model) { const float deadZone = 0.2f; var leftRightStick = ScalingUtils.ShortToFloat(model.LeftThumbStick.Horizontal); if (leftRightStick <= deadZone && leftRightStick >= -deadZone) { leftRightStick = 0; } leftRightStick *= 0.1f; // -0.1:0.1 range return(ScalingUtils.SymmetricalConstrain(leftRightStick, 0.1f)); }