2022-07-12 23:09:23 +00:00
|
|
|
using MoonWorks.Math;
|
|
|
|
using SDL2;
|
|
|
|
|
2022-03-18 18:46:44 +00:00
|
|
|
namespace MoonWorks.Input
|
|
|
|
{
|
2023-09-14 18:23:04 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Represents a specific joystick direction on a gamepad.
|
|
|
|
/// </summary>
|
2022-03-18 18:46:44 +00:00
|
|
|
public class Axis
|
|
|
|
{
|
2022-07-13 18:53:09 +00:00
|
|
|
public Gamepad Parent { get; }
|
2022-07-12 23:09:23 +00:00
|
|
|
SDL.SDL_GameControllerAxis SDL_Axis;
|
|
|
|
|
|
|
|
public AxisCode Code { get; private set; }
|
|
|
|
|
2022-03-18 18:58:10 +00:00
|
|
|
/// <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(
|
2022-07-13 18:53:09 +00:00
|
|
|
Gamepad parent,
|
2022-07-12 23:09:23 +00:00
|
|
|
AxisCode code,
|
|
|
|
SDL.SDL_GameControllerAxis sdlAxis
|
|
|
|
) {
|
2022-07-13 18:53:09 +00:00
|
|
|
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(
|
2022-07-13 18:53:09 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|