-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_tessiture.cpp
More file actions
979 lines (856 loc) · 41.7 KB
/
test_tessiture.cpp
File metadata and controls
979 lines (856 loc) · 41.7 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
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
/******************************************************************************
* File: test_tessiture.cpp
* Author: Michele Cipriani - Tommaso Vilotto
* Description: This project is designed to test various materials
and observe how light interacts with them, particularly through
the effects of their normal maps.
*****************************************************************************/
#include <glad/glad.h>
#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM
#include "imgui/imconfig.h"
#include "imgui/imgui_impl_glfw.h"
#include "imgui/imgui_impl_opengl3.h"
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <learnopengl/shader.h>
#include <learnopengl/camera.h>
#include <learnopengl/model.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include <iostream>
// Callback per ridimensionamento finestra: aggiorna viewport OpenGL
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
// Callback per movimento mouse: aggiorna orientamento camera
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
// Callback per scroll del mouse: aggiorna zoom camera
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
// Gestione input tastiera: aggiorna posizione camera
void processInput(GLFWwindow* window);
// Caricamento texture da file (non usata nel main, ma utile per estensioni)
unsigned int loadTexture(const char* path);
// Renderizza la scena per shadow mapping
void RenderScene(Shader &shader);
// Impostazioni finestra (risoluzione)
const unsigned int SCR_WIDTH = 1800;
const unsigned int SCR_HEIGHT = 1200;
// Shadow map resolution
const unsigned int SHADOW_WIDTH = 8096, SHADOW_HEIGHT = 8096;
// Camera globale (gestisce posizione e orientamento dell'osservatore)
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
float lastX = (float)SCR_WIDTH / 2.0; // Ultima posizione X del mouse
float lastY = (float)SCR_HEIGHT / 2.0; // Ultima posizione Y del mouse
bool firstMouse = true; // Serve per evitare salti all'inizio
// Variabili per il tempo (utile per movimenti smooth e indipendenti dal frame rate)
float deltaTime = 0.0f; // Tempo tra un frame e l'altro
float lastFrame = 0.0f; // Tempo dell'ultimo frame
// === Floor (Pavimento) ===
// Vertici del piano: posizione (3), normale (3), texcoord (2), tangente (3), bitangente (3)
// Le texcoord vanno da 0 a 10 per ripetere la texture 10 volte su X e Z
float planeVertices[] = {
// positions // normals // texcoords // tangent // bitangente
-1.0f, 0.0f, -1.0f, 0,1,0, 0.0f, 0.0f, 1,0,0, 0,0,1,
1.0f, 0.0f, -1.0f, 0,1,0, 100.0f, 0.0f, 1,0,0, 0,0,1,
1.0f, 0.0f, 1.0f, 0,1,0, 100.0f,100.0f, 1,0,0, 0,0,1,
-1.0f, 0.0f, 1.0f, 0,1,0, 0.0f,100.0f, 1,0,0, 0,0,1
};
unsigned int planeIndices[] = {
0, 1, 2,
2, 3, 0
};
unsigned int planeVAO = 0, planeVBO = 0, planeEBO = 0;
unsigned int floorDiffuse, floorNormal, floorgloss;
// === Wall (Muri) ===
// Vertici del muro: posizione (3), normale (3), texcoord (2), tangente (3), bitangente (3)
// Le texcoord sono proporzionali alle dimensioni del muro per evitare stretching
constexpr float wall_tex_x = 9.288005f; // larghezza reale muro
constexpr float wall_tex_y = 2.0f; // aumenta ancora ripetizione verticale per mattoni più corti
float wallVertices[] = {
// positions // normals // texcoords // tangent // bitangent
-1.0f, 0.0f, 0.0f, 0,0,1, 0.0f, 0.0f, 1,0,0, 0,1,0,
1.0f, 0.0f, 0.0f, 0,0,1, wall_tex_x, 0.0f, 1,0,0, 0,1,0,
1.0f, 1.0f, 0.0f, 0,0,1, wall_tex_x, wall_tex_y, 1,0,0, 0,1,0,
-1.0f, 1.0f, 0.0f, 0,0,1, 0.0f, wall_tex_y, 1,0,0, 0,1,0
};
unsigned int wallIndices[] = { 0, 1, 2, 2, 3, 0 };
unsigned int wallVAO = 0, wallVBO = 0, wallEBO = 0;
unsigned int wallDiffuse, wallNormal, wallgloss;
unsigned int ceilingVAO = 0, ceilingVBO = 0, ceilingEBO = 0;
float ceilingVertices[] = {
// positions // normals // texcoords // tangent // bitangente
-1.0f, 0.0f, -1.0f, 0,1,0, 0.0f, 0.0f, 1,0,0, 0,0,1,
1.0f, 0.0f, -1.0f, 0,1,0, 10.0f, 0.0f, 1,0,0, 0,0,1,
1.0f, 0.0f, 1.0f, 0,1,0, 10.0f, 10.0f, 1,0,0, 0,0,1,
-1.0f, 0.0f, 1.0f, 0,1,0, 0.0f, 10.0f, 1,0,0, 0,0,1
};
unsigned int ceilingIndices[] = { 0, 1, 2, 2, 3, 0 };
// posizione faro sinistro
glm::vec3 farettoSxPos = glm::vec3(
-2.73f, // manteniamo X simile
1.181563f, // altezza invariata
3.0f // spostato in avanti rispetto a prima (~3.20 → 1.35)
);
// Risultato: circa (-2.735169, 2.181563, 3.202862)
// posizione faro destro
glm::vec3 farettoDxPos = glm::vec3(
1.78f, // simmetrico
1.181563f, // altezza invariata
3.0f // stesso Z del faretto sinistro
);
// Risultato: circa (1.782247, 2.181563, 3.363492)
// Soffitto
unsigned int ceilingDiffuse, ceilingNormal, ceilinggloss;
// Limiti della stanza (calcolati in base alla posizione e dimensione dei muri)
const float room_min_x = -0.0029815f - 9.288005f/2.0f - 4.14f + 0.5f; // +0.5f margine per non attraversare il muro
const float room_max_x = -0.0029815f + 9.288005f/2.0f + 4.14f - 0.5f;
const float room_min_z = 1.5337835f - 5.676001f/2.0f - 2.34f + 0.5f;
const float room_max_z = 1.5337835f + 5.676001f/2.0f + 2.34f - 0.5f;
const float room_min_y = 0.0f; // pavimento
const float room_max_y = 3.0f - 0.1f; // soffitto (con piccolo margine)
// === Modelli globali come puntatori ===
Model* personaggio = nullptr;
Model* farettodx = nullptr;
Model* farettosx = nullptr;
Model* telo = nullptr;
Model* ventola = nullptr;
Model* divanetto = nullptr;
Model* divanetto2 = nullptr;
Model* tavolino = nullptr;
Model* fotocamera = nullptr;
Model* wall_e = nullptr;
Model* arcade = nullptr;
Model* cap = nullptr;
struct MaterialSet {
std::string diffuse;
std::string gloss;
std::string normal;
};
// Array di materiali disponibili
MaterialSet materiali[] = {
{ // erika originale
"./Progetto/x64/Debug/tex/erika_originale/rp_erika_animated_001_dif.jpg",
"./Progetto/x64/Debug/tex/erika_originale/rp_erika_animated_001_gloss.jpg",
"./Progetto/x64/Debug/tex/erika_originale/rp_erika_animated_001_norm.jpg"
},
{ // boucleFabric
"./Progetto/x64/Debug/tex/boucleFabric/rp_erika_animated_001_dif.jpg",
"./Progetto/x64/Debug/tex/boucleFabric/rp_erika_animated_001_gloss.jpg",
"./Progetto/x64/Debug/tex/boucleFabric/rp_erika_animated_001_norm.jpg"
},
{ // leather
"./Progetto/x64/Debug/tex/leather/rp_erika_animated_001_dif.jpg",
"./Progetto/x64/Debug/tex/leather/rp_erika_animated_001_gloss.jpg",
"./Progetto/x64/Debug/tex/leather/rp_erika_animated_001_norm.jpg"
},
{ // redCotton
"./Progetto/x64/Debug/tex/redCotton/rp_erika_animated_001_dif.jpg",
"./Progetto/x64/Debug/tex/redCotton/rp_erika_animated_001_gloss.jpg",
"./Progetto/x64/Debug/tex/redCotton/rp_erika_animated_001_norm.jpg"
},
{ // simiLino
"./Progetto/x64/Debug/tex/simiLino/rp_erika_animated_001_dif.jpg",
"./Progetto/x64/Debug/tex/simiLino/rp_erika_animated_001_gloss.jpg",
"./Progetto/x64/Debug/tex/simiLino/rp_erika_animated_001_norm.jpg"
},
{ // towelCotton
"./Progetto/x64/Debug/tex/towelCotton/rp_erika_animated_001_dif.jpg",
"./Progetto/x64/Debug/tex/towelCotton/rp_erika_animated_001_gloss.jpg",
"./Progetto/x64/Debug/tex/towelCotton/rp_erika_animated_001_norm.jpg"
},
{ // denim
"./Progetto/x64/Debug/tex/denim/rp_erika_animated_001_dif.jpg",
"./Progetto/x64/Debug/tex/denim/rp_erika_animated_001_gloss.jpg",
"./Progetto/x64/Debug/tex/denim/rp_erika_animated_001_norm.jpg"
}
};
const int numMateriali = sizeof(materiali) / sizeof(MaterialSet);
int materialeCorrente = 0;
string materiali_sel[] = {
"Default Fabric",
"Boucle Fabric",
"Leather",
"Red Cotton",
"Simil Lino",
"Towel Cotton",
"Denim"
};
string scena_sel[] = {
"Studio",
"white background + cemento",
"white background + marble tiles",
"white background + quarzite",
"white background + tiles"
};
unsigned int personaggioDiffuse[numMateriali];
unsigned int personaggioGloss[numMateriali];
unsigned int personaggioNormal[numMateriali];
// Variabile per dimmare la luminosità delle due luci laterali
float intensitaLuciLaterali = 0.3f;
int livelloIntensitaLuci = 1; // 0=spento, 1=bassa, 2=media, 3=alta
const char* intensitaLabels[] = { "Off", "Low", "Medium", "High" };
// === Variabili globali per gestione scena e texture extra ===
int sceneState = 0; // 0: tutto visibile, 1: nascosto cemento, 2: nascosto Marble, 3: nascosto quarzite, 4: nascosto piastrelle
unsigned int floorQuarziteDiffuse, floorQuarziteNormal, floorQuarzitegloss;
unsigned int floorTilesDiffuse, floorTilesNormal, floorTilesgloss;
unsigned int floorTilesMDiffuse, floorTilesMNormal, floorTilesMgloss;
int main()
{
// Inizializza GLFW e imposta versione OpenGL
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Crea la finestra principale
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Graphics Programming Univr - Fabric Simulation", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
// Imposta le callback per input e resize
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetCursorPosCallback(window, mouse_callback);
glfwSetScrollCallback(window, scroll_callback);
// Disabilita il cursore per un'esperienza FPS (mouse catturato)
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// Inizializza GLAD per caricare le funzioni OpenGL
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
// === IMGUI: Inizializzazione ===
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 330");
ImFont* font = io.Fonts->AddFontFromFileTTF("Progetto/x64/Debug/Font/Timeline.ttf", 18.0f * (SCR_HEIGHT / 1080.0f));
io.FontDefault = font;
// Carica i modelli 3D DOPO aver creato il contesto OpenGL
personaggio = new Model("Progetto/x64/Debug/erika.obj");
farettodx = new Model("Progetto/x64/Debug/faretto_dx.obj");
farettosx = new Model("Progetto/x64/Debug/faretto_sx.obj");
telo = new Model("Progetto/x64/Debug/studio.obj");
ventola = new Model("Progetto/x64/Debug/ceiling_fan_(OBJ).obj");
divanetto = new Model("Progetto/x64/Debug/leather_chair(OBJ).obj");
divanetto2 = new Model("Progetto/x64/Debug/leather_chair(OBJ).obj");
tavolino = new Model("Progetto/x64/Debug/Table.obj");
fotocamera = new Model("Progetto/x64/Debug/camera.obj");
wall_e = new Model("Progetto/x64/Debug/wall-e.obj");
arcade = new Model("Progetto/x64/Debug/arcade.obj");
cap = new Model("Progetto/x64/Debug/cap.obj");
// === Caricamento texture per tutti i materiali del personaggio ===
for (int i = 0; i < numMateriali; ++i) {
personaggioDiffuse[i] = loadTexture(materiali[i].diffuse.c_str());
personaggioGloss[i] = loadTexture(materiali[i].gloss.c_str());
personaggioNormal[i] = loadTexture(materiali[i].normal.c_str());
}
// Abilita il depth test per la corretta visualizzazione 3D (gestione profondità)
glEnable(GL_DEPTH_TEST);
// Carica e compila gli shader (vertex e fragment)
Shader shader("progetto.vs", "progetto.fs");
Shader shadowMappingShader("shadow_mapping.vs", "shadow_mapping.fs");
// Configurazione shadow mapping per luceDx, luceSx e luce centrale
unsigned int depthMapFBOLuceDx, depthMapFBOLuceSx;
unsigned int depthMapFBOCentro, depthMapLuceCentro; // Shadow map centrale
glGenFramebuffers(1, &depthMapFBOLuceDx);
glGenFramebuffers(1, &depthMapFBOLuceSx);
glGenFramebuffers(1, &depthMapFBOCentro);
unsigned int depthMapLuceDx, depthMapLuceSx;
glGenTextures(1, &depthMapLuceDx);
glGenTextures(1, &depthMapLuceSx);
glGenTextures(1, &depthMapLuceCentro);
// LuceDx
glBindTexture(GL_TEXTURE_2D, depthMapLuceDx);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
float borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBOLuceDx);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMapLuceDx, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// LuceSx
glBindTexture(GL_TEXTURE_2D, depthMapLuceSx);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBOLuceSx);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMapLuceSx, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// Shadow map centrale
// Inizializzazione texture e FBO centrale
glBindTexture(GL_TEXTURE_2D, depthMapLuceCentro);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBOCentro);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMapLuceCentro, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// === Inizializzazione VAO/VBO/EBO per il piano ===
glGenVertexArrays(1, &planeVAO);
glGenBuffers(1, &planeVBO);
glGenBuffers(1, &planeEBO);
glBindVertexArray(planeVAO);
glBindBuffer(GL_ARRAY_BUFFER, planeVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(planeVertices), planeVertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, planeEBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(planeIndices), planeIndices, GL_STATIC_DRAW);
// posizione
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
// normale
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
// texcoords
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)(6 * sizeof(float)));
glEnableVertexAttribArray(2);
// tangente
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)(8 * sizeof(float)));
glEnableVertexAttribArray(3);
// bitangente
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)(11 * sizeof(float)));
glEnableVertexAttribArray(4);
glBindVertexArray(0);
// Inizializzazione VAO/VBO/EBO per il soffitto
glGenVertexArrays(1, &ceilingVAO);
glGenBuffers(1, &ceilingVBO);
glGenBuffers(1, &ceilingEBO);
glBindVertexArray(ceilingVAO);
glBindBuffer(GL_ARRAY_BUFFER, ceilingVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(ceilingVertices), ceilingVertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ceilingEBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(ceilingIndices), ceilingIndices, GL_STATIC_DRAW);
// posizione
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
// normale
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
// texcoords
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)(6 * sizeof(float)));
glEnableVertexAttribArray(2);
// tangente
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)(8 * sizeof(float)));
glEnableVertexAttribArray(3);
// bitangente
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)(11 * sizeof(float)));
glEnableVertexAttribArray(4);
glBindVertexArray(0);
// === Caricamento texture per il Soffitto ===
ceilingDiffuse = loadTexture("./Progetto/x64/Debug/tex/soffitto/Ceiling_Drop_Tiles_001_basecolor.jpg");
ceilingNormal = loadTexture("./Progetto/x64/Debug/tex/soffitto/Ceiling_Drop_Tiles_001_normal.jpg");
ceilinggloss = loadTexture("./Progetto/x64/Debug/tex/soffitto/Ceiling_Drop_Tiles_001_gloss.jpg");
// === Caricamento texture Poliigon per il pavimento ===
floorDiffuse = loadTexture("./Progetto/x64/Debug/tex/pavimento_cemento/Poliigon_ConcreteFloorPoured_7656_BaseColor.jpg");
floorNormal = loadTexture("./Progetto/x64/Debug/tex/pavimento_cemento/Poliigon_ConcreteFloorPoured_7656_Normal.png");
floorgloss = loadTexture("./Progetto/x64/Debug/tex/pavimento_cemento/Poliigon_ConcreteFloorPoured_7656_gloss.jpg");
// === Caricamento texture piastrelle Marble ===
floorTilesMDiffuse = loadTexture("./Progetto/x64/Debug/tex/pavimento_stelle/Patterned_Marble_Tiles_vichadav_8K_BaseColor.jpg");
floorTilesMNormal = loadTexture("./Progetto/x64/Debug/tex/pavimento_stelle/Patterned_Marble_Tiles_vichadav_8K_Normal.jpg");
floorTilesMgloss = loadTexture("./Progetto/x64/Debug/tex/pavimento_stelle/Patterned_Marble_Tiles_vichadav_8K_gloss.jpg");
// === Caricamento texture quarzite ===
floorQuarziteDiffuse = loadTexture("./Progetto/x64/Debug/tex/pavimento_quarzite/Poliigon_quarzite_5212_BaseColor.jpg");
floorQuarziteNormal = loadTexture("./Progetto/x64/Debug/tex/pavimento_quarzite/Poliigon_quarzite_5212_Normal.png");
floorQuarzitegloss = loadTexture("./Progetto/x64/Debug/tex/pavimento_quarzite/Poliigon_quarzite_5212_gloss.jpg");
// === Caricamento texture piastrelle ===
floorTilesDiffuse = loadTexture("./Progetto/x64/Debug/tex/pavimento_piastrelle/Poliigon_TilesCeramicWhite_6956_BaseColor.jpg");
floorTilesNormal = loadTexture("./Progetto/x64/Debug/tex/pavimento_piastrelle/Poliigon_TilesCeramicWhite_6956_Normal.png");
floorTilesgloss = loadTexture("./Progetto/x64/Debug/tex/pavimento_piastrelle/Poliigon_TilesCeramicWhite_6956_gloss.jpg");
// === Inizializzazione VAO/VBO/EBO per il muro ===
glGenVertexArrays(1, &wallVAO);
glGenBuffers(1, &wallVBO);
glGenBuffers(1, &wallEBO);
glBindVertexArray(wallVAO);
glBindBuffer(GL_ARRAY_BUFFER, wallVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(wallVertices), wallVertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, wallEBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(wallIndices), wallIndices, GL_STATIC_DRAW);
// posizione
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
// normale
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
// texcoords
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)(6 * sizeof(float)));
glEnableVertexAttribArray(2);
// tangente
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)(8 * sizeof(float)));
glEnableVertexAttribArray(3);
// bitangente
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void*)(11 * sizeof(float)));
glEnableVertexAttribArray(4);
glBindVertexArray(0);
// === Caricamento texture per i muri ===
wallDiffuse = loadTexture("./Progetto/x64/Debug/tex/muri/Poliigon_PlasterPainted_7664_BaseColor.jpg");
wallNormal = loadTexture("./Progetto/x64/Debug/tex/muri/Poliigon_PlasterPainted_7664_Normal.png");
wallgloss = loadTexture("./Progetto/x64/Debug/tex/muri/Poliigon_PlasterPainted_7664_gloss.jpg");
// Ciclo di rendering principale
while (!glfwWindowShouldClose(window))
{
// Calcola il tempo trascorso tra un frame e l'altro (per movimenti smooth)
float currentFrame = static_cast<float>(glfwGetTime());
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
// Gestione input tastiera/mouse
processInput(window);
// Rendering shadow map per luceDx
glm::vec3 luceDxPos(1.25f, 1.9f, 1.6f);
glm::vec3 luceDxTarget(0.5f, 1.4f, 0.5f);
glm::vec3 luceDxDir = glm::normalize(luceDxTarget - luceDxPos);
float near_plane = 0.1f, far_plane = 20.0f;
float ortho_size = 10.0f;
glm::mat4 luceDxProjection = glm::ortho(-ortho_size, ortho_size, -ortho_size, ortho_size, near_plane, far_plane);
glm::mat4 luceDxView = glm::lookAt(luceDxPos, luceDxTarget, glm::vec3(0, 1, 0));
glm::mat4 luceDxSpaceMatrix = luceDxProjection * luceDxView;
shadowMappingShader.use();
shadowMappingShader.setMat4("lightSpaceMatrix", luceDxSpaceMatrix);
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBOLuceDx);
glClear(GL_DEPTH_BUFFER_BIT);
RenderScene(shadowMappingShader);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// Rendering shadow map per luceSx
glm::vec3 luceSxPos(-1.25f, 1.9f, 1.6f);
glm::vec3 luceSxTarget(-0.4f, 1.4f, 0.4f);
glm::vec3 luceSxDir = glm::normalize(luceSxTarget - luceSxPos);
glm::mat4 luceSxProjection = glm::ortho(-ortho_size, ortho_size, -ortho_size, ortho_size, near_plane, far_plane);
glm::mat4 luceSxView = glm::lookAt(luceSxPos, luceSxTarget, glm::vec3(0, 1, 0));
glm::mat4 luceSxSpaceMatrix = luceSxProjection * luceSxView;
shadowMappingShader.use();
shadowMappingShader.setMat4("lightSpaceMatrix", luceSxSpaceMatrix);
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBOLuceSx);
glClear(GL_DEPTH_BUFFER_BIT);
RenderScene(shadowMappingShader);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// Rendering shadow map per luce centrale
glm::vec3 luceCentroPos = 0.5f * (luceDxPos + luceSxPos) + glm::vec3(0.0f, 0.5f, 0.7f); // più alta
glm::vec3 luceCentroTarget = 0.5f * (luceDxTarget + luceSxTarget) + glm::vec3(0.0f, 0.5f, 0.0f); // punta più in basso
glm::mat4 luceCentroProjection = glm::ortho(-ortho_size, ortho_size, -ortho_size, ortho_size, near_plane, far_plane);
glm::mat4 luceCentroView = glm::lookAt(luceCentroPos, luceCentroTarget, glm::vec3(0, 1, 0));
glm::mat4 luceCentroSpaceMatrix = luceCentroProjection * luceCentroView;
shadowMappingShader.use();
shadowMappingShader.setMat4("lightSpaceMatrix", luceCentroSpaceMatrix);
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBOCentro);
glClear(GL_DEPTH_BUFFER_BIT);
RenderScene(shadowMappingShader);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
//Rendering normale della scena con shadow mapping
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); //sfondo bianco
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader.use();
// Calcola le matrici di proiezione e vista (telecamera)
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
glm::mat4 view = camera.GetViewMatrix();
shader.setMat4("projection", projection); // Passa la matrice di proiezione allo shader
shader.setMat4("view", view); // Passa la matrice di vista allo shader
// Matrice modello identità
glm::mat4 model = glm::mat4(1.0f);
// Riduci la scala del modello
model = glm::scale(model, glm::vec3(1.0f));
shader.setMat4("model", model); // Passa la matrice modello allo shader
// Passa la posizione della camera sia come viewPos che come lightPos (spotlight)
shader.setVec3("viewPos", camera.Position); // Posizione osservatore
shader.setVec3("lightPos", camera.Position); // La luce segue la camera
// Passa anche la direzione della camera come spotlightDir
shader.setVec3("spotlightDir", camera.Front); // Direzione della spotlight
shader.setVec3("luceDxPos", luceDxPos);
shader.setVec3("luceDxDir", luceDxDir);
shader.setFloat("luceDxAngle", 191.0f);
shader.setMat4("luceDxSpaceMatrix", luceDxSpaceMatrix);
shader.setVec3("luceSxPos", luceSxPos);
shader.setVec3("luceSxDir", luceSxDir);
shader.setFloat("luceSxAngle", 191.0f);
shader.setMat4("luceSxSpaceMatrix", luceSxSpaceMatrix);
shader.setFloat("intensitaLuciLaterali", intensitaLuciLaterali);
glActiveTexture(GL_TEXTURE5);
glBindTexture(GL_TEXTURE_2D, depthMapLuceDx);
shader.setInt("shadowMapLuceDx", 5);
glActiveTexture(GL_TEXTURE6);
glBindTexture(GL_TEXTURE_2D, depthMapLuceSx);
shader.setInt("shadowMapLuceSx", 6);
glActiveTexture(GL_TEXTURE7);
glBindTexture(GL_TEXTURE_2D, depthMapLuceCentro);
shader.setInt("shadowMapLuceCentro", 7);
shader.setMat4("luceCentroSpaceMatrix", luceCentroSpaceMatrix);
// Renderizza la scena
RenderScene(shader);
// Inizio frame ImGui
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Finestra custom
ImGui::SetNextWindowSize(ImVec2(SCR_WIDTH * 0.215f, SCR_HEIGHT * 0.12f), ImGuiCond_Always);
ImGui::Begin("Info");
ImGui::Text("Materiale corrente: %s", materiali_sel[materialeCorrente].c_str());
ImGui::Text("Intensita luci laterali: %s", intensitaLabels[livelloIntensitaLuci]);
ImGui::Text("Ambiente: %s", scena_sel[sceneState].c_str());
ImGui::End();
// Rendering ImGui
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
// Scambia i buffer e gestisce gli eventi di input
glfwSwapBuffers(window);
glfwPollEvents();
}
// Libera le risorse e termina l'applicazione
delete personaggio;
delete farettodx;
delete farettosx;
delete telo;
delete ventola;
delete divanetto;
delete divanetto2;
delete tavolino;
delete fotocamera;
delete wall_e;
delete arcade;
delete cap;
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwTerminate();
return 0;
}
// Gestione input tastiera: aggiorna la posizione della camera in base ai tasti premuti
void processInput(GLFWwindow* window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
camera.ProcessKeyboard(FORWARD, deltaTime);
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
camera.ProcessKeyboard(BACKWARD, deltaTime);
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
camera.ProcessKeyboard(LEFT, deltaTime);
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
camera.ProcessKeyboard(RIGHT, deltaTime);
static bool mPressed = false;
if (glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS && !mPressed) {
materialeCorrente = (materialeCorrente + 1) % numMateriali;
mPressed = true;
}
if (glfwGetKey(window, GLFW_KEY_M) == GLFW_RELEASE) {
mPressed = false;
}
static bool cPressed = false;
if (glfwGetKey(window, GLFW_KEY_C) == GLFW_PRESS && !cPressed) {
sceneState = (sceneState + 1) % 5;
cPressed = true;
}
if (glfwGetKey(window, GLFW_KEY_C) == GLFW_RELEASE) {
cPressed = false;
}
// --- Gestione intensità luci laterali con L ---
static bool lPressed = false;
if (glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS && !lPressed) {
livelloIntensitaLuci = (livelloIntensitaLuci + 1) % 4;
switch (livelloIntensitaLuci) {
case 0: intensitaLuciLaterali = 0.0f; break; // spento
case 1: intensitaLuciLaterali = 0.1f; break; // bassa
case 2: intensitaLuciLaterali = 0.2f; break; // media
case 3: intensitaLuciLaterali = 0.3f; break; // alta
}
lPressed = true;
}
if (glfwGetKey(window, GLFW_KEY_L) == GLFW_RELEASE) {
lPressed = false;
}
// Vincola la posizione della camera all'interno delle mura
camera.Position.x = glm::clamp(camera.Position.x, room_min_x, room_max_x);
camera.Position.y = glm::clamp(camera.Position.y, room_min_y+0.2f, room_max_y-0.2f);
camera.Position.z = glm::clamp(camera.Position.z, room_min_z, room_max_z);
}
// Callback per il ridimensionamento della finestra: aggiorna la viewport OpenGL
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
// Callback per il movimento del mouse: aggiorna l'orientamento della camera
void mouse_callback(GLFWwindow* window, double xposIn, double yposIn)
{
float xpos = static_cast<float>(xposIn);
float ypos = static_cast<float>(yposIn);
if (firstMouse)
{
lastX = xpos;
lastY = ypos;
firstMouse = false;
}
float xoffset = xpos - lastX;
float yoffset = lastY - ypos; // Invertito perché le y crescono dal basso verso l'alto
lastX = xpos;
lastY = ypos;
camera.ProcessMouseMovement(xoffset, yoffset);
}
// Callback per lo scroll del mouse: aggiorna lo zoom della camera
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
camera.ProcessMouseScroll(static_cast<float>(yoffset));
}
// Carica una texture da file e restituisce l'ID OpenGL della texture
// (Non usata direttamente nel main, ma utile per estensioni future)
unsigned int loadTexture(char const* path)
{
unsigned int textureID;
glGenTextures(1, &textureID);
int width, height, nrComponents;
unsigned char* data = stbi_load(path, &width, &height, &nrComponents, 0);
if (data)
{
GLenum format;
if (nrComponents == 1)
format = GL_RED;
else if (nrComponents == 3)
format = GL_RGB;
else if (nrComponents == 4)
format = GL_RGBA;
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
// Imposta i parametri di wrapping e filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, format == GL_RGBA ? GL_CLAMP_TO_EDGE : GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, format == GL_RGBA ? GL_CLAMP_TO_EDGE : GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
stbi_image_free(data);
}
else
{
std::cout << "Texture failed to load at path: " << path << std::endl;
stbi_image_free(data);
}
return textureID;
}
// Renderizza la scena per shadow mapping
void RenderScene(Shader &shader)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, personaggioDiffuse[materialeCorrente]);
shader.setInt("texture_diffuse1", 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, personaggioNormal[materialeCorrente]);
shader.setInt("texture_normal1", 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, personaggioGloss[materialeCorrente]);
shader.setInt("texture_specular1", 2);
// Modello del personaggio
glm::mat4 model = glm::mat4(1.0f);
model = glm::scale(model, glm::vec3(1.0f));
shader.setMat4("model", model);
if (personaggio) personaggio->Draw(shader);
// Modello della cappello
model = glm::mat4(1.0f);
model = glm::scale(model, glm::vec3(1.0f));
shader.setMat4("model", model);
if (cap) cap->Draw(shader);
if (sceneState == 0) {
// Tutti gli oggetti visibili
// Modello del faretto dx
model = glm::mat4(1.0f);
model = glm::scale(model, glm::vec3(1.0f));
shader.setMat4("model", model);
if(farettodx) farettodx->Draw(shader);
// Modello del faretto sx
model = glm::mat4(1.0f);
model = glm::scale(model, glm::vec3(1.0f));
shader.setMat4("model", model);
if(farettosx) farettosx->Draw(shader);
// Modello del telo/rampa
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(0.0f, 0.01f, 0.0f));
model = glm::scale(model, glm::vec3(0.6f));
shader.setMat4("model", model);
if(telo) telo->Draw(shader);
// Modello della ventola
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(0.0f, 2.7f, 0.0f));
model = glm::scale(model, glm::vec3(0.6f));
shader.setMat4("model", model);
if(ventola) ventola->Draw(shader);
// Modello del divanetto
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(2.0f, 0.01f, 5.5f));
model = glm::rotate(model, glm::radians(180.0f), glm::vec3(0, 1, 0));
model = glm::rotate(model, glm::radians(20.0f), glm::vec3(0, 1, 0));
model = glm::scale(model, glm::vec3(1.0f));
shader.setMat4("model", model);
if(divanetto) divanetto->Draw(shader);
// Modello del divanetto 2
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(-2.0f, 0.01f, 5.5f));
model = glm::rotate(model, glm::radians(160.0f), glm::vec3(0, 1, 0));
model = glm::scale(model, glm::vec3(1.0f));
shader.setMat4("model", model);
if(divanetto2) divanetto2->Draw(shader);
// Modello del tavolino
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(0.0f, 0.01f, 5.2f));
model = glm::rotate(model, glm::radians(180.0f), glm::vec3(0, 1, 0));
model = glm::scale(model, glm::vec3(0.03f));
shader.setMat4("model", model);
if(tavolino) tavolino->Draw(shader);
// Modello della fotocamera
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(0.0f, 0.78f, 5.2f));
model = glm::scale(model, glm::vec3(1.0f));
shader.setMat4("model", model);
if(fotocamera) fotocamera->Draw(shader);
// Modello della wall_e
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(8.5f, 0.01f, 6.2f));
model = glm::rotate(model, glm::radians(50.0f), glm::vec3(0, 1, 0));
model = glm::scale(model, glm::vec3(0.008f));
shader.setMat4("model", model);
if (wall_e) wall_e->Draw(shader);
// Modello della macchina arcade
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(-8.2f, 0.01f, 6.2f));
model = glm::rotate(model, glm::radians(120.0f), glm::vec3(0, 1, 0));
model = glm::scale(model, glm::vec3(1.0f));
shader.setMat4("model", model);
if (arcade) arcade->Draw(shader);
// === Soffitto ===
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, ceilingDiffuse);
shader.setInt("texture_diffuse1", 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, ceilingNormal);
shader.setInt("texture_normal1", 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, ceilinggloss);
shader.setInt("texture_specular1", 2);
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(-0.0029815f, 3.0f, 1.5337835f));
model = glm::rotate(model, glm::radians(180.0f), glm::vec3(1, 0, 0));
model = glm::scale(model, glm::vec3(9.288005f, 1.0f, 5.676001f));
shader.setMat4("model", model);
glBindVertexArray(ceilingVAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
// === Muri ===
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, wallDiffuse);
shader.setInt("texture_diffuse1", 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, wallNormal);
shader.setInt("texture_normal1", 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, wallgloss);
shader.setInt("texture_specular1", 2);
float wall_height = 3.0f;
float wall_thickness = 1.0f;
glm::vec3 floor_center_position = glm::vec3(-0.0029815f, 0.0f, 1.5337835f);
float floor_size_x = 9.288005f;
float floor_size_z = 5.676001f;
// Back wall
model = glm::mat4(1.0f);
model = glm::translate(model, floor_center_position + glm::vec3(0.0f, 0.0f, -floor_size_z/2.0f - wall_thickness/2.0f - 2.34f));
model = glm::scale(model, glm::vec3(floor_size_x, wall_height, wall_thickness));
shader.setMat4("model", model);
glBindVertexArray(wallVAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
// Front wall
model = glm::mat4(1.0f);
model = glm::translate(model, floor_center_position + glm::vec3(0.0f, 0.0f, floor_size_z/2.0f + wall_thickness/2.0f + 2.34f));
model = glm::rotate(model, glm::radians(180.0f), glm::vec3(0, 1, 0));
model = glm::scale(model, glm::vec3(floor_size_x, wall_height, wall_thickness));
shader.setMat4("model", model);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
// Left wall
model = glm::mat4(1.0f);
model = glm::translate(model, floor_center_position + glm::vec3(-floor_size_x/2.0f - wall_thickness/2.0f - 4.14f, 0.0f, 0.0f));
model = glm::rotate(model, glm::radians(90.0f), glm::vec3(0,1,0));
model = glm::scale(model, glm::vec3(floor_size_z, wall_height, wall_thickness));
shader.setMat4("model", model);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
// Right wall
model = glm::mat4(1.0f);
model = glm::translate(model, floor_center_position + glm::vec3(floor_size_x/2.0f + wall_thickness/2.0f + 4.14f, 0.0f, 0.0f));
model = glm::rotate(model, glm::radians(180.0f), glm::vec3(0, 1, 0));
model = glm::rotate(model, glm::radians(90.0f), glm::vec3(0,1,0));
model = glm::scale(model, glm::vec3(floor_size_z, wall_height, wall_thickness));
shader.setMat4("model", model);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
}
// === Pavimento: scegli texture in base allo stato ===
if (sceneState == 3) {
// Pavimento quarzite
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, floorQuarziteDiffuse);
shader.setInt("texture_diffuse1", 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, floorQuarziteNormal);
shader.setInt("texture_normal1", 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, floorQuarzitegloss);
shader.setInt("texture_specular1", 2);
} else if (sceneState == 4) {
// Pavimento piastrelle
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, floorTilesDiffuse);
shader.setInt("texture_diffuse1", 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, floorTilesNormal);
shader.setInt("texture_normal1", 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, floorTilesgloss);
shader.setInt("texture_specular1", 2);
}
else if (sceneState == 2) {
// Pavimento piastrelle Marble
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, floorTilesMDiffuse);
shader.setInt("texture_diffuse1", 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, floorTilesMNormal);
shader.setInt("texture_normal1", 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, floorTilesMgloss);
shader.setInt("texture_specular1", 2);
} else {
// Pavimento cemento
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, floorDiffuse);
shader.setInt("texture_diffuse1", 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, floorNormal);
shader.setInt("texture_normal1", 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, floorgloss);
shader.setInt("texture_specular1", 2);
}
glm::vec3 floor_center_position = glm::vec3(-0.0029815f, 0.0f, 1.5337835f);
model = glm::mat4(1.0f);
model = glm::translate(model, floor_center_position);
model = glm::scale(model, glm::vec3(100.0f, 1.0f, 100.0f));
shader.setMat4("model", model);
glBindVertexArray(planeVAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
}