MoonWorks/src/Input/Axis.cs

38 lines
662 B
C#
Raw Permalink Normal View History

2022-07-12 23:09:23 +00:00
using MoonWorks.Math;
using SDL2;
2022-03-18 18:46:44 +00:00
namespace MoonWorks.Input
{
public class Axis
{
public Gamepad Parent { get; }
2022-07-12 23:09:23 +00:00
SDL.SDL_GameControllerAxis SDL_Axis;
public AxisCode Code { get; private set; }
/// <summary>
/// An axis value between -1 and 1.
/// </summary>
2022-03-18 18:46:44 +00:00
public float Value { get; private set; }
2022-07-12 23:09:23 +00:00
public Axis(
Gamepad parent,
2022-07-12 23:09:23 +00:00
AxisCode code,
SDL.SDL_GameControllerAxis sdlAxis
) {
Parent = parent;
2022-07-12 23:09:23 +00:00
SDL_Axis = sdlAxis;
Code = code;
}
internal void Update()
2022-03-18 18:46:44 +00:00
{
2022-07-12 23:09:23 +00:00
Value = MathHelper.Normalize(
SDL.SDL_GameControllerGetAxis(Parent.Handle, SDL_Axis),
2022-07-12 23:09:23 +00:00
short.MinValue, short.MaxValue,
-1, 1
);
2022-03-18 18:46:44 +00:00
}
}
}