-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.c
64 lines (57 loc) · 2.32 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
#include "objects.h"
#include "renderer.h"
#include "arg_parser.h"
#include "xtrig.h"
#include "utils.h" // UT_MAX
#include <math.h> // sin, cos
#include <unistd.h> // for usleep
#include <stdlib.h> // exit
#include <time.h> // time
#include <signal.h> // signal
/* Callback that clears the screen and makes the cursor visible when the user hits Ctr+C */
static void interrupt_handler(int int_num) {
if (int_num == SIGINT) {
render_end();
exit(SIGINT);
}
}
int main(int argc, char** argv) {
arg_parse(argc, argv);
// make sure we end gracefully if the user hits Ctr+C
signal(SIGINT, interrupt_handler);
render_init();
ftrig_init_lut();
mesh_t* shape = obj_mesh_from_file(g_mesh_file, g_cx, g_cy, g_cz, g_width, g_height, g_depth);
// spinning parameters in case random rotation was selected
#ifndef _WIN32
const float random_rot_speed_x = 0.002, random_rot_speed_y = 0.002, random_rot_speed_z = 0.002;
const float amplitude_x = 4.25, amplitude_y = 4.25, amplitude_z = 4.25;
#else
// make it spin faster on Windows because terminal refresh functions are sluggish there
const float random_rot_speed_x = 0.01, random_rot_speed_y = 0.01, random_rot_speed_z = 0.01;
const float amplitude_x = 6.0, amplitude_y = 6.0, amplitude_z = 6.0;
#endif
for (size_t t = 0; t < g_max_iterations; ++t) {
if (g_use_random_rotation)
obj_mesh_rotate_to(shape, amplitude_x*fsin(random_rot_speed_x*fsin(random_rot_speed_x*t) + 2*random_bias_x),
amplitude_y*fsin(random_rot_speed_y*random_bias_y*t + 2*random_bias_y),
amplitude_z*fsin(random_rot_speed_z*random_bias_z*t + 2*random_bias_z));
else
obj_mesh_rotate_to(shape, g_rot_speed_x/20*t, g_rot_speed_y/20*t, g_rot_speed_z/20*t);
if (g_bounce_every != 0) {
if ((t % (2*g_bounce_every)) >= g_bounce_every)
obj_mesh_translate_by(shape, g_move_x, g_move_y, g_move_z);
else
obj_mesh_translate_by(shape, -g_move_x, -g_move_y, -g_move_z);
}
render_write_shape(shape);
render_flush();
#ifndef _WIN32
// nanosleep does not work on Windows
nanosleep((const struct timespec[]) {{0, (int)(1.0 / g_fps * 1e9)}}, NULL);
#endif
}
obj_mesh_free(shape);
render_end();
return 0;
}