-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
122 lines (110 loc) · 2.71 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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "matrix.h"
#include "ml6.h"
#include "display.h"
#include "draw.h"
void parse_nums(double vals[], char buffer[]){
char *prev, *curr = buffer;
int i = 0;
while(curr){
prev = strsep(&curr, " ");
sscanf(prev, "%lf", &vals[i]);
i++;
}
}
int main(){
struct matrix *points = new_matrix(4, 1);
struct matrix *transform = new_matrix(4, 4);
ident(transform);
char input[64];
char command;
double args[6];
screen s;
color c;
c.green = 128;
clear_screen(s);
while(1){
fgets(input, sizeof(input), stdin);
*(strchr(input, '\n')) = 0;
printf("\tCommand Read\n");
command = input[0];
if(command == 'q')
break;
else if(command == 'w'){
printf("\tClearing\n");
free_matrix(transform);
free_matrix(points);
points = new_matrix(4, 1);
transform = new_matrix(4, 4);
ident(transform);
}
else if(command == 'i'){
printf("\tCreating Identity\n");
ident(transform);
}
else if(command == 'a'){
printf("\tApplying\n");
matrix_mult(transform, points);
}
else if(command == 'v'){
printf("\tDisplaying\n");
clear_screen(s);
draw_lines(points, s, c);
display(s);
}
else{
fgets(input, sizeof(input), stdin);
*(strchr(input, '\n')) = 0;
if(command != 'g')
parse_nums(args, input);
if(command == 'l'){
printf("\tLine\n");
add_edge(points, args[0], args[1], args[2], args[3], args[4], args[5]);
}
else if(command == 's'){
printf("\tScaling\n");
matrix_mult(make_scale(args[0], args[1], args[2]), transform);
}
else if(command == 't'){
printf("\tTranslating\n");
matrix_mult(make_translate(args[0], args[1], args[2]), transform);
}
else if(command == 'x'){
printf("\tRotating in X\n");
matrix_mult(make_rotX(args[0]), transform);
}
else if(command == 'y'){
printf("\tRotating in Y\n");
matrix_mult(make_rotY(args[0]), transform);
}
else if(command == 'z'){
printf("\tRotating in Z\n");
matrix_mult(make_rotZ(args[0]), transform);
}
else if(command == 'c'){
printf("\tCircle\n");
render_circle(points, args[0], args[1], args[2], args[3]);
}
else if(command == 'm'){
printf("\tMunchkin\n");
render_sphere_mesh(points, args[0], args[1], args[2], .05);
}
else if(command == 'd'){
printf("\tDoughnut\n");
render_torus_mesh(points, args[0], args[1], args[2], args[3], .05);
}
else if(command == 'g'){
printf("\tSaving\n");
clear_screen(s);
draw_lines(points, s, c);
save_extension(s, input);
}
}
}
free_matrix(points);
free_matrix(transform);
return 42;
}