From d8f9f53dac994f8ccd4ba6b05071924aa514c7b2 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 21 Mar 2022 16:21:22 -0700 Subject: [PATCH] move Normalize functions to MathHelper --- src/Input/Gamepad.cs | 9 ++------- src/Math/MathHelper.cs | 10 ++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Input/Gamepad.cs b/src/Input/Gamepad.cs index 8c82651..f025986 100644 --- a/src/Input/Gamepad.cs +++ b/src/Input/Gamepad.cs @@ -89,14 +89,14 @@ namespace MoonWorks.Input foreach (var (sdlEnum, axis) in EnumToAxis) { var sdlAxisValue = SDL.SDL_GameControllerGetAxis(Handle, sdlEnum); - var axisValue = Normalize(sdlAxisValue, short.MinValue, short.MaxValue, -1, 1); + var axisValue = MathHelper.Normalize(sdlAxisValue, short.MinValue, short.MaxValue, -1, 1); axis.Update(axisValue); } foreach (var (sdlEnum, trigger) in EnumToTrigger) { var sdlAxisValue = SDL.SDL_GameControllerGetAxis(Handle, sdlEnum); - var axisValue = Normalize(sdlAxisValue, 0, short.MaxValue, 0, 1); + var axisValue = MathHelper.Normalize(sdlAxisValue, 0, short.MaxValue, 0, 1); trigger.Update(axisValue); } } @@ -177,10 +177,5 @@ namespace MoonWorks.Input { return MoonWorks.Conversions.ByteToBool(SDL.SDL_GameControllerGetButton(Handle, button)); } - - private float Normalize(float value, short min, short max, short newMin, short newMax) - { - return ((value - min) * (newMax - newMin)) / (max - min) + newMin; - } } } diff --git a/src/Math/MathHelper.cs b/src/Math/MathHelper.cs index b98ef4c..da01c7d 100644 --- a/src/Math/MathHelper.cs +++ b/src/Math/MathHelper.cs @@ -331,6 +331,16 @@ namespace MoonWorks.Math return angle; } + public static float Normalize(float value, short min, short max, short newMin, short newMax) + { + return ((value - min) * (newMax - newMin)) / (max - min) + newMin; + } + + public static float Normalize(float value, float min, float max, float newMin, float newMax) + { + return ((value - min) * (newMax - newMin)) / (max - min) + newMin; + } + #endregion #region Internal Static Methods