-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrols.cpp
More file actions
144 lines (125 loc) · 2.35 KB
/
controls.cpp
File metadata and controls
144 lines (125 loc) · 2.35 KB
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
#include <stdio.h>
#include <math.h>
#include "visuals.h"
#include "controls.h"
#ifdef _WIN32
#include "gl/glut.h"
#endif
#ifdef __linux__
#include <GL/glut.h>
#endif
int mode = SOLID;
struct rt rt = {0, 0, 0, 0, 0, 0};
static float r_step = 5;
static float t_step = 0.5;
static int last_x = 0;
static int last_y = 0;
float distance = 30;
int texture_enabled = 0;
int vres_step = 5;
int vres = vres_step;
int view = 0;
int c_sim = 0;
int ff_sim = 0;
int sim_pause = 0;
int sim_ready = 0;
int frame_step = 1;
void key_down(unsigned char key,int x,int y)
{
switch(key)
{
case 27 : exit(0); // escape
break;
case '-' : distance += 1;
break;
case '=' : distance -= 1;
break;
case 't':
if (texture_enabled) {
glDisable(GL_TEXTURE_2D);
texture_enabled = 0;
}
else {
glEnable(GL_TEXTURE_2D);
texture_enabled = 1;
}
break;
case '0': view = 0; // master model
break;
case '1': view = 1; // voxel model (cubes)
break;
case '2': view = 2; // reconstructed model
break;
case '3': view = 3; // angle histogram (master)
break;
case '4': view = 4; // angle histogram (reconstructed)
break;
case '5': view = 5; // voxel model (spheres)
break;
case '6': view = 6; // simulation
break;
case 'i': vres += vres_step;
break;
case 'd':
if (vres>vres_step) vres -= vres_step;
break;
case 'f':
ff_sim = 1; // free fall
break;
case 'c': // collision
c_sim = 1;
break;
case ',': // rewind
frame_step -= 1;
break;
case '.': // fast forward
frame_step += 1;
break;
default : break;
}
glutPostRedisplay();
}
void key_up(unsigned char key, int x, int y)
{
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_LEFT_BUTTON :
if(state == GLUT_DOWN) {
last_x = x;
last_y = y;
glutPostRedisplay();
}
break;
case 3 : distance -= 1;
break;
case 4 : distance += 1;
break;
default : break;
}
}
void mouse_motion(int x, int y)
{
float rot_x = 0.5 * (y - last_y);
float rot_y = 0.5 * (x - last_x);
last_x = x;
last_y = y;
rt.rx += rot_x;
rt.ry += rot_y;
glutPostRedisplay();
}
void menu(int choice)
{
switch (choice) {
case WIRE :
mode = WIRE;
break;
case SOLID :
mode = SOLID;
break;
default : break;
}
glutPostRedisplay();
}