-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
179 lines (162 loc) · 4.72 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX_BRUSH_SIZE ((unsigned short) 600)
#define MAX_TEXTURE_LENGTH ((unsigned char) 255)
int minX = -700, maxX = 700, size = 8, spacing = 2;
//minX - The minimum X value
//maxX - The maximum X value
//size - The size of the plot point (cod units)
//spacing - Increment through X values by this amount. Cannot be <= 0
double f(double x) {
return x * x * (x/10000); //REPLACE RETURN FUNCTION HERE
//return sin((x/100))*100;
// replace with user input at some point
}
struct brush6 {
int x, y, z, l, w, h;
char texture[MAX_TEXTURE_LENGTH];
// generated data
char *bottomPlane;
char *topPlane;
char *sidePlane1;
char *sidePlane2;
char *sidePlane3;
char *sidePlane4;
};
void printBrush6(struct brush6 *b) {
printf("%s\n%s\n%s\n%s\n%s\n%s", b->bottomPlane, b->topPlane, b->sidePlane1, b->sidePlane2, b->sidePlane3,
b->sidePlane4);
}
void genBrush6(struct brush6 *b) {
char footer[] = "64 64 0 0 0 0 lightmap_gray 16384 16384 0 0 0 0";
char format[] = " ( %d %d %d ) ( %d %d %d ) ( %d %d %d ) %s %s";
//calculate the length of the formatted string
int len = snprintf(NULL, 0, format,
b->l + b->x,
b->w + b->y,
b->z, // line1
b->x,
b->w + b->y,
b->z, // line2
b->x,
b->y,
b->z, // line3
b->texture,
footer);
len++; //add 1 for the null-terminator
// Allocate memory for the planes
b->bottomPlane = (char *)malloc(len * sizeof(char));
b->topPlane = (char *)malloc(len * sizeof(char));
b->sidePlane1 = (char *)malloc(len * sizeof(char));
b->sidePlane2 = (char *)malloc(len * sizeof(char));
b->sidePlane3 = (char *)malloc(len * sizeof(char));
b->sidePlane4 = (char *)malloc(len * sizeof(char));
// Generate the planes
snprintf(b->bottomPlane, len, format,
b->l + b->x,
b->w + b->y,
b->z, // line1
b->x,
b->w + b->y,
b->z, // line2
b->x,
b->y,
b->z, // line3
b->texture,
footer);
snprintf(b->topPlane, len, format,
b->x,
b->y,
b->h + b->z, // line1
b->x,
b->w + b->y,
b->h + b->z, // line2
b->l + b->x,
b->w + b->y,
b->h + b->z, // line3
b->texture,
footer);
snprintf(b->sidePlane1, len, format,
b->x,
b->y,
b->h + b->z, // line1
b->l + b->x,
b->y,
b->h + b->z, // line2
b->l + b->x,
b->y,
b->z, // line3
b->texture,
footer);
snprintf(b->sidePlane2, len, format,
b->l + b->x,
b->y,
b->h + b->z, // line1
b->l + b->x,
b->w + b->y,
b->h + b->z, // line2
b->l + b->x,
b->w + b->y,
b->z, // line3
b->texture,
footer);
snprintf(b->sidePlane3, len, format,
b->l + b->x,
b->y + b->w,
b->h + b->z, // line1
b->x,
b->w + b->y,
b->h + b->z, // line2
b->x,
b->w + b->y,
b->z, // line3
b->texture,
footer);
snprintf(b->sidePlane4, len, format,
b->x,
b->y + b->w,
b->h + b->z, // line1
b->x,
b->y,
b->h + b->z, // line2
b->x,
b->y,
b->z, // line3
b->texture,
footer);
}
struct brush6 *createBrush6(int l, int w, int h, int x, int y, int z, char *texture) {
struct brush6 *b = malloc(sizeof(struct brush6));
b->l = l;
b->w = w;
b->h = h;
b->x = x;
b->y = y;
b->z = z;
strcpy(b->texture, texture);
return b;
}
int main() {
if(spacing <= 0) {
printf("Spacing too small");
return 1;
}
for (int x = minX; x < maxX; x+=spacing) {
struct brush6 *b = createBrush6(size, size, size, x, f(x), 0, "caulk");
genBrush6(b);
printf("{\n");
printBrush6(b);
printf("\n}\n");
//free the allocated memory
free(b->bottomPlane);
free(b->topPlane);
free(b->sidePlane1);
free(b->sidePlane2);
free(b->sidePlane3);
free(b->sidePlane4);
free(b);
}
return 0;
}