move Normalize functions to MathHelper
parent
8aa64fc664
commit
d8f9f53dac
|
@ -89,14 +89,14 @@ namespace MoonWorks.Input
|
||||||
foreach (var (sdlEnum, axis) in EnumToAxis)
|
foreach (var (sdlEnum, axis) in EnumToAxis)
|
||||||
{
|
{
|
||||||
var sdlAxisValue = SDL.SDL_GameControllerGetAxis(Handle, sdlEnum);
|
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);
|
axis.Update(axisValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var (sdlEnum, trigger) in EnumToTrigger)
|
foreach (var (sdlEnum, trigger) in EnumToTrigger)
|
||||||
{
|
{
|
||||||
var sdlAxisValue = SDL.SDL_GameControllerGetAxis(Handle, sdlEnum);
|
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);
|
trigger.Update(axisValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,10 +177,5 @@ namespace MoonWorks.Input
|
||||||
{
|
{
|
||||||
return MoonWorks.Conversions.ByteToBool(SDL.SDL_GameControllerGetButton(Handle, button));
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -331,6 +331,16 @@ namespace MoonWorks.Math
|
||||||
return angle;
|
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
|
#endregion
|
||||||
|
|
||||||
#region Internal Static Methods
|
#region Internal Static Methods
|
||||||
|
|
Loading…
Reference in New Issue