예제 #1
0
        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
        }
예제 #2
0
        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));
        }
예제 #3
0
        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;
        }
예제 #4
0
        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));
        }