-
Notifications
You must be signed in to change notification settings - Fork 0
/
callbacks.cpp
134 lines (125 loc) · 3.22 KB
/
callbacks.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
#include "callbacks.hpp"
using namespace std;
// keyboard callback function
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 27: // ESC
cout << "Exiting..." << endl;
exit(0);
break;
case 'c':
cam.toggleMode();
// store mouse location for fps
// button set to -1 to not cause any Orbit mode rotations
cam.storeMouseLoc(x, y, -1);
break;
case 'r':
body.reset();
break;
default:
break;
}
if (cam.getMode() == cam.CAM_FPS)
{
switch (key)
{
case 'w':
cam.mov_forward(1.0);
break;
case 'a':
cam.mov_sideways(-1.0);
break;
case 's':
cam.mov_forward(-1.0);
break;
case 'd':
cam.mov_sideways(1.0);
break;
case 'q':
cam.mov_upward(-1.0);
break;
case 'e':
cam.mov_upward(1.0);
break;
case '+':
cam.changeSpeed(0.1);
break;
case '-':
cam.changeSpeed(-0.1);
break;
}
}
glutPostRedisplay();
}
// callback function for special keys (e.g. arrow keys)
void SpecialInput(int key, int x, int y)
{
if (cam.getMode() == cam.CAM_ORBIT)
{
// TODO: Add keyboard controls
switch (key)
{
case (GLUT_KEY_RIGHT):
//body.torque += vec3(0.0, 0.0, 1.0);
break;
case (GLUT_KEY_LEFT):
//body.torque += vec3(0.0, 0.0, -1.0);
break;
}
}
glutPostRedisplay();
}
// callback function for mouse press events
void mouse(int button, int state, int x, int y)
{
if (cam.getMode() == cam.CAM_ORBIT)
{
// only left click
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN
&& glutGetModifiers() != GLUT_ACTIVE_SHIFT)
{
cam.storeMouseLoc(x, y, GLUT_LEFT_BUTTON);
}
// shift + left click
else if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN
&& glutGetModifiers() == GLUT_ACTIVE_SHIFT)
{
cam.storeMouseLoc(x, y, 3);
}
// right click
else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
{
cam.storeMouseLoc(x,y, GLUT_RIGHT_BUTTON);
}
}
}
// callback function for mouse drag
void motion(int x, int y)
{
if (cam.getMode() == cam.CAM_ORBIT)
{
cam.rot_mouse(x, y);
cam.storeMouseLoc(x, y, cam.getMouseButton());
glutPostRedisplay();
}
}
// callback function for mouse motion without drag
void passiveMotion(int x, int y)
{
if (cam.getMode() == cam.CAM_FPS)
{
cam.rot_fps(x, y);
cam.storeMouseLoc(x, y, -1);
glutPostRedisplay();
}
}
// callback for change in window shape
void reshape(int width, int height)
{
glViewport(0, 0, (GLsizei) width, (GLsizei) height);
cam.storeScreenSize(width, height);
cam.update();
glutPostRedisplay();
}