-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.cpp
271 lines (263 loc) · 14.4 KB
/
models.cpp
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#include "camera.hpp"
#include <cstdlib>
#include <iostream>
#include <raylib.h>
#include <raymath.h>
#include <string>
FoxModel makeCube(Vector3 position, Vector3 scale) {
return makeCubeColor(position, scale, 0);
}
FoxModel makeCubeColor(Vector3 position, Vector3 scale, int hue) {
int tris = 108;
FoxModel ret;
ret.tris = (FoxTri **)malloc(sizeof(FoxTri *) * tris);
float vertices[108] = {
// Front
-0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
-0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f,
// Right
0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f,
0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f,
// Back
0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f,
// Left
-0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f,
0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f,
// Top
-0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f,
-0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
// Bottom
-0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f,
0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f};
ret.tris = vertToTri(vertices, tris, position, scale);
ret.size = tris / 9;
ret.hue = hue;
return ret;
}
FoxModel makeTorus(Vector3 position, Vector3 scale) {
int tris = 864;
FoxModel ret;
ret.tris = (FoxTri **)malloc(sizeof(FoxTri *) * tris);
float vertices[864] = {
1.25000000, 0.00000000, 0.00000000, 0.79549503, 0.21650635,
0.79549515, 1.12500000, 0.21650635, 0.00000000, 0.79549503,
0.21650635, 0.79549515, 0.87500000, 0.21650635, 0.00000000,
1.12500000, 0.21650635, 0.00000000, 0.87500000, 0.21650635,
0.00000000, 0.53033006, 0.00000000, 0.53033012, 0.75000000,
0.00000000, 0.00000000, 0.53033006, 0.00000000, 0.53033012,
0.87500000, -0.21650635, 0.00000000, 0.75000000, 0.00000000,
0.00000000, 0.61871839, -0.21650635, 0.61871850, 1.12500000,
-0.21650635, 0.00000000, 0.87500000, -0.21650635, 0.00000000,
0.79549503, -0.21650635, 0.79549515, 1.25000000, 0.00000000,
0.00000000, 1.12500000, -0.21650635, 0.00000000, 0.00000009,
0.00000000, 1.25000000, 0.79549503, 0.21650635, 0.79549515,
0.88388336, 0.00000000, 0.88388354, 0.79549503, 0.21650635,
0.79549515, 0.00000007, 0.21650635, 0.87500000, 0.61871839,
0.21650635, 0.61871850, 0.00000007, 0.21650635, 0.87500000,
0.53033006, 0.00000000, 0.53033012, 0.61871839, 0.21650635,
0.61871850, 0.00000006, 0.00000000, 0.75000000, 0.61871839,
-0.21650635, 0.61871850, 0.53033006, 0.00000000, 0.53033012,
0.00000007, -0.21650635, 0.87500000, 0.79549503, -0.21650635,
0.79549515, 0.61871839, -0.21650635, 0.61871850, 0.00000008,
-0.21650635, 1.12500000, 0.88388336, 0.00000000, 0.88388354,
0.79549503, -0.21650635, 0.79549515, -0.88388371, 0.00000000,
0.88388324, 0.00000008, 0.21650635, 1.12500000, 0.00000009,
0.00000000, 1.25000000, -0.79549533, 0.21650635, 0.79549491,
0.00000007, 0.21650635, 0.87500000, 0.00000008, 0.21650635,
1.12500000, -0.61871856, 0.21650635, 0.61871827, 0.00000006,
0.00000000, 0.75000000, 0.00000007, 0.21650635, 0.87500000,
-0.53033018, 0.00000000, 0.53032994, 0.00000007, -0.21650635,
0.87500000, 0.00000006, 0.00000000, 0.75000000, -0.61871856,
-0.21650635, 0.61871827, 0.00000008, -0.21650635, 1.12500000,
0.00000007, -0.21650635, 0.87500000, -0.79549533, -0.21650635,
0.79549491, 0.00000009, 0.00000000, 1.25000000, 0.00000008,
-0.21650635, 1.12500000, -1.25000000, 0.00000000, 0.00000011,
-0.79549533, 0.21650635, 0.79549491, -0.88388371, 0.00000000,
0.88388324, -1.12500000, 0.21650635, 0.00000010, -0.61871856,
0.21650635, 0.61871827, -0.79549533, 0.21650635, 0.79549491,
-0.87500000, 0.21650635, 0.00000008, -0.53033018, 0.00000000,
0.53032994, -0.61871856, 0.21650635, 0.61871827, -0.75000000,
0.00000000, 0.00000007, -0.61871856, -0.21650635, 0.61871827,
-0.53033018, 0.00000000, 0.53032994, -0.87500000, -0.21650635,
0.00000008, -0.79549533, -0.21650635, 0.79549491, -0.61871856,
-0.21650635, 0.61871827, -1.12500000, -0.21650635, 0.00000010,
-0.88388371, 0.00000000, 0.88388324, -0.79549533, -0.21650635,
0.79549491, -0.88388371, 0.00000000, -0.88388324, -1.12500000,
0.21650635, 0.00000010, -1.25000000, 0.00000000, 0.00000011,
-0.79549533, 0.21650635, -0.79549491, -0.87500000, 0.21650635,
0.00000008, -1.12500000, 0.21650635, 0.00000010, -0.61871856,
0.21650635, -0.61871827, -0.75000000, 0.00000000, 0.00000007,
-0.87500000, 0.21650635, 0.00000008, -0.53033018, 0.00000000,
-0.53032994, -0.87500000, -0.21650635, 0.00000008, -0.75000000,
0.00000000, 0.00000007, -0.87500000, -0.21650635, 0.00000008,
-0.79549533, -0.21650635, -0.79549491, -1.12500000, -0.21650635,
0.00000010, -0.79549533, -0.21650635, -0.79549491, -1.25000000,
0.00000000, 0.00000011, -1.12500000, -0.21650635, 0.00000010,
0.00000009, 0.00000000, -1.25000000, -0.79549533, 0.21650635,
-0.79549491, -0.88388371, 0.00000000, -0.88388324, 0.00000008,
0.21650635, -1.12500000, -0.61871856, 0.21650635, -0.61871827,
-0.79549533, 0.21650635, -0.79549491, 0.00000007, 0.21650635,
-0.87500000, -0.53033018, 0.00000000, -0.53032994, -0.61871856,
0.21650635, -0.61871827, 0.00000006, 0.00000000, -0.75000000,
-0.61871856, -0.21650635, -0.61871827, -0.53033018, 0.00000000,
-0.53032994, -0.61871856, -0.21650635, -0.61871827, 0.00000008,
-0.21650635, -1.12500000, -0.79549533, -0.21650635, -0.79549491,
0.00000008, -0.21650635, -1.12500000, -0.88388371, 0.00000000,
-0.88388324, -0.79549533, -0.21650635, -0.79549491, 0.88388300,
0.00000000, -0.88388395, 0.00000008, 0.21650635, -1.12500000,
0.00000009, 0.00000000, -1.25000000, 0.00000008, 0.21650635,
-1.12500000, 0.61871809, 0.21650635, -0.61871880, 0.00000007,
0.21650635, -0.87500000, 0.61871809, 0.21650635, -0.61871880,
0.00000006, 0.00000000, -0.75000000, 0.00000007, 0.21650635,
-0.87500000, 0.53032982, 0.00000000, -0.53033042, 0.00000007,
-0.21650635, -0.87500000, 0.00000006, 0.00000000, -0.75000000,
0.61871809, -0.21650635, -0.61871880, 0.00000008, -0.21650635,
-1.12500000, 0.00000007, -0.21650635, -0.87500000, 0.79549474,
-0.21650635, -0.79549557, 0.00000009, 0.00000000, -1.25000000,
0.00000008, -0.21650635, -1.12500000, 1.25000000, 0.00000000,
0.00000000, 0.79549474, 0.21650635, -0.79549557, 0.88388300,
0.00000000, -0.88388395, 0.79549474, 0.21650635, -0.79549557,
0.87500000, 0.21650635, 0.00000000, 0.61871809, 0.21650635,
-0.61871880, 0.87500000, 0.21650635, 0.00000000, 0.53032982,
0.00000000, -0.53033042, 0.61871809, 0.21650635, -0.61871880,
0.75000000, 0.00000000, 0.00000000, 0.61871809, -0.21650635,
-0.61871880, 0.53032982, 0.00000000, -0.53033042, 0.87500000,
-0.21650635, 0.00000000, 0.79549474, -0.21650635, -0.79549557,
0.61871809, -0.21650635, -0.61871880, 1.12500000, -0.21650635,
0.00000000, 0.88388300, 0.00000000, -0.88388395, 0.79549474,
-0.21650635, -0.79549557, 1.25000000, 0.00000000, 0.00000000,
0.88388336, 0.00000000, 0.88388354, 0.79549503, 0.21650635,
0.79549515, 0.79549503, 0.21650635, 0.79549515, 0.61871839,
0.21650635, 0.61871850, 0.87500000, 0.21650635, 0.00000000,
0.87500000, 0.21650635, 0.00000000, 0.61871839, 0.21650635,
0.61871850, 0.53033006, 0.00000000, 0.53033012, 0.53033006,
0.00000000, 0.53033012, 0.61871839, -0.21650635, 0.61871850,
0.87500000, -0.21650635, 0.00000000, 0.61871839, -0.21650635,
0.61871850, 0.79549503, -0.21650635, 0.79549515, 1.12500000,
-0.21650635, 0.00000000, 0.79549503, -0.21650635, 0.79549515,
0.88388336, 0.00000000, 0.88388354, 1.25000000, 0.00000000,
0.00000000, 0.00000009, 0.00000000, 1.25000000, 0.00000008,
0.21650635, 1.12500000, 0.79549503, 0.21650635, 0.79549515,
0.79549503, 0.21650635, 0.79549515, 0.00000008, 0.21650635,
1.12500000, 0.00000007, 0.21650635, 0.87500000, 0.00000007,
0.21650635, 0.87500000, 0.00000006, 0.00000000, 0.75000000,
0.53033006, 0.00000000, 0.53033012, 0.00000006, 0.00000000,
0.75000000, 0.00000007, -0.21650635, 0.87500000, 0.61871839,
-0.21650635, 0.61871850, 0.00000007, -0.21650635, 0.87500000,
0.00000008, -0.21650635, 1.12500000, 0.79549503, -0.21650635,
0.79549515, 0.00000008, -0.21650635, 1.12500000, 0.00000009,
0.00000000, 1.25000000, 0.88388336, 0.00000000, 0.88388354,
-0.88388371, 0.00000000, 0.88388324, -0.79549533, 0.21650635,
0.79549491, 0.00000008, 0.21650635, 1.12500000, -0.79549533,
0.21650635, 0.79549491, -0.61871856, 0.21650635, 0.61871827,
0.00000007, 0.21650635, 0.87500000, -0.61871856, 0.21650635,
0.61871827, -0.53033018, 0.00000000, 0.53032994, 0.00000006,
0.00000000, 0.75000000, -0.53033018, 0.00000000, 0.53032994,
-0.61871856, -0.21650635, 0.61871827, 0.00000007, -0.21650635,
0.87500000, -0.61871856, -0.21650635, 0.61871827, -0.79549533,
-0.21650635, 0.79549491, 0.00000008, -0.21650635, 1.12500000,
-0.79549533, -0.21650635, 0.79549491, -0.88388371, 0.00000000,
0.88388324, 0.00000009, 0.00000000, 1.25000000, -1.25000000,
0.00000000, 0.00000011, -1.12500000, 0.21650635, 0.00000010,
-0.79549533, 0.21650635, 0.79549491, -1.12500000, 0.21650635,
0.00000010, -0.87500000, 0.21650635, 0.00000008, -0.61871856,
0.21650635, 0.61871827, -0.87500000, 0.21650635, 0.00000008,
-0.75000000, 0.00000000, 0.00000007, -0.53033018, 0.00000000,
0.53032994, -0.75000000, 0.00000000, 0.00000007, -0.87500000,
-0.21650635, 0.00000008, -0.61871856, -0.21650635, 0.61871827,
-0.87500000, -0.21650635, 0.00000008, -1.12500000, -0.21650635,
0.00000010, -0.79549533, -0.21650635, 0.79549491, -1.12500000,
-0.21650635, 0.00000010, -1.25000000, 0.00000000, 0.00000011,
-0.88388371, 0.00000000, 0.88388324, -0.88388371, 0.00000000,
-0.88388324, -0.79549533, 0.21650635, -0.79549491, -1.12500000,
0.21650635, 0.00000010, -0.79549533, 0.21650635, -0.79549491,
-0.61871856, 0.21650635, -0.61871827, -0.87500000, 0.21650635,
0.00000008, -0.61871856, 0.21650635, -0.61871827, -0.53033018,
0.00000000, -0.53032994, -0.75000000, 0.00000000, 0.00000007,
-0.53033018, 0.00000000, -0.53032994, -0.61871856, -0.21650635,
-0.61871827, -0.87500000, -0.21650635, 0.00000008, -0.87500000,
-0.21650635, 0.00000008, -0.61871856, -0.21650635, -0.61871827,
-0.79549533, -0.21650635, -0.79549491, -0.79549533, -0.21650635,
-0.79549491, -0.88388371, 0.00000000, -0.88388324, -1.25000000,
0.00000000, 0.00000011, 0.00000009, 0.00000000, -1.25000000,
0.00000008, 0.21650635, -1.12500000, -0.79549533, 0.21650635,
-0.79549491, 0.00000008, 0.21650635, -1.12500000, 0.00000007,
0.21650635, -0.87500000, -0.61871856, 0.21650635, -0.61871827,
0.00000007, 0.21650635, -0.87500000, 0.00000006, 0.00000000,
-0.75000000, -0.53033018, 0.00000000, -0.53032994, 0.00000006,
0.00000000, -0.75000000, 0.00000007, -0.21650635, -0.87500000,
-0.61871856, -0.21650635, -0.61871827, -0.61871856, -0.21650635,
-0.61871827, 0.00000007, -0.21650635, -0.87500000, 0.00000008,
-0.21650635, -1.12500000, 0.00000008, -0.21650635, -1.12500000,
0.00000009, 0.00000000, -1.25000000, -0.88388371, 0.00000000,
-0.88388324, 0.88388300, 0.00000000, -0.88388395, 0.79549474,
0.21650635, -0.79549557, 0.00000008, 0.21650635, -1.12500000,
0.00000008, 0.21650635, -1.12500000, 0.79549474, 0.21650635,
-0.79549557, 0.61871809, 0.21650635, -0.61871880, 0.61871809,
0.21650635, -0.61871880, 0.53032982, 0.00000000, -0.53033042,
0.00000006, 0.00000000, -0.75000000, 0.53032982, 0.00000000,
-0.53033042, 0.61871809, -0.21650635, -0.61871880, 0.00000007,
-0.21650635, -0.87500000, 0.61871809, -0.21650635, -0.61871880,
0.79549474, -0.21650635, -0.79549557, 0.00000008, -0.21650635,
-1.12500000, 0.79549474, -0.21650635, -0.79549557, 0.88388300,
0.00000000, -0.88388395, 0.00000009, 0.00000000, -1.25000000,
1.25000000, 0.00000000, 0.00000000, 1.12500000, 0.21650635,
0.00000000, 0.79549474, 0.21650635, -0.79549557, 0.79549474,
0.21650635, -0.79549557, 1.12500000, 0.21650635, 0.00000000,
0.87500000, 0.21650635, 0.00000000, 0.87500000, 0.21650635,
0.00000000, 0.75000000, 0.00000000, 0.00000000, 0.53032982,
0.00000000, -0.53033042, 0.75000000, 0.00000000, 0.00000000,
0.87500000, -0.21650635, 0.00000000, 0.61871809, -0.21650635,
-0.61871880, 0.87500000, -0.21650635, 0.00000000, 1.12500000,
-0.21650635, 0.00000000, 0.79549474, -0.21650635, -0.79549557,
1.12500000, -0.21650635, 0.00000000, 1.25000000, 0.00000000,
0.00000000, 0.88388300, 0.00000000, -0.88388395,
};
ret.tris = vertToTri(vertices, tris, position, scale);
ret.size = tris / 9;
return ret;
}
FoxTri **vertToTri(float *vert, int size, Vector3 position, Vector3 scale) {
if (size % 3 != 0) {
std::cout << "Model not Tris";
return nullptr;
}
FoxTri **ret = (FoxTri **)malloc(sizeof(FoxTri *) * size / 3);
Vector3 A;
Vector3 B;
Vector3 C;
Vector3 temp;
int triProg = 0;
int triTotal = 0;
for (int i = 0; i < size; i++) {
switch (i % 3) {
case 0:
temp.x = vert[i] * scale.x;
break;
case 1:
temp.y = vert[i] * scale.y;
break;
case 2:
temp.z = vert[i] * scale.z;
temp = Vector3Add(temp, position);
switch (triProg) {
case 0:
A = temp;
break;
case 1:
B = temp;
break;
case 2:
C = temp;
ret[triTotal] = new FoxTri(A, B, C);
++triTotal;
triProg = -1;
break;
}
++triProg;
break;
}
}
return ret;
}