MoonWorks/src/Input/Trigger.cs

38 lines
655 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 Trigger
{
public Gamepad Parent { get; }
2022-07-12 23:09:23 +00:00
public SDL.SDL_GameControllerAxis SDL_Axis;
public TriggerCode Code { get; }
/// <summary>
/// A trigger value between 0 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 Trigger(
Gamepad parent,
2022-07-12 23:09:23 +00:00
TriggerCode code,
SDL.SDL_GameControllerAxis sdlAxis
) {
Parent = parent;
2022-07-12 23:09:23 +00:00
Code = code;
SDL_Axis = sdlAxis;
}
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
0, short.MaxValue,
0, 1
);
2022-03-18 18:46:44 +00:00
}
}
}