-
Notifications
You must be signed in to change notification settings - Fork 7
/
fan.cpp
416 lines (361 loc) · 8.27 KB
/
fan.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
#include <iostream>
#include <stdexcept>
#include "fan.h"
//Lave these defined for some reason
#define TRIANGLES
using namespace std;
using namespace glm;
Fan::Fan() {
//trying to make this fan within a 2 pt box
//and 3 pts stretch from mid box, so lets make it uniformed
//we are starting at .4, -.4
delta = 2.0f / 5.0f;
numFins = 4;
zCoord = 0.075f;
}
bool Fan::PreGLInitialize()
{
//variables to create shape
bool isInverseX, isInverseY, isZero, wasZero;
float nX, nY, nZ = 0.0f;
//Gonna Need a for loop to create the second face
for (unsigned int t = 0; t < 6; t++)
{
//set the variables, need to do this twice since theres 2 faces
vec3 startPt(delta / 2, -delta / 2, zCoord);
isInverseX = true;
isInverseY = true;
isZero = true;
wasZero = false;
//for loop for creating the vertices, textures, normals, colors, normal vis
//setup for each of the 4 blades
for (unsigned int i = 0; i < numFins; i++)
{
//delta isZero if no movement (if vertical blade, then isZero is true)
if (i == 0 || i == 2)
{
isZero = true;
}
else
{
isZero = false;
}
//make the blade, which has 4 points each
for (unsigned int a = 0; a < numFins; a++)
{
//setup default values
nX = 0.0f, nY = 0.0f, nZ = 0.0f;
//setup vertices, textures, normals, etc
this->data.vertices.push_back(startPt);
this->data.textures.push_back(vec2(startPt.x / 2.0f + 0.5f, startPt.y / 2.0f + 0.5f));
this->data.colors.push_back(this->RandomColor((this->data.colors.size() > 0 ? *(this->data.colors.end() - 1) : vec4(0.5f, 0.5f, 0.5f, 1.0f)), -0.2f, 0.2f));
//NORMALS
//Setup the the two planes (normal with respect to z)
if (t == 0)
{
nZ = 1.0f;
}
else if (t == 1)
{
nZ = -1.0f;
}
//normals for the sides
if (t == 2 || t == 3)
{
if (isZero || wasZero)
{
if (startPt.x > 0)
nX = 1.0f;
else
nX = -1.0f;
}
else if (a == 1 || a == 2)
{
if (startPt.x > 0)
nX = 1.0f;
else
nX = -1.0f;
if (startPt.y > 0)
nY = 1.0f;
else
nY = -1.0f;
if (a == 2)
{
nY = -nY;
}
}
}
//normals for top and bottom
if (t == 4 || t == 5)
{
if (!isZero || wasZero)
{
if (startPt.y > 0)
nY = 1.0f;
else
nY = -1.0f;
}
else if (a == 1 || a == 2)
{
if (startPt.x > 0)
nX = 1.0f;
else
nX = -1.0f;
if (startPt.y > 0)
nY = 1.0f;
else
nY = -1.0f;
if (a == 2)
{
nX = -nX;
}
}
}
//need this for interior normals
if (a == 3)
wasZero = true;
else
wasZero = false;
if (a == 0 && t > 3 && i == 0)
{
nY = -1;
nX = 0;
}
//push the normals back
this->data.normals.push_back(vec3(nX, nY, nZ));
this->data.normal_visualization_coordinates.push_back(*(this->data.vertices.end() - 1));
this->data.normal_visualization_coordinates.push_back(*(this->data.vertices.end() - 1) + vec3(nX, nY, nZ) / NORMAL_LENGTH_DIVISOR);
//UPDATE
//SPECIAL CASE switching to other half of blade
if (a == 1)
{
//update coords where we hit tip of the blade
startPt.x = startPt.x + getDelta(isInverseX, false);
startPt.y = startPt.y + getDelta(isInverseY, false);
//come back from tip of blade back to center
if (isZero)
isInverseY = !isInverseY;
else
isInverseX = !isInverseX;
}
else
{
//Update coords per usual
startPt.x = startPt.x + getDelta(isInverseX, isZero);
startPt.y = startPt.y + getDelta(isInverseY, !isZero);
startPt.z = zCoord;
}
}
}
//change the second z coord for second plane
if (t == 0 || t == 2 || t == 4)
{
zCoord = -0.075f;
}
else
{
zCoord = 0.075f;
}
}
//Planes
//INDICIES
//vertex holder
int v = 0;
//FIRST PLANE
//Make indices now
for (unsigned int d = 0; d < 4; d++)
{
//1st triangle
this->data.indices.push_back(v);
this->data.indices.push_back(v + 1);
this->data.indices.push_back(v + 3);
//2nd triangle
this->data.indices.push_back(v + 1);
this->data.indices.push_back(v + 2);
this->data.indices.push_back(v + 3);
//3rd triangle w special case
this->data.indices.push_back(v + 3);
if (v != 12)
this->data.indices.push_back(v + 4);
else
this->data.indices.push_back(0);
this->data.indices.push_back(v);
//increase the vertex counter by 4, since theres 4 vertices per "plane"
v = v + 4;
}
//inside box triangles
v = 0;
//first triangle of the plane
this->data.indices.push_back(v);
this->data.indices.push_back(v + 4);
this->data.indices.push_back(v + 8);
//second triangle of the plane
this->data.indices.push_back(v);
this->data.indices.push_back(v + 8);
this->data.indices.push_back(v + 12);
//SECOND PLANE
//Make indices now
v = 16;
for (unsigned int d = 0; d < 4; d++)
{
//1st triangle
this->data.indices.push_back(v);
this->data.indices.push_back(v + 3);
this->data.indices.push_back(v + 1);
//2nd triangle
this->data.indices.push_back(v + 1);
this->data.indices.push_back(v + 3);
this->data.indices.push_back(v + 2);
//3rd triangle w special case
this->data.indices.push_back(v + 3);
this->data.indices.push_back(v);
if (v != 28)
this->data.indices.push_back(v + 4);
else
this->data.indices.push_back(16);
//increase the vertex counter by 4, since theres 4 vertices per "plane"
v = v + 4;
}
//inside box triangles
v = 16;
//first triangle of the plane
this->data.indices.push_back(v);
this->data.indices.push_back(v + 8);
this->data.indices.push_back(v + 4);
//second triangle of the plane
this->data.indices.push_back(v);
this->data.indices.push_back(v + 12);
this->data.indices.push_back(v + 8);
////CONNECTING THE SIDES
int temp = 0;
//(these vertices are 32 - 64)
for (unsigned int c = 32; c < 48; c++)
{
if (drawIt(c))
{
//first triangle of the plane
this->data.indices.push_back(c);
this->data.indices.push_back(c + 16);
this->data.indices.push_back(c + 17);
//second triangle of the plane
this->data.indices.push_back(c);
this->data.indices.push_back(c + 17);
this->data.indices.push_back(c + 1);
}
else
{
temp = c;
c = c + 32;
if (temp != 47)
{//first triangle of the plane
this->data.indices.push_back(c);
this->data.indices.push_back(c + 16);
this->data.indices.push_back(c + 17);
//second triangle of the plane
this->data.indices.push_back(c);
this->data.indices.push_back(c + 17);
this->data.indices.push_back(c + 1);
}
else
{
//first triangle of the plane
this->data.indices.push_back(c);
this->data.indices.push_back(c + 16);
this->data.indices.push_back(c + 1);
//second triangle of the plane
this->data.indices.push_back(c);
this->data.indices.push_back(c + 1);
this->data.indices.push_back(64);
}
c = temp;
}
}
//int c = 79;
// //first triangle of the plane
// this->data.indices.push_back(c);
// this->data.indices.push_back(c + 16);
// this->data.indices.push_back(c + 1);
// //second triangle of the plane
// this->data.indices.push_back(c);
// this->data.indices.push_back(c + 1);
// this->data.indices.push_back(64);
//make backup because Perry said so. not really though. still would be good to have
this->data.vbackup = this->data.vertices;
return true;
}
void Fan::NonGLTakeDown()
{
}
void Fan::RecomputeNormals()
{
}
float Fan::getDelta(bool isInverse, bool isZero)
{
//return 0 if no movement on that coord
if (isZero)
return 0;
//else give inverse delta or not
else
{
if (isInverse)
return -delta;
else
return delta;
}
}
float Fan::getNormalX(bool isInverse, bool isZero)
{
if (isInverse)
return 1;
else
return -1;
}
float Fan::getNormalY(bool isInverse, bool isZero)
{
if (isZero)
{
return 0;
}
else
if (isInverse)
return -1;
else
return 1;
}
bool Fan::drawIt(int check)
{
if (check == 33)
{
return false;
}
else if (check == 36)
{
return false;
}
else if (check == 38)
{
return false;
}
else if (check == 39)
{
return false;
}
else if (check == 41)
{
return false;
}
else if (check == 44)
{
return false;
}
else if (check == 46)
{
return false;
}
else if (check == 47)
{
return false;
}
else
return true;
}