move Normalize functions to MathHelper

pull/17/head
cosmonaut 2022-03-21 16:21:22 -07:00
parent 8aa64fc664
commit d8f9f53dac
2 changed files with 12 additions and 7 deletions

View File

@ -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;
}
}
}

View File

@ -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