-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaneGLImproved.cpp
More file actions
725 lines (606 loc) · 22 KB
/
planeGLImproved.cpp
File metadata and controls
725 lines (606 loc) · 22 KB
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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
#include <GLFW/glfw3.h>
#include <cmath>
#include <cstdlib>
#include <random>
#include <vector>
struct Nuage { float x, y; } nuages[5];
struct BrinHerbe {
float x;
float yBase;
float hauteur;
float largeur;
float orientation;
float rigidite;
};
std::vector<BrinHerbe> brinsHerbe;
float ventMagnitude = 0.030f; // force du vent de fond
float ventLongueurOnde = 7.0f; // fréquence spatiale du vent
float ventPeriode = 1.4f; // vitesse temporelle du vent
float souffleMagnitude = 0.22f; // intensité du souffle type réacteur
float souffleLargeur = 0.18f; // rayon d'influence du souffle
float souffleY = -0.66f; // hauteur verticale de la zone de souffle
float souffleVitesse = 0.35f; // vitesse de déplacement du souffle
void cercle(float cx, float cy, float r) {
glBegin(GL_TRIANGLE_FAN);
glVertex2f(cx, cy);
for (int i = 0; i <= 32; i++) {
float a = i * 2.0f * 3.14159f / 32;
glVertex2f(cx + cosf(a) * r, cy + sinf(a) * r);
}
glEnd();
}
// Enhanced realistic tree rendering
void dessinerArbreRealiste(float cx, float baseY, float scale, bool isDarkVariant) {
glPushMatrix();
glTranslatef(cx, baseY, 0.0f);
glScalef(scale, scale, 1.0f);
// Trunk
glColor3f(0.35f, 0.20f, 0.12f);
glBegin(GL_POLYGON);
glVertex2f(-0.015f, 0.0f);
glVertex2f(0.015f, 0.0f);
glVertex2f(0.012f, 0.25f);
glVertex2f(-0.012f, 0.25f);
glEnd();
// Shadow under trunk
glColor3f(0.05f, 0.05f, 0.05f);
glBegin(GL_POLYGON);
glVertex2f(-0.020f, -0.002f);
glVertex2f(0.020f, -0.002f);
glVertex2f(0.025f, -0.020f);
glVertex2f(-0.025f, -0.020f);
glEnd();
if (isDarkVariant) {
// Dark green variant - deeper foliage
// Lower foliage layer (darkest)
glColor3f(0.06f, 0.28f, 0.10f);
glPushMatrix();
glTranslatef(0.0f, 0.18f, 0.0f);
glScalef(1.15f, 1.0f, 1.0f);
cercle(0.0f, 0.0f, 0.120f);
glPopMatrix();
// Middle foliage layer
glColor3f(0.08f, 0.32f, 0.12f);
glPushMatrix();
glTranslatef(0.0f, 0.28f, 0.0f);
glScalef(1.1f, 0.95f, 1.0f);
cercle(0.0f, 0.0f, 0.115f);
glPopMatrix();
// Upper foliage layer
glColor3f(0.10f, 0.35f, 0.14f);
glPushMatrix();
glTranslatef(0.0f, 0.36f, 0.0f);
glScalef(1.0f, 0.85f, 1.0f);
cercle(0.0f, 0.0f, 0.100f);
glPopMatrix();
// Top peak (brighter edge highlights)
glColor3f(0.12f, 0.38f, 0.16f);
glPushMatrix();
glTranslatef(-0.025f, 0.42f, 0.0f);
glScalef(0.8f, 0.9f, 1.0f);
cercle(0.0f, 0.0f, 0.045f);
glPopMatrix();
glColor3f(0.13f, 0.40f, 0.17f);
glPushMatrix();
glTranslatef(0.030f, 0.40f, 0.0f);
glScalef(0.75f, 0.85f, 1.0f);
cercle(0.0f, 0.0f, 0.042f);
glPopMatrix();
// Slight highlight on edge
glColor3f(0.15f, 0.42f, 0.19f);
glBegin(GL_TRIANGLES);
glVertex2f(-0.085f, 0.28f);
glVertex2f(-0.070f, 0.35f);
glVertex2f(-0.065f, 0.25f);
glEnd();
}
else {
// Light green variant - lighter, brighter foliage
// Lower foliage layer
glColor3f(0.12f, 0.45f, 0.18f);
glPushMatrix();
glTranslatef(0.0f, 0.18f, 0.0f);
glScalef(1.15f, 1.0f, 1.0f);
cercle(0.0f, 0.0f, 0.120f);
glPopMatrix();
// Middle foliage layer
glColor3f(0.15f, 0.50f, 0.22f);
glPushMatrix();
glTranslatef(0.0f, 0.28f, 0.0f);
glScalef(1.1f, 0.95f, 1.0f);
cercle(0.0f, 0.0f, 0.115f);
glPopMatrix();
// Upper foliage layer (brightest in light variant)
glColor3f(0.18f, 0.54f, 0.26f);
glPushMatrix();
glTranslatef(0.0f, 0.36f, 0.0f);
glScalef(1.0f, 0.85f, 1.0f);
cercle(0.0f, 0.0f, 0.100f);
glPopMatrix();
// Top peak with subtle highlight
glColor3f(0.20f, 0.58f, 0.30f);
glPushMatrix();
glTranslatef(-0.025f, 0.42f, 0.0f);
glScalef(0.8f, 0.9f, 1.0f);
cercle(0.0f, 0.0f, 0.045f);
glPopMatrix();
glColor3f(0.22f, 0.60f, 0.32f);
glPushMatrix();
glTranslatef(0.030f, 0.40f, 0.0f);
glScalef(0.75f, 0.85f, 1.0f);
cercle(0.0f, 0.0f, 0.042f);
glPopMatrix();
// Bright highlight on sun-facing edge
glColor3f(0.25f, 0.65f, 0.38f);
glBegin(GL_TRIANGLES);
glVertex2f(-0.085f, 0.28f);
glVertex2f(-0.070f, 0.35f);
glVertex2f(-0.065f, 0.25f);
glEnd();
// Right side lighter reflection
glColor3f(0.23f, 0.62f, 0.35f);
glBegin(GL_TRIANGLES);
glVertex2f(0.085f, 0.26f);
glVertex2f(0.070f, 0.33f);
glVertex2f(0.065f, 0.22f);
glEnd();
}
glPopMatrix();
}
void dessinerCiel() {
glBegin(GL_QUADS);
// Zénith — bleu profond
glColor3f(0.05f, 0.23f, 0.43f); glVertex2f(-1.0f, 1.0f);
glColor3f(0.05f, 0.23f, 0.43f); glVertex2f(1.0f, 1.0f);
glColor3f(0.10f, 0.43f, 0.66f); glVertex2f(1.0f, 0.35f);
glColor3f(0.10f, 0.43f, 0.66f); glVertex2f(-1.0f, 0.35f);
// Milieu — bleu clair
glColor3f(0.10f, 0.43f, 0.66f); glVertex2f(-1.0f, 0.35f);
glColor3f(0.10f, 0.43f, 0.66f); glVertex2f(1.0f, 0.35f);
glColor3f(0.36f, 0.72f, 0.83f); glVertex2f(1.0f, -0.10f);
glColor3f(0.36f, 0.72f, 0.83f); glVertex2f(-1.0f, -0.10f);
// Horizon — très clair
glColor3f(0.36f, 0.72f, 0.83f); glVertex2f(-1.0f, -0.10f);
glColor3f(0.36f, 0.72f, 0.83f); glVertex2f(1.0f, -0.10f);
glColor3f(0.72f, 0.91f, 0.94f); glVertex2f(1.0f, -0.35f);
glColor3f(0.72f, 0.91f, 0.94f); glVertex2f(-1.0f, -0.35f);
glEnd();
}
void dessinerNuage(float x, float y) {
// =========================
// Ombre douce derrière
// =========================
glColor3f(0.85f, 0.87f, 0.90f);
cercle(x - 0.090f, y - 0.015f, 0.035f);
cercle(x - 0.045f, y - 0.020f, 0.045f);
cercle(x + 0.010f, y - 0.022f, 0.055f);
cercle(x + 0.065f, y - 0.018f, 0.045f);
cercle(x + 0.105f, y - 0.012f, 0.032f);
// =========================
// Base du nuage
// =========================
glColor3f(0.96f, 0.96f, 0.98f);
cercle(x - 0.080f, y, 0.038f);
cercle(x - 0.030f, y - 0.003f, 0.045f);
cercle(x + 0.030f, y - 0.002f, 0.048f);
cercle(x + 0.085f, y, 0.035f);
// =========================
// Partie haute plus gonflée
// =========================
glColor3f(1.0f, 1.0f, 1.0f);
cercle(x - 0.060f, y + 0.020f, 0.045f);
cercle(x - 0.010f, y + 0.032f, 0.058f);
cercle(x + 0.050f, y + 0.022f, 0.048f);
// =========================
// Petit reflet lumineux
// =========================
glColor3f(1.0f, 1.0f, 1.0f);
cercle(x - 0.030f, y + 0.030f, 0.020f);
}
// --- Avion ---
void dessinerAvion() {
glPushMatrix();
// Position + scale
glTranslatef(0.02f, -0.46f, 0.0f);
glScalef(1.55f, 1.55f, 1.0f);
// ---------------- SHADOW ----------------
glColor4f(0.18f, 0.18f, 0.18f, 0.28f);
glPushMatrix();
glTranslatef(0.00f, -0.135f, 0.0f);
glScalef(2.4f, 0.42f, 1.0f);
cercle(0.0f, 0.0f, 0.11f);
glPopMatrix();
// ---------------- MAIN LANDING GEAR UNDER WING ----------------
glColor3f(0.68f, 0.68f, 0.70f);
glLineWidth(4.0f);
// Left main wheel
glColor3f(0.08f, 0.08f, 0.08f);
glPushMatrix();
glTranslatef(-0.15f, -0.1f, 0.0f);
glScalef(1.45f, 1.45f, 1.0f);
cercle(0.0f, 0.0f, 0.014f);
glPopMatrix();
glColor3f(0.62f, 0.62f, 0.64f);
glPushMatrix();
glTranslatef(-0.15f, -0.1f, 0.0f);
cercle(0.0f, 0.0f, 0.0065f);
glPopMatrix();
glBegin(GL_LINES);
glVertex2f(-0.14f, -0.045f);
glVertex2f(-0.14f, -0.085f);
glEnd();
glBegin(GL_LINES);
glVertex2f(-0.140f, -0.082f);
glVertex2f(-0.126f, -0.104f);
glVertex2f(-0.140f, -0.082f);
glVertex2f(-0.154f, -0.104f);
glEnd();
// Right main wheel
glColor3f(0.08f, 0.08f, 0.08f);
glPushMatrix();
glTranslatef(-0.127f, -0.114f, 0.0f);
glScalef(1.45f, 1.45f, 1.0f);
cercle(0.0f, 0.0f, 0.015f);
glPopMatrix();
glColor3f(0.62f, 0.62f, 0.64f);
glPushMatrix();
glTranslatef(-0.127f, -0.114f, 0.0f);
cercle(0.0f, 0.0f, 0.0065f);
glPopMatrix();
// ---------------- FUSELAGE ----------------
glColor3f(0.92f, 0.92f, 0.92f);
glBegin(GL_POLYGON);
glVertex2f(-0.34f, 0.012f); // arrière haut
glVertex2f(-0.26f, 0.034f);
glVertex2f(-0.05f, 0.040f);
glVertex2f(0.16f, 0.038f);
glVertex2f(0.28f, 0.030f);
glVertex2f(0.34f, 0.020f);
glVertex2f(0.365f, 0.010f); // nez haut
glVertex2f(0.42f, -0.03f); // pointe du nez
glVertex2f(0.366f, -0.048f); // nez bas
glVertex2f(0.330f, -0.020f);
glVertex2f(0.20f, -0.032f);
glVertex2f(-0.04f, -0.036f);
glVertex2f(-0.25f, -0.030f);
glVertex2f(-0.34f, -0.012f); // arrière bas
glEnd();
// ---------------- TOP HIGHLIGHT ----------------
glColor3f(0.98f, 0.98f, 0.99f);
glBegin(GL_POLYGON);
glVertex2f(-0.20f, 0.020f);
glVertex2f(0.10f, 0.026f);
glVertex2f(0.24f, 0.022f);
glVertex2f(0.12f, 0.016f);
glVertex2f(-0.10f, 0.014f);
glEnd();
// ---------------- BELLY SHADE ----------------
glColor3f(0.82f, 0.82f, 0.84f);
glBegin(GL_POLYGON);
glVertex2f(-0.20f, -0.022f);
glVertex2f(0.00f, -0.050f);
glVertex2f(0.18f, -0.052f);
glVertex2f(0.31f, -0.043f);
glVertex2f(0.25f, -0.020f);
glVertex2f(0.05f, -0.060f);
glVertex2f(-0.18f, -0.054f);
glEnd();
// ---------------- COCKPIT ----------------
glColor3f(0.10f, 0.33f, 0.58f);
glBegin(GL_POLYGON);
glVertex2f(0.250f, 0.018f);
glVertex2f(0.292f, 0.022f);
glVertex2f(0.336f, 0.018f);
glVertex2f(0.365f, 0.00f);
glVertex2f(0.345f, -0.025f);
glVertex2f(0.280f, -0.022f);
glVertex2f(0.262f, 0.014f);
glEnd();
// Cockpit shine
glColor3f(0.55f, 0.78f, 0.96f);
glBegin(GL_TRIANGLES);
glVertex2f(0.272f, 0.017f);
glVertex2f(0.328f, 0.01f);
glVertex2f(0.295f, 0.00f);
glEnd();
// ---------------- PASSENGER WINDOWS ----------------
for (int i = 0; i < 15; i++) {
float wx = -0.11f + i * 0.024f;
// Main oval window
glColor3f(0.12f, 0.45f, 0.70f);
glPushMatrix();
glTranslatef(wx, 0.006f, 0.0f);
glScalef(1.35f, 0.72f, 1.0f);
cercle(0.0f, 0.0f, 0.0050f);
glPopMatrix();
// Window shine
glColor3f(0.72f, 0.88f, 0.98f);
glPushMatrix();
glTranslatef(wx - 0.0015f, 0.0075f, 0.0f);
glScalef(0.65f, 0.30f, 1.0f);
cercle(0.0f, 0.0f, 0.0030f);
glPopMatrix();
}
// ---------------- MAIN WING ----------------
glColor3f(0.90f, 0.90f, 0.91f);
glBegin(GL_POLYGON);
glVertex2f(-0.01f, -0.006f);
glVertex2f(0.12f, 0.002f);
glVertex2f(0.02f, -0.105f);
glVertex2f(-0.12f, -0.090f);
glEnd();
glColor3f(0.82f, 0.82f, 0.84f);
glBegin(GL_POLYGON);
glVertex2f(-0.005f, -0.018f);
glVertex2f(0.085f, -0.012f);
glVertex2f(0.018f, -0.074f);
glVertex2f(-0.078f, -0.064f);
glEnd();
// ---------------- REAR HORIZONTAL STABILIZER ----------------
glColor3f(0.88f, 0.88f, 0.90f);
glBegin(GL_POLYGON);
glVertex2f(-0.28f, -0.006f);
glVertex2f(-0.17f, 0.000f);
glVertex2f(-0.20f, -0.050f);
glVertex2f(-0.31f, -0.042f);
glEnd();
// ---------------- VERTICAL TAIL ----------------
glColor3f(0.95f, 0.95f, 0.96f);
glBegin(GL_POLYGON);
glVertex2f(-0.315f, 0.005f);
glVertex2f(-0.245f, 0.018f);
glVertex2f(-0.225f, 0.115f);
glVertex2f(-0.285f, 0.095f);
glVertex2f(-0.325f, 0.050f);
glEnd();
glColor3f(0.84f, 0.84f, 0.86f);
glBegin(GL_TRIANGLES);
glVertex2f(-0.294f, 0.020f);
glVertex2f(-0.245f, 0.092f);
glVertex2f(-0.270f, 0.018f);
glEnd();
// ---------------- NOSE LANDING GEAR ----------------
glColor3f(0.68f, 0.68f, 0.70f);
glLineWidth(3.0f);
glBegin(GL_LINES);
glVertex2f(0.240f, -0.045f);
glVertex2f(0.240f, -0.094f);
glEnd();
glBegin(GL_LINES);
glVertex2f(0.240f, -0.082f);
glVertex2f(0.226f, -0.104f);
glVertex2f(0.240f, -0.082f);
glVertex2f(0.254f, -0.104f);
glEnd();
glColor3f(0.08f, 0.08f, 0.08f);
glPushMatrix();
glTranslatef(0.240f, -0.110f, 0.0f);
glScalef(1.18f, 1.18f, 1.0f);
cercle(0.0f, 0.0f, 0.014f);
glPopMatrix();
glColor3f(0.62f, 0.62f, 0.64f);
glPushMatrix();
glTranslatef(0.240f, -0.110f, 0.0f);
cercle(0.0f, 0.0f, 0.0055f);
glPopMatrix();
glLineWidth(1.0f);
glPopMatrix();
}
//herbes
void dessinerHerbe() {
//behin the runway
glBegin(GL_QUADS); //rectangle
glColor3f(0.15f, 0.50f, 0.15f);
glVertex2f(-1.0f, -0.35f); //top left
glVertex2f(1.0f, -0.35f); //top right
glVertex2f(1.0f, -0.50f); //bottom right
glVertex2f(-1.0f, -0.50f); //bottomleft
glEnd();
// in front of runway
glBegin(GL_QUADS);
glColor3f(0.15f, 0.50f, 0.15f);
glVertex2f(-1.0f, -0.80f); //top left
glVertex2f(1.0f, -0.80f); //top right
glVertex2f(1.0f, -1.00f); //bottom right
glVertex2f(-1.0f, -1.00f); //bottom left
glEnd();
}
float bruit01(float n) {
return 0.5f + 0.5f * sinf(n * 12.9898f + 78.233f);
}
void initialiserHerbe() {
if (!brinsHerbe.empty()) return; // éviter de regénérer chaque frame
const int nombreBrins = 8200; // densité plus élevée
std::mt19937 gen(1337); // graine fixe pour un rendu stable
std::uniform_real_distribution<float> distX(-1.0f, 1.0f); // distribution horizontale
std::uniform_real_distribution<float> distOri(0.0f, 3.14159f); // orientation locale
std::uniform_real_distribution<float> distJitter(-0.003f, 0.003f); // petit bruit spatial
std::uniform_real_distribution<float> distRigidite(0.55f, 0.98f); // souplesse du brin
std::uniform_real_distribution<float> distSelect(0.0f, 1.0f); // tirage aléatoire générique
brinsHerbe.reserve(nombreBrins); // allouer une seule fois
for (int i = 0; i < nombreBrins; ++i) {
const float x = distX(gen); // position x du brin
const bool zoneAvant = distSelect(gen) > 0.65f; // choisir avant/arrière piste
const float yMin = zoneAvant ? -1.0f : -0.50f; // borne basse de zone
const float yMax = zoneAvant ? -0.80f : -0.26f; // borne haute de zone
const float t = distSelect(gen); // interpolation aléatoire
const float y = yMin + (yMax - yMin) * t + distJitter(gen); // y final du brin
const float base = 0.006f + 0.016f * bruit01(x * 31.0f + y * 57.0f + i * 0.13f); // hauteur de base
const float hauteur = zoneAvant ? (base * 1.4f + 0.005f) : base; // avant piste un peu plus long
BrinHerbe b; // créer un nouveau brin
b.x = x + distJitter(gen); // x légèrement perturbé
b.yBase = y; // base au sol
b.hauteur = hauteur; // longueur du brin
b.largeur = 0.002f + 0.002f * bruit01(i * 0.87f); // largeur locale
b.orientation = distOri(gen); // orientation initiale
b.rigidite = distRigidite(gen); // résistance à la courbure
brinsHerbe.push_back(b); // stocker le brin
}
}
void dessinerHerbeRealiste() {
// Back grass gradient (behind runway)
glBegin(GL_QUADS);
glColor3f(0.30f, 0.66f, 0.43f); glVertex2f(-1.0f, -0.40f);
glColor3f(0.30f, 0.66f, 0.43f); glVertex2f(1.0f, -0.40f);
glColor3f(0.18f, 0.48f, 0.30f); glVertex2f(1.0f, -0.50f);
glColor3f(0.18f, 0.48f, 0.30f); glVertex2f(-1.0f, -0.50f);
glEnd();
// Front grass gradient (in front of runway)
glBegin(GL_QUADS);
glColor3f(0.24f, 0.58f, 0.35f); glVertex2f(-1.0f, -0.80f);
glColor3f(0.24f, 0.58f, 0.35f); glVertex2f(1.0f, -0.80f);
glColor3f(0.10f, 0.34f, 0.18f); glVertex2f(1.0f, -1.00f);
glColor3f(0.10f, 0.34f, 0.18f); glVertex2f(-1.0f, -1.00f);
glEnd();
glBegin(GL_QUADS);
glColor3f(0.24f, 0.58f, 0.35f); glVertex2f(-1.0f, -0.25f);
glColor3f(0.24f, 0.58f, 0.35f); glVertex2f(1.0f, -0.25f);
glColor3f(0.10f, 0.34f, 0.18f); glVertex2f(1.0f, -0.4f);
glColor3f(0.10f, 0.34f, 0.18f); glVertex2f(-1.0f, -0.4f);
glEnd();
// Animated blades inspired by compute-driven grass (CPU adaptation)
initialiserHerbe(); // s'assurer que le champ de brins existe
const float t = (float)glfwGetTime(); // temps global en secondes
const float cycle = fmodf(t * souffleVitesse, 2.8f); // progression cyclique du souffle
const float sourceX = -1.4f + cycle; // position x instantanée du souffle
glLineWidth(1.0f); // épaisseur des brins
glBegin(GL_LINES); // rendu en segments base->pointe
for (size_t i = 0; i < brinsHerbe.size(); ++i) {
const BrinHerbe& b = brinsHerbe[i]; // brin courant
// Background atmospheric wind
const float onde = t * ventPeriode + b.x * ventLongueurOnde + b.yBase * 4.0f; // phase locale
const float vent = sinf(onde) * ventMagnitude * (1.15f - b.rigidite); // pli dû au vent
// Local turbulence
const float turbulence = sinf(onde * 0.7f + b.orientation) * 0.006f; // micro-oscillation
// Plane takeoff blast: stronger near moving source and runway centerline
const float dx = b.x - sourceX; // écart horizontal au souffle
const float dy = b.yBase - souffleY; // écart vertical au souffle
const float distance2 = dx * dx + dy * dy; // distance au carré
const float attenuation = expf(-distance2 / (souffleLargeur * souffleLargeur)); // décroissance spatiale
const float pulse = 0.7f + 0.3f * sinf(onde * 1.8f + 2.0f); // pulsation du jet
const float souffle = souffleMagnitude * attenuation * pulse * (1.12f - b.rigidite); // effet final du jet
// Net lateral displacement tends to follow plane direction (+x) near blast zone
const float deplacementX = vent + turbulence + souffle; // déplacement latéral total
const float tipX = b.x + cosf(b.orientation) * b.largeur + deplacementX; // x de la pointe
const float tipY = b.yBase + b.hauteur; // y de la pointe
if (b.yBase > -0.52f) glColor3f(0.35f, 0.70f, 0.42f); // teinte zone arrière
else glColor3f(0.32f, 0.64f, 0.37f); // teinte zone avant
glVertex2f(b.x, b.yBase); // base du brin
glColor3f(0.49f, 0.79f, 0.46f); // pointe plus claire
glVertex2f(tipX, tipY); // pointe du brin
}
glEnd(); // fin du rendu des lignes
}
// runway
void dessinerPiste1() {
glBegin(GL_QUADS);
glColor3f(0.28f, 0.28f, 0.28f);
glVertex2f(-1.0f, -0.50f); //top left
glVertex2f(1.0f, -0.50f); //top right
glVertex2f(1.0f, -0.80f); //bottom right
glVertex2f(-1.0f, -0.80f); //bottom left
glEnd();
}
void dessinerPiste2() {
glBegin(GL_QUADS);
glColor3f(0.28f, 0.28f, 0.28f);
glVertex2f(-1.0f, -0.3f); //top left
glVertex2f(1.0f, -0.3f); //top right
glVertex2f(1.0f, -0.40f); //bottom right
glVertex2f(-1.0f, -0.40f); //bottom left
glEnd();
}
void dessinerMontagnes() {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// =========================
// Couche 1 : montagnes très loin
// =========================
glBegin(GL_TRIANGLES);
glColor4f(0.55f, 0.68f, 0.78f, 0.45f);
glVertex2f(-1.00f, -0.05f);
glVertex2f(-0.65f, 0.45f);
glVertex2f(-0.25f, -0.05f);
glColor4f(0.58f, 0.70f, 0.80f, 0.42f);
glVertex2f(-0.55f, -0.05f);
glVertex2f(-0.20f, 0.35f);
glVertex2f(0.15f, -0.05f);
glColor4f(0.52f, 0.66f, 0.77f, 0.43f);
glVertex2f(0.00f, -0.05f);
glVertex2f(0.35f, 0.42f);
glVertex2f(0.75f, -0.05f);
glColor4f(0.56f, 0.69f, 0.79f, 0.40f);
glVertex2f(0.45f, -0.05f);
glVertex2f(0.80f, 0.33f);
glVertex2f(1.10f, -0.05f);
glEnd();
// =========================
// Couche 2 : montagnes un peu plus proches
// =========================
glBegin(GL_TRIANGLES);
glColor4f(0.40f, 0.55f, 0.60f, 0.60f);
glVertex2f(-1.10f, -0.10f);
glVertex2f(-0.75f, 0.25f);
glVertex2f(-0.35f, -0.10f);
glColor4f(0.38f, 0.52f, 0.58f, 0.62f);
glVertex2f(-0.60f, -0.10f);
glVertex2f(-0.25f, 0.18f);
glVertex2f(0.10f, -0.10f);
glColor4f(0.36f, 0.50f, 0.56f, 0.58f);
glVertex2f(-0.05f, -0.10f);
glVertex2f(0.25f, 0.28f);
glVertex2f(0.60f, -0.10f);
glColor4f(0.39f, 0.53f, 0.59f, 0.60f);
glVertex2f(0.35f, -0.10f);
glVertex2f(0.70f, 0.20f);
glVertex2f(1.05f, -0.10f);
glEnd();
glDisable(GL_BLEND);
}
// fonction affichage
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
dessinerCiel();
dessinerMontagnes();
for (int i = 0; i < 12; i++) {
float x = -1.0f + i * 0.18f;
bool dark = (i % 2 == 0);
dessinerArbreRealiste(x, -0.25f, 0.5f, dark);
}
for (int i = 0; i < 5; i++)
dessinerNuage(nuages[i].x, nuages[i].y);
dessinerHerbeRealiste();
dessinerPiste1();
dessinerPiste2();
dessinerAvion();
}
// --- Main ---
int main() {
glfwInit();
glfwWindowHint(GLFW_SAMPLES, 4);
GLFWwindow* win;
win = glfwCreateWindow(1400, 900, "Avion OpenGL", NULL, NULL);
glfwMakeContextCurrent(win);
/*
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
win = glfwCreateWindow(mode->width, mode->height, "Avion OpenGL", monitor, NULL);
*/
glfwSwapInterval(1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
srand(42);
for (int i = 0; i < 5; i++) {
nuages[i].x = -0.8f + i * 0.45f; // disposer horizontalement
nuages[i].y = 0.30f + (rand() % 4) * 0.12f; // disposer verticalement au hasard
}
while (!glfwWindowShouldClose(win)) {
display();
glfwSwapBuffers(win);
glfwPollEvents();
}
glfwTerminate();
return 0;
}