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
|
|
|
|
{
|
2022-07-13 18:53:09 +00:00
|
|
|
public Gamepad Parent { get; }
|
2022-07-12 23:09:23 +00:00
|
|
|
public SDL.SDL_GameControllerAxis SDL_Axis;
|
|
|
|
|
|
|
|
public TriggerCode Code { get; }
|
|
|
|
|
2022-03-18 18:58:10 +00:00
|
|
|
/// <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(
|
2022-07-13 18:53:09 +00:00
|
|
|
Gamepad parent,
|
2022-07-12 23:09:23 +00:00
|
|
|
TriggerCode code,
|
|
|
|
SDL.SDL_GameControllerAxis sdlAxis
|
|
|
|
) {
|
2022-07-13 18:53:09 +00:00
|
|
|
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(
|
2022-07-13 18:53:09 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|