-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.c
48 lines (40 loc) · 782 Bytes
/
input.c
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
#include "input.h"
void initInput(int autoInit)
{
memset(&input, 0, sizeof(Input));
if (autoInit)
{
glutKeyboardFunc(keyDown);
glutKeyboardUpFunc(keyUp);
glutSpecialFunc(specialKeyDown);
glutSpecialUpFunc(specialKeyUp);
glutMouseFunc(mouseClick);
}
}
void keyDown(unsigned char key, int x, int y)
{
input.keys[key] = 1;
}
void keyUp(unsigned char key, int x, int y)
{
input.keys[key] = 0;
}
void specialKeyDown(int key, int x, int y)
{
input.specialKeys[key] = 1;
}
void specialKeyUp(int key, int x, int y)
{
input.specialKeys[key] = 0;
}
void mouseClick(GLint button, GLint state, GLint x, GLint y)
{
input.mouse.keys[button] = !state;
input.mouse.x = x;
input.mouse.y = y;
}
void moveMouse(GLint x, GLint y)
{
input.mouse.x = x;
input.mouse.y = y;
}