-
Notifications
You must be signed in to change notification settings - Fork 7
/
gamepad.cpp
66 lines (58 loc) · 1.22 KB
/
gamepad.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* author : Shuichi TAKANO
* since : Sun Jan 02 2022 18:19:28
*/
#include "gamepad.h"
#include <stdio.h>
namespace io
{
namespace
{
GamePadState currentGamePad_[2];
}
GamePadState &getCurrentGamePadState(int i)
{
return currentGamePad_[i];
}
void
GamePadState::convertButtonsFromAxis(int axisX, int axisY)
{
int x = axis[axisX];
int y = axis[axisY];
if (x < 64)
{
buttons |= Button::LEFT;
}
else if (x > 192)
{
buttons |= Button::RIGHT;
}
if (y < 64)
{
buttons |= Button::UP;
}
else if (y > 192)
{
buttons |= Button::DOWN;
}
}
void
GamePadState::convertButtonsFromHat()
{
static constexpr int table[] = {
Button::UP,
Button::UP | Button::RIGHT,
Button::RIGHT,
Button::DOWN | Button::RIGHT,
Button::DOWN,
Button::LEFT | Button::DOWN,
Button::LEFT,
Button::LEFT | Button::UP,
};
auto i = static_cast<int>(hat);
if (i < 8)
{
buttons |= table[i];
}
}
}