-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
874 lines (748 loc) · 32.8 KB
/
main.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
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
//
// main.cpp
// 3D Object Drawing
//
// Created by Nazirul Hasan on 4/9/23.
//
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "shader.h"
#include "camera.h"
#include "basic_camera.h"
#include <iostream>
using namespace std;
//void DrawFan(unsigned int VAO, Shader ourShader,float r);
void DrawBar(unsigned int VAO, Shader ourShader);
void DrawFan(unsigned int VAO, Shader ourShader, float r, glm::mat4 tran_mat);
void DrawWall(unsigned int VAO, Shader ourShader);
void DrawChairTable(unsigned int VAO, Shader ourShader, glm::mat4 tran_mat);
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void processInput(GLFWwindow* window);
// settings
const unsigned int SCR_WIDTH = 1000;
const unsigned int SCR_HEIGHT = 600;
float r = 0.0;
bool rot = false;
// modelling transform
float rotateAngle_X = 45.0;
float rotateAngle_Y = 45.0;
float rotateAngle_Z = 45.0;
float rotateAxis_X = 0.0;
float rotateAxis_Y = 0.0;
float rotateAxis_Z = 1.0;
float translate_X = 0.0;
float translate_Y = 0.0;
float translate_Z = 0.0;
float scale_X = 1.0;
float scale_Y = 1.0;
float scale_Z = 1.0;
// camera
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
float lastX = SCR_WIDTH / 2.0f;
float lastY = SCR_HEIGHT / 2.0f;
bool firstMouse = true;
float eyeX = 0.0, eyeY = 1.0, eyeZ = 3.0;
float lookAtX = 0.0, lookAtY = 0.0, lookAtZ = 0.0;
glm::vec3 V = glm::vec3(0.0f, 1.0f, 0.0f);
BasicCamera basic_camera(eyeX, eyeY, eyeZ, lookAtX, lookAtY, lookAtZ, V);
// timing
float deltaTime = 0.0f; // time between current frame and last frame
float lastFrame = 0.0f;
int main()
{
// glfw: initialize and configure
// ------------------------------
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
// glfw window creation
// --------------------
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "CSE 4208: Computer Graphics Laboratory", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetCursorPosCallback(window, mouse_callback);
glfwSetScrollCallback(window, scroll_callback);
// tell GLFW to capture our mouse
//glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// glad: load all OpenGL function pointers
// ---------------------------------------
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
// configure global opengl state
// -----------------------------
glEnable(GL_DEPTH_TEST);
// build and compile our shader zprogram
// ------------------------------------
Shader ourShader("vertexShader.vs", "fragmentShader.fs");
// set up vertex data (and buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------
/*float cube_vertices[] = {
0.0f, 0.0f, 0.0f, 0.3f, 0.8f, 0.5f,
0.5f, 0.0f, 0.0f, 0.5f, 0.4f, 0.3f,
0.5f, 0.5f, 0.0f, 0.2f, 0.7f, 0.3f,
0.0f, 0.5f, 0.0f, 0.6f, 0.2f, 0.8f,
0.0f, 0.0f, 0.5f, 0.8f, 0.3f, 0.6f,
0.5f, 0.0f, 0.5f, 0.4f, 0.4f, 0.8f,
0.5f, 0.5f, 0.5f, 0.2f, 0.3f, 0.6f,
0.0f, 0.5f, 0.5f, 0.7f, 0.5f, 0.4f
};*/
/*float cube_vertices[] = {
0.0f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.5f, 0.5f, 0.0f,
0.0f, 0.5f, 0.0f,
0.0f, 0.0f, 0.5f,
0.5f, 0.0f, 0.5f,
0.5f, 0.5f, 0.5f,
0.0f, 0.5f, 0.5f
};*/
float cube_vertices[] = {
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f,
0.5f, 0.0f, 0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f,
0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.5f, 1.0f, 1.0f, 0.0f,
0.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.0f,
0.0f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 1.0f,
0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.5f, 0.5f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
0.5f, 0.0f, 0.5f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.5f, 1.0f, 0.0f, 1.0f
};
unsigned int cube_indices[] = {
0, 3, 2,
2, 1, 0,
4, 5, 7,
7, 6, 4,
8, 9, 10,
10, 11, 8,
12, 13, 14,
14, 15, 12,
16, 17, 18,
18, 19, 16,
20, 21, 22,
22, 23, 20
};
/*unsigned int cube_indices[] = {
0, 3, 2,
2, 1, 0,
1, 2, 6,
6, 5, 1,
5, 6, 7,
7 ,4, 5,
4, 7, 3,
3, 0, 4,
6, 2, 3,
3, 7, 6,
1, 5, 4,
4, 0, 1
};*/
/*float cube_vertices[] = {
-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,
-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,
-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,
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,
-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,
-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,
};*/
// world space positions of our cubes
/*glm::vec3 cubePositions[] = {
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(2.0f, 5.0f, -15.0f),
glm::vec3(-1.5f, -2.2f, -2.5f),
glm::vec3(-3.8f, -2.0f, -12.3f),
glm::vec3(2.4f, -0.4f, -3.5f),
glm::vec3(-1.7f, 3.0f, -7.5f),
glm::vec3(1.3f, -2.0f, -2.5f),
glm::vec3(1.5f, 2.0f, -2.5f),
glm::vec3(1.5f, 0.2f, -1.5f),
glm::vec3(-1.3f, 1.0f, -1.5f)
};*/
unsigned int VBO, VAO, EBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), cube_vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cube_indices), cube_indices, GL_STATIC_DRAW);
// position attribute
// glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
//glEnableVertexAttribArray(0);
// position attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
//color attribute
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)12);
glEnableVertexAttribArray(1);
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
//ourShader.use();
// render loop
// -----------
while (!glfwWindowShouldClose(window))
{
// per-frame time logic
// --------------------
float currentFrame = static_cast<float>(glfwGetTime());
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
// input
// -----
processInput(window);
// render
// ------
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// activate shader
ourShader.use();
// pass projection matrix to shader (note that in this case it could change every frame)
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
//glm::mat4 projection = glm::ortho(-2.0f, +2.0f, -1.5f, +1.5f, 0.1f, 100.0f);
ourShader.setMat4("projection", projection);
// camera/view transformation
//glm::mat4 view = camera.GetViewMatrix();
glm::mat4 view = basic_camera.createViewMatrix();
ourShader.setMat4("view", view);
// Modelling Transformation
glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
glm::mat4 translateMatrix, rotateXMatrix, rotateYMatrix, rotateZMatrix, scaleMatrix, model;
//translateMatrix = glm::translate(identityMatrix, glm::vec3(-1.0f, .5f, -.5f));
glm::mat4 tran_mat, tran_mat2,tran_mat3;
tran_mat = identityMatrix;
tran_mat2 = identityMatrix;
tran_mat3 = identityMatrix;
//floor
//DrawWall(VAO, ourShader);
//chair table started
DrawChairTable(VAO,ourShader, identityMatrix);
for (int i = 0; i <= 3; i++)
{
tran_mat = tran_mat * glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f, -1.2f));
DrawChairTable(VAO, ourShader, tran_mat);
}
tran_mat = glm::translate(identityMatrix, glm::vec3(-1.5f, 0.0f, 0.0f));
DrawChairTable(VAO, ourShader, tran_mat);
for (int i = 0; i <= 3; i++)
{
tran_mat = tran_mat * glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f, -1.2f));
DrawChairTable(VAO, ourShader, tran_mat);
}
//Rotating Fan
DrawFan(VAO, ourShader,r,tran_mat3);
tran_mat3 = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f, -1.5f));
DrawFan(VAO, ourShader, r, tran_mat3);
tran_mat3 = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f, -3.0f));
DrawFan(VAO, ourShader, r, tran_mat3);
tran_mat3 = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f, -4.5f));
DrawFan(VAO, ourShader, r, tran_mat3);
tran_mat3 = glm::translate(identityMatrix, glm::vec3(-1.5f, 0.0f, 0.0));
DrawFan(VAO, ourShader, r, tran_mat3);
tran_mat3 = glm::translate(identityMatrix, glm::vec3(-1.5f, 0.0f, -1.5f));
DrawFan(VAO, ourShader, r, tran_mat3);
tran_mat3 = glm::translate(identityMatrix, glm::vec3(-1.5f, 0.0f, -3.0f));
DrawFan(VAO, ourShader, r, tran_mat3);
tran_mat3 = glm::translate(identityMatrix, glm::vec3(-1.5f, 0.0f, -4.5f));
DrawFan(VAO, ourShader, r, tran_mat3);
DrawBar(VAO, ourShader);
tran_mat3 = glm::translate(identityMatrix, glm::vec3(1.5f, 0.0f, -2.0f));
DrawFan(VAO, ourShader, r, tran_mat3);
if(rot)
r = r + 0.5;
//for(int i = 0;i<)
// render boxes
//for (unsigned int i = 0; i < 10; i++)
//{
// // calculate the model matrix for each object and pass it to shader before drawing
// glm::mat4 model = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
// model = glm::translate(model, cubePositions[i]);
// float angle = 20.0f * i;
// model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));
// ourShader.setMat4("model", model);
// glDrawArrays(GL_TRIANGLES, 0, 36);
//}
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}
// optional: de-allocate all resources once they've outlived their purpose:
// ------------------------------------------------------------------------
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &EBO);
// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
glfwTerminate();
return 0;
}
// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
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);
}
if (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS)
{
if (rotateAxis_X) rotateAngle_X -= 1;
else if (rotateAxis_Y) rotateAngle_Y -= 1;
else rotateAngle_Z -= 1;
}
if (glfwGetKey(window, GLFW_KEY_I) == GLFW_PRESS) translate_Y += 0.01;
if (glfwGetKey(window, GLFW_KEY_K) == GLFW_PRESS) translate_Y -= 0.01;
if (glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS) translate_X += 0.01;
if (glfwGetKey(window, GLFW_KEY_J) == GLFW_PRESS) translate_X -= 0.01;
if (glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS) translate_Z += 0.01;
if (glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) translate_Z -= 0.01;
if (glfwGetKey(window, GLFW_KEY_C) == GLFW_PRESS) scale_X += 0.01;
if (glfwGetKey(window, GLFW_KEY_V) == GLFW_PRESS) scale_X -= 0.01;
if (glfwGetKey(window, GLFW_KEY_B) == GLFW_PRESS) scale_Y += 0.01;
if (glfwGetKey(window, GLFW_KEY_N) == GLFW_PRESS) scale_Y -= 0.01;
//if (glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) scale_Z += 0.01;
if (glfwGetKey(window, GLFW_KEY_U) == GLFW_PRESS) scale_Z -= 0.01;
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS)
{
rotateAngle_X += 1;
rotateAxis_X = 1.0;
rotateAxis_Y = 0.0;
rotateAxis_Z = 0.0;
}
if (glfwGetKey(window, GLFW_KEY_Y) == GLFW_PRESS)
{
rotateAngle_Y += 1;
rotateAxis_X = 0.0;
rotateAxis_Y = 1.0;
rotateAxis_Z = 0.0;
}
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)
{
rotateAngle_Z += 1;
rotateAxis_X = 0.0;
rotateAxis_Y = 0.0;
rotateAxis_Z = 1.0;
}
if (glfwGetKey(window, GLFW_KEY_H) == GLFW_PRESS)
{
eyeX += 2.5 * deltaTime;
basic_camera.changeEye(eyeX, eyeY, eyeZ);
}
if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS)
{
eyeX -= 2.5 * deltaTime;
basic_camera.changeEye(eyeX, eyeY, eyeZ);
}
if (glfwGetKey(window, GLFW_KEY_T) == GLFW_PRESS)
{
eyeZ += 2.5 * deltaTime;
basic_camera.changeEye(eyeX, eyeY, eyeZ);
}
if (glfwGetKey(window, GLFW_KEY_G) == GLFW_PRESS)
{
eyeZ -= 2.5 * deltaTime;
basic_camera.changeEye(eyeX, eyeY, eyeZ);
}
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
{
eyeY += 2.5 * deltaTime;
basic_camera.changeEye(eyeX, eyeY, eyeZ);
}
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
{
eyeY -= 1.0 * deltaTime;
basic_camera.changeEye(eyeX, eyeY, eyeZ);
}
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
{
lookAtX += 2.5 * deltaTime;
basic_camera.changeLookAt(lookAtX, lookAtY, lookAtZ);
}
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS)
{
lookAtX -= 2.5 * deltaTime;
basic_camera.changeLookAt(lookAtX, lookAtY, lookAtZ);
}
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS)
{
lookAtY += 2.5 * deltaTime;
basic_camera.changeLookAt(lookAtX, lookAtY, lookAtZ);
}
if (glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS)
{
lookAtY -= 2.5 * deltaTime;
basic_camera.changeLookAt(lookAtX, lookAtY, lookAtZ);
}
if (glfwGetKey(window, GLFW_KEY_5) == GLFW_PRESS)
{
lookAtZ += 2.5 * deltaTime;
basic_camera.changeLookAt(lookAtX, lookAtY, lookAtZ);
}
if (glfwGetKey(window, GLFW_KEY_6) == GLFW_PRESS)
{
lookAtZ -= 2.5 * deltaTime;
basic_camera.changeLookAt(lookAtX, lookAtY, lookAtZ);
}
if (glfwGetKey(window, GLFW_KEY_7) == GLFW_PRESS)
{
basic_camera.changeViewUpVector(glm::vec3(1.0f, 0.0f, 0.0f));
}
if (glfwGetKey(window, GLFW_KEY_8) == GLFW_PRESS)
{
basic_camera.changeViewUpVector(glm::vec3(0.0f, 1.0f, 0.0f));
}
if (glfwGetKey(window, GLFW_KEY_9) == GLFW_PRESS)
{
basic_camera.changeViewUpVector(glm::vec3(0.0f, 0.0f, 1.0f));
}
if (glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS)
{
rot = !rot;
}
}
// glfw: whenever the window size changed (by OS or user resize) this callback function executes
// ---------------------------------------------------------------------------------------------
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
// glfw: whenever the mouse moves, this callback is called
// -------------------------------------------------------
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; // reversed since y-coordinates go from bottom to top
lastX = xpos;
lastY = ypos;
camera.ProcessMouseMovement(xoffset, yoffset);
}
// glfw: whenever the mouse scroll wheel scrolls, this callback is called
// ----------------------------------------------------------------------
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
camera.ProcessMouseScroll(static_cast<float>(yoffset));
}
void DrawChairTable(unsigned int VAO, Shader ourShader, glm::mat4 tran_mat)
{
glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
glm::mat4 translateMatrix, rotateXMatrix, rotateYMatrix, rotateZMatrix, scaleMatrix, model;
//tran_mat = identityMatrix;
//lower surface of table
scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.5f, 0.08f, 0.5f));
model = tran_mat* scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//spindle of table
translateMatrix = glm::translate(identityMatrix, glm::vec3(0.12f, 0.0f, 0.11f));
scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.05f, 0.8f, 0.05f));
model = tran_mat * translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//upper surface of table
translateMatrix = glm::translate(identityMatrix, glm::vec3(-0.25f, 0.4f, -0.12f));
scaleMatrix = glm::scale(identityMatrix, glm::vec3(1.5f, 0.08f, 1.0f));
model = tran_mat * translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//chair seat
translateMatrix = glm::translate(identityMatrix, glm::vec3(-0.25f, 0.0f, -0.3f));
scaleMatrix = glm::scale(identityMatrix, glm::vec3(1.5f, 0.5f, 0.5f));
model = tran_mat * translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//chair back rest
translateMatrix = glm::translate(identityMatrix, glm::vec3(-0.25f, 0.0f, -0.3f));
scaleMatrix = glm::scale(identityMatrix, glm::vec3(1.5f, 1.0f, 0.07f));
model = tran_mat * translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//chair2 seat
translateMatrix = glm::translate(identityMatrix, glm::vec3(-0.25f, 0.0f, 0.3f));
scaleMatrix = glm::scale(identityMatrix, glm::vec3(1.5f, 0.5f, 0.5f));
model = tran_mat * translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//chair2 back rest
translateMatrix = glm::translate(identityMatrix, glm::vec3(-0.25f, 0.0f, 0.55f));
scaleMatrix = glm::scale(identityMatrix, glm::vec3(1.5f, 1.0f, 0.07f));
model = tran_mat * translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
}
void DrawWall(unsigned int VAO, Shader ourShader)
{
glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
glm::mat4 translateMatrix, rotateXMatrix, rotateYMatrix, rotateZMatrix, scaleMatrix, model;
scaleMatrix = glm::scale(identityMatrix, glm::vec3(10.0f, 0.08f, 15.0f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(-2.0f, -0.05f, -6.0f));
model = translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//ceiling
scaleMatrix = glm::scale(identityMatrix, glm::vec3(10.0f, 0.08f, 15.0f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(-2.0f, 1.56f, -6.0f));
model = translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//wall left
scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.08f, 3.22f, 15.0f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(-2.0f, -0.05f, -6.0f));
model = translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//wall right
scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.08f, 3.22f, 15.0f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(2.96f, -0.05f, -6.0f));
model = translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//wall back
scaleMatrix = glm::scale(identityMatrix, glm::vec3(10.0f, 3.22f, 0.08f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(-2.0f, -0.05f, -6.0f));
model = translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//wall front
//scaleMatrix = glm::scale(identityMatrix, glm::vec3(10.0f, 3.0f, 0.08f));
//translateMatrix = glm::translate(identityMatrix, glm::vec3(-2.0f, -0.05f, 1.46f));
//model = translateMatrix * scaleMatrix;
//ourShader.setMat4("model", model);
////ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
//glBindVertexArray(VAO);
//glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
}
void DrawFan(unsigned int VAO, Shader ourShader, float r, glm::mat4 tran_mat)
{
glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
glm::mat4 translateMatrix, rotateXMatrix, rotateYMatrix, rotateZMatrix, scaleMatrix, model;
//fan body
scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.3f, 0.08f, 0.3f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 1.35f, 0.0f));
rotateYMatrix = glm::rotate(identityMatrix, glm::radians(r), glm::vec3(0.0f, 0.075f, 0.0f));
model = tran_mat * glm::translate(identityMatrix, glm::vec3(0.075f, 0.02f, 0.075f)) * rotateYMatrix * glm::translate(identityMatrix, glm::vec3(-0.075f, -0.02f, -0.075f)) * translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//fan spindle
scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.02f, 0.52f, 0.02f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(0.075f, 1.35f, 0.075f));
model = tran_mat * translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//fan blades
//b1 b3
rotateYMatrix = glm::rotate(identityMatrix, glm::radians(r), glm::vec3(0.0f, 0.075f, 0.0f));
scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.1f, 0.015f, 1.6f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0555f, 1.35f, -0.31f));
model = tran_mat * glm::translate(identityMatrix, glm::vec3(0.075f, 0.02f, 0.075f)) * rotateYMatrix * glm::translate(identityMatrix, glm::vec3(-0.075f, -0.02f, -0.075f)) * translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//b2 b4
rotateYMatrix = glm::rotate(identityMatrix, glm::radians(r + 90), glm::vec3(0.0f, 0.075f, 0.0f));
scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.1f, 0.015f, 1.6f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0555f, 1.35f, -0.31f));
model = tran_mat * glm::translate(identityMatrix, glm::vec3(0.075f, 0.02f, 0.075f)) * rotateYMatrix * glm::translate(identityMatrix, glm::vec3(-0.075f, -0.02f, -0.075f)) * translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
}
void DrawBar(unsigned int VAO, Shader ourShader)
{
glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
glm::mat4 translateMatrix, rotateXMatrix, rotateYMatrix, rotateZMatrix, scaleMatrix, model;
translateMatrix = glm::translate(identityMatrix, glm::vec3(1.5f, 0.0f, -4.5f));
scaleMatrix = glm::scale(identityMatrix, glm::vec3(1.8f, 1.22f, 10.0f));
rotateYMatrix = glm::rotate(identityMatrix, glm::radians(r+90), glm::vec3(0.0f, 0.075f, 0.0f));
model = translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
}
/*void DrawFan(unsigned int VAO, Shader ourShader, float r, glm::mat4 tran_mat)
{
glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
glm::mat4 translateMatrix, rotateXMatrix, rotateYMatrix, rotateZMatrix, scaleMatrix, model;
//fan body
scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.3f, 0.08f, 0.3f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 1.35f, 0.0f));
rotateYMatrix = glm::rotate(identityMatrix, glm::radians(r), glm::vec3(0.0f, 0.075f, 0.0f));
model = glm::translate(identityMatrix, glm::vec3(0.075f, 0.02f, 0.075f))* rotateYMatrix* glm::translate(identityMatrix,glm::vec3(-0.075f,-0.02f,-0.075f)) *translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//fan spindle
scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.02f, 0.52f, 0.02f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(0.075f, 1.35f, 0.075f));
model = translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//fan blades
//b1 b3
rotateYMatrix = glm::rotate(identityMatrix, glm::radians(r), glm::vec3(0.0f, 0.075f, 0.0f));
scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.1f, 0.015f, 1.6f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0555f, 1.35f, -0.31f));
model = glm::translate(identityMatrix, glm::vec3(0.075f, 0.02f, 0.075f)) * rotateYMatrix * glm::translate(identityMatrix, glm::vec3(-0.075f, -0.02f, -0.075f)) * translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
//b2 b4
rotateYMatrix = glm::rotate(identityMatrix, glm::radians(r+90), glm::vec3(0.0f, 0.075f, 0.0f));
scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.1f, 0.015f, 1.6f));
translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0555f, 1.35f, -0.31f));
model = glm::translate(identityMatrix, glm::vec3(0.075f, 0.02f, 0.075f)) * rotateYMatrix * glm::translate(identityMatrix, glm::vec3(-0.075f, -0.02f, -0.075f)) * translateMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
////b2
//scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.1f, 0.015f, 0.8f));
//translateMatrix = glm::translate(identityMatrix, glm::vec3(0.055f, 1.35f, -0.35f));
//model = translateMatrix * scaleMatrix;
//ourShader.setMat4("model", model);
////ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
//glBindVertexArray(VAO);
//glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
////b3
//scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.8f, 0.015f, 0.1f));
//translateMatrix = glm::translate(identityMatrix, glm::vec3(0.05f, 1.35f, 0.05f));
//model = translateMatrix * scaleMatrix;
//ourShader.setMat4("model", model);
////ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
//glBindVertexArray(VAO);
//glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
////b4
//scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.8f, 0.015f, 0.1f));
//translateMatrix = glm::translate(identityMatrix, glm::vec3(-0.3f, 1.35f, 0.05f));
//model = translateMatrix * scaleMatrix;
//ourShader.setMat4("model", model);
////ourShader.setVec4("color", glm::vec4(0.2f, 0.1f, 0.4f, 1.0f));
//glBindVertexArray(VAO);
//glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
}*/
//extra code
/*translateMatrix = glm::translate(identityMatrix, glm::vec3(translate_X, translate_Y, translate_Z));
rotateXMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_X), glm::vec3(1.0f, 0.0f, 0.0f));
rotateYMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_Y), glm::vec3(0.0f, 1.0f, 0.0f));
rotateZMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_Z), glm::vec3(0.0f, 0.0f, 1.0f));
scaleMatrix = glm::scale(identityMatrix, glm::vec3(scale_X, scale_Y, scale_Z));
model = translateMatrix * rotateXMatrix * rotateYMatrix * rotateZMatrix * scaleMatrix;
ourShader.setMat4("model", model);
//ourShader.setVec3("aColor", glm::vec3(0.2f, 0.1f, 0.4f));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);*/