-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathControl.cpp
More file actions
52 lines (47 loc) · 864 Bytes
/
Control.cpp
File metadata and controls
52 lines (47 loc) · 864 Bytes
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
#include "Control.h"
Controls::Controls()
{
w = a = s = d = space = rmb = lmb = false;
xRotation = 0.0;
yRotation = 0.0;
lastX = 0.0;
lastY = 0.0;
}
void Controls::interpretKey(int keycode, int action)
{
switch (keycode)
{
case 17:
w = action != 0;
break;
case 30:
a = action != 0;
break;
case 31:
s = action != 0;
break;
case 32:
d = action != 0;
break;
case 57:
space = action != 0;
break;
default:
break;
}
}
void Controls::interpretMouseButton(int button, int action)
{
if (button == 0 && action == 1)
lmb = true;
if (button == 1 && action == 1)
rmb = true;
}
void Controls::interpretMouseMove(double x, double y)
{
xRotation += (x-lastX) / 600.0;
float potentialY = yRotation + (-y + lastY) / 700.0;
yRotation = potentialY < -1.5708 || potentialY > 1.5708 ? yRotation : potentialY;
lastX = x;
lastY = y;
}