-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrols.h
108 lines (98 loc) · 1.98 KB
/
controls.h
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
#ifndef CONTROLS
#define CONTROLS
#include <GL/glut.h>
#include "globals.h"
void keyboard(unsigned char key, int x, int y) {
if (key == 27)
exit(0);
else if (key == 'a') {
dude.strafeLeft();
glutPostRedisplay();
}
else if (key == 'd') {
dude.strafeRight();
glutPostRedisplay();
}
else if (key == 'z') {
dude.z-=10;
glutPostRedisplay();
}
else if (key == 'q') {
dude.o+=10;
glutPostRedisplay();
}
else if (key == 'w') {
dude.goForward();
glutPostRedisplay();
}
else if (key == 's') {
dude.goBackward();
glutPostRedisplay();
}
else if (key == 'x') {
dude.s-=5;
glutPostRedisplay();
}
else if (key == 'j') {
glutPostRedisplay();
}
else if (key == 'k') {
glutPostRedisplay();
}
else if (key == 'e') {
dude.lampState = !dude.lampState;
dude.setLamp();
glutPostRedisplay();
}
else if(key == 'o'){
oilGodMode = !oilGodMode;
glutPostRedisplay();
}
else if (key == ' ') {
dude.doSomething();
glutPostRedisplay();
}
}
void special(int key, int x, int y) {
if (key == GLUT_KEY_LEFT) {
dude.strafeLeft();
glutPostRedisplay();
}
else if (key == GLUT_KEY_RIGHT) {
dude.strafeRight();
glutPostRedisplay();
}
else if (key == GLUT_KEY_UP) {
dude.goForward();
glutPostRedisplay();
}
else if (key == GLUT_KEY_DOWN) {
dude.goBackward();
glutPostRedisplay();
}
else if (key == GLUT_KEY_END) {
dude.s += 5;
glutPostRedisplay();
}
}
void mouseMove(int x, int y)
{
if(!dude.mouseWarp)
{
int centerX = width / 2;
int centerY = height / 2;
int deltaX = -1 * (x - centerX);
int deltaY = -1 * (y - centerY);
dude.o += deltaX;
if(dude.s + deltaY > -90 && dude.s + deltaY < 90)
dude.s += deltaY;
dude.mouseWarp = true;
glutWarpPointer(centerX, centerY);
}
else
{
dude.mouseWarp = false;
}
glutPostRedisplay();
}
#endif