-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputManager.cpp
154 lines (118 loc) · 2.71 KB
/
InputManager.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <stdio.h>
#include "InputManager.h"
#include "GLManager.h"
#include <GL/glut.h>
#include "externs.h"
int InputManager::keys[KEY_COUNT];
int InputManager::ops[OP_COUNT];
int InputManager::mouse_x, InputManager::mouse_y;
void InputManager::init() {
for (int i = 0; i < KEY_COUNT; i++) {
keys[i] = KEY_OFF;
}
mouse_x = KEY_UNDEF;
mouse_y = KEY_UNDEF;
for (int i = 0; i < OP_COUNT; i++) {
ops[i] = KEY_OFF;
}
ops[MUSIC_MODE] = KEY_ON;
ops[SOUND_MODE] = KEY_ON;
}
void InputManager::keyboardFunc(unsigned char key, int mouse_x, int mouse_y) {
InputManager::setKeyState(key, KEY_ON);
InputManager::setOpState((int) key);
}
void InputManager::keyboardUpFunc(unsigned char key, int mouse_x, int mouse_y) {
InputManager::setKeyState(key, KEY_OFF);
}
void InputManager::keyboardSpecialFunc(int key, int mouse_x, int mouse_y) {
switch (key) {
case GLUT_KEY_F1:
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
break;
case GLUT_KEY_F2:
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
break;
}
}
void InputManager::mouseButtons(int button, int state, int xx, int yy) {
}
void InputManager::mouseMotion(int xx, int yy) {
static bool done = false;
if (!done) {
keys[MOUSE_OFF_X] += xx - g_win_half_w;
keys[MOUSE_OFF_Y] += yy - g_win_half_h;
keys[MOUSE_X] = xx;
keys[MOUSE_Y] = yy;
glutWarpPointer(g_win_half_w, g_win_half_h);
}
done = !done;
}
int InputManager::getKeyState(KEY_CODE code) {
return keys[code];
}
int InputManager::getOpState(OP_CODE code) {
return ops[code];
}
void InputManager::resetMouseMove() {
keys[MOUSE_OFF_X] = 0;
keys[MOUSE_OFF_Y] = 0;
}
void InputManager::setOpState(int key) {
OP_CODE op_code = OP_VOID;
switch (key) {
case 'c':
case 'C':
op_code = CAMERA_MODE;
break;
case 'm':
case 'M':
op_code = MUSIC_MODE;
Sound::toogleMusic();
break;
case 'n':
case 'N':
op_code = SOUND_MODE;
break;
case 'p':
case 'P':
op_code = PROFILING_MODE;
break;
}
if (op_code != -1) {
ops[op_code] = 1 - ops[op_code];
}
}
void InputManager::setKeyState(unsigned char key, int state) {
KEY_CODE key_code = KEY_VOID;
switch (key) {
case 'a':
case 'A':
key_code = KEY_A;
break;
case 'd':
case 'D':
key_code = KEY_D;
break;
case 'w':
case 'W':
key_code = KEY_W;
break;
case 's':
case 'S':
key_code = KEY_S;
break;
case KEY_ASCII_SPACE:
key_code = KEY_SPACE;
break;
case KEY_ASCII_ESC:
exit(0);
break;
}
if (key_code != KEY_VOID)
keys[key_code] = state;
}
void InputManager::setSpecialKeyState(int key, int state) {
switch (key) {
}
}