internal static void Update(IInputHandler handler, InputDeviceAxis input, float value) { if (input.Value != value) { input.Value = value; handler.OnInput(input); } }
/// <summary> /// Updates the thumb stick inputs. /// </summary> /// <param name="handler">The input handler.</param> /// <param name="xAxis">The X axis input.</param> /// <param name="yAxis">The Y axis input.</param> /// <param name="x">The X axis value.</param> /// <param name="y">The Y axis value.</param> /// <param name="deadZone">The stick dead zone.</param> private static void UpdateStick(IInputHandler handler, GamepadAxis xAxis, InputDeviceAxis yAxis, int x, int y, int deadZone) { if (Math.Sqrt((x * x) + (y * y)) < deadZone) { Update(handler, xAxis, AxisValue.Neutral); Update(handler, yAxis, AxisValue.Neutral); } else { Update(handler, xAxis, x < 0 ? AxisValue.Rescale(x, short.MinValue, -deadZone, AxisValue.Minimum, AxisValue.Neutral) : AxisValue.Rescale(x, +deadZone, short.MaxValue, AxisValue.Neutral, AxisValue.Maximum)); Update(handler, yAxis, y < 0 ? AxisValue.Rescale(y, short.MinValue, -deadZone, AxisValue.Minimum, AxisValue.Neutral) : AxisValue.Rescale(y, +deadZone, short.MaxValue, AxisValue.Neutral, AxisValue.Maximum)); } }
/// <summary> /// Called when an input device axis is moved. /// </summary> /// <param name="axis">The input device axis.</param> public virtual void OnInputDeviceAxis(InputDeviceAxis axis) { }