/
main.c
130 lines (104 loc) · 2.9 KB
/
main.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
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
#include <GL/glew.h>
#include <GL/glut.h>
#include "geometry/marching_cubes.h"
#include "configuration.h"
geometry g;
mat4_t projection;
mat4_t view;
mat4_t model;
float up[3] = {0.0f, 1.0f, 0.0f};
float center[3] = {0.0f, 0.0f,0.0f};
float eye[3] = {0.0f, 0.0f, -40.0f};
void InitGL()
{
glEnable(GL_DEPTH_TEST);
glClearColor(0.2, 0.2 , 0.6, 0.0);
projection = mat4_create(projection);
view = mat4_create(view);
model = mat4_create(model);
model = mat4_identity(model);
scan_data data = load_scan_data(filename, data_width, data_height, data_length, bit_rate);
marching_cubes(threshold, &data, debug, &g);
model = mat4_translate(model, g.center, model);
free(data.data);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
mat4_identity(view);
view = mat4_lookAt(eye, center, up, view);
render_geometry(&g, model, view, projection);
if (debug)
{
render_debug(&g, model, view, projection);
}
glutSwapBuffers();
}
void reshape(int width, int height)
{
if (height == 0)
{
height = 1;
}
glViewport(0, 0, width, height);
mat4_identity(projection);
projection = mat4_perspective(45.0f, (GLfloat) width / (GLfloat) height, 0.01f, 100000.0f , projection);
mat4_identity(view);
view = mat4_lookAt(eye, center, up, view);
}
void keyboard(unsigned char key, int x, int y)
{
float direction[3];
float rotation[16];
mat4_identity(rotation);
switch (key) {
case 'q':
vec3_subtract(center, eye, direction);
vec3_normalize(direction, direction);
vec3_add(eye, direction, eye);
break;
case 'e':
vec3_subtract(center, eye, direction);
vec3_normalize(direction, direction);
vec3_subtract(eye, direction, eye);
break;
case 'a':
mat4_rotateY(rotation, 0.1f, rotation);
mat4_multiply(rotation, model, model);
break;
case 'd':
mat4_rotateY(rotation, -0.1f, rotation);
mat4_multiply(rotation, model, model);
break;
case 'w':
mat4_rotateX(rotation, 0.1f, rotation);
mat4_multiply(rotation, model, model);
break;
case 's':
mat4_rotateX(rotation, -0.1f, rotation);
mat4_multiply(rotation, model, model);
break;
case 27:
exit(0);
default:
break;
}
}
void shutdown()
{
}
void main(int argc, char **argv)
{
parse_args(argc, argv);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(500, 500);
glutCreateWindow("Gomputer graphics ftn"); //
glewInit();
InitGL();
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
shutdown();
}