Facebook
From Waliul Islam Sumon, 2 Months ago, written in C++.
Embed
Download Paste or View Raw
Hits: 302
  1. //
  2. //  main.cpp
  3. //  3D Object Drawing
  4. //
  5. //  Created by Nazirul Hasan on 4/9/23.
  6. //
  7.  
  8. #include <glad/glad.h>
  9. #include <GLFW/glfw3.h>
  10.  
  11. #include <glm/glm.hpp>
  12. #include <glm/gtc/matrix_transform.hpp>
  13. #include <glm/gtc/type_ptr.hpp>
  14.  
  15. #include "shader.h"
  16. #include "camera.h"
  17. #include "basic_camera.h"
  18.  
  19. #include <iostream>
  20. #include <stdlib.h>
  21. #include<windows.h>  
  22.  
  23. using namespace std;
  24.  
  25. void framebuffer_size_callback(GLFWwindow* window, int width, int height);
  26. //void mouse_callback(GLFWwindow* window, double xpos, double ypos);
  27. void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
  28. void processInput(GLFWwindow* window);
  29. void Table(Shader ourshader, glm::mat4 moveMatrix);
  30. void Chair(Shader ourShader, glm::mat4 moveMatrix);
  31. void SideWall(Shader ourShader, glm::mat4 moveMatrix);
  32. void FrontWall(Shader ourShader, glm::mat4 moveMatrix);
  33. void Roof(Shader ourShader, glm::mat4 moveMatrix, glm::vec4 color);
  34. void Floor(Shader ourShader, glm::mat4 moveMatrix, glm::vec4 color);
  35. void BlackBoard(Shader ourShader, glm::mat4 moveMatrix);
  36. void Fan1(Shader ourShader);
  37. void Fan2(Shader ourShader);
  38.  
  39.  
  40. // settings
  41. const unsigned int SCR_WIDTH = 1200;
  42. const unsigned int SCR_HEIGHT = 600;
  43.  
  44. // modelling transform
  45. float rotateAngle_X = 0.0;
  46. float rotateAngle_Y = 0.0;
  47. float rotateAngle_Z = 0.0;
  48. float rotateAxis_X = 0.0;
  49. float rotateAxis_Y = 0.0;
  50. float rotateAxis_Z = 0.0;
  51. float translate_X = 0.0;
  52. float translate_Y = 0.0;
  53. float translate_Z = 0.0;
  54. float scale_X = 1.0;
  55. float scale_Y = 1.0;
  56. float scale_Z = 1.0;
  57.  
  58. // camera
  59. Camera camera(glm::vec3(0.0f, 1.0f, 2.7f));
  60. float lastX = SCR_WIDTH / 2.0f;
  61. float lastY = SCR_HEIGHT / 2.0f;
  62. bool firstMouse = true;
  63.  
  64. float eyeX = 0.0, eyeY = 1.0, eyeZ = 2.7;
  65. float lookAtX = 0.0, lookAtY = 1.0, lookAtZ = 0.0;
  66. glm::vec3 V = glm::vec3(0.0f, 1.0f, 0.0f);
  67. BasicCamera basic_camera(eyeX, eyeY, eyeZ, lookAtX, lookAtY, lookAtZ, V);
  68.  
  69. // timing
  70. float deltaTime = 0.0f;    // time between current frame and last frame
  71. float lastFrame = 0.0f;
  72.  
  73.  
  74. //rotate
  75. bool isRotate = false;
  76. float fanSpeed = 2.7f;
  77.  
  78. int main()
  79. {
  80.     // glfw: initialize and configure
  81.     // ------------------------------
  82.     glfwInit();
  83.     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  84.     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  85.     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  86.  
  87. #ifdef __APPLE__
  88.     glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  89. #endif
  90.  
  91.     // glfw window creation
  92.     // --------------------
  93.     GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "CSE 4208: Computer Graphics Laboratory", NULL, NULL);
  94.     if (window == NULL)
  95.     {
  96.         std::cout << "Failed to create GLFW window" << std::endl;
  97.         glfwTerminate();
  98.         return -1;
  99.     }
  100.     glfwMakeContextCurrent(window);
  101.     glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
  102.     //glfwSetCursorPosCallback(window, mouse_callback);
  103.     glfwSetScrollCallback(window, scroll_callback);
  104.  
  105.     // tell GLFW to capture our mouse
  106.     glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
  107.  
  108.     // glad: load all OpenGL function pointers
  109.     // ---------------------------------------
  110.     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
  111.     {
  112.         std::cout << "Failed to initialize GLAD" << std::endl;
  113.         return -1;
  114.     }
  115.  
  116.     // configure global opengl state
  117.     // -----------------------------
  118.     glEnable(GL_DEPTH_TEST);
  119.  
  120.     // build and compile our shader zprogram
  121.     // ------------------------------------
  122.     Shader ourShader("vertexShader.vs", "fragmentShader.fs");
  123.  
  124.     // set up vertex data (and buffer(s)) and configure vertex attributes
  125.     // ------------------------------------------------------------------
  126.  
  127.  
  128.     //// For axis
  129.     //float axisVertices[] = {
  130.     //    // X axis          // Color
  131.     //    -1.0f, 0.0f, 0.0f,  1.0f, 0.0f, 0.0f,            //Red
  132.     //    1.0f, 0.0f, 0.0f,  1.0f, 0.0f, 0.0f,
  133.  
  134.     //    // Y axis
  135.     //    0.0f, -1.0f, 0.0f,  0.0f, 1.0f, 0.0f,            //Green
  136.     //    0.0f, 1.0f, 0.0f,  0.0f, 1.0f, 0.0f,
  137.  
  138.     //    // Z axis
  139.     //    0.0f, 0.0f, -1.0f,  0.0f, 0.0f, 1.0f,            //Blue
  140.     //    0.0f, 0.0f, 1.0f,  0.0f, 0.0f, 1.0f
  141.     //};
  142.  
  143.     /*float cube_vertices[] = {
  144.         0.0f, 0.0f, 0.0f, 0.3f, 0.8f, 0.5f,
  145.         0.5f, 0.0f, 0.0f, 0.5f, 0.4f, 0.3f,
  146.         0.5f, 0.5f, 0.0f, 0.2f, 0.7f, 0.3f,
  147.         0.0f, 0.5f, 0.0f, 0.6f, 0.2f, 0.8f,
  148.         0.0f, 0.0f, 0.5f, 0.8f, 0.3f, 0.6f,
  149.         0.5f, 0.0f, 0.5f, 0.4f, 0.4f, 0.8f,
  150.         0.5f, 0.5f, 0.5f, 0.2f, 0.3f, 0.6f,
  151.         0.0f, 0.5f, 0.5f, 0.7f, 0.5f, 0.4f
  152.     };*/
  153.     /*float cube_vertices[] = {
  154.         0.0f, 0.0f, 0.0f,
  155.         0.5f, 0.0f, 0.0f,
  156.         0.5f, 0.5f, 0.0f,
  157.         0.0f, 0.5f, 0.0f,
  158.         0.0f, 0.0f, 0.5f,
  159.         0.5f, 0.0f, 0.5f,
  160.         0.5f, 0.5f, 0.5f,
  161.         0.0f, 0.5f, 0.5f
  162.     };*/
  163.     float cube_vertices[] = {
  164.         0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
  165.         0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
  166.         0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f,
  167.         0.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f,
  168.  
  169.         0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
  170.         0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f,
  171.         0.5f, 0.0f, 0.5f, 0.0f, 1.0f, 0.0f,
  172.         0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
  173.  
  174.         0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f,
  175.         0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f,
  176.         0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
  177.         0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
  178.  
  179.         0.0f, 0.0f, 0.5f, 1.0f, 1.0f, 0.0f,
  180.         0.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.0f,
  181.         0.0f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f,
  182.         0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
  183.  
  184.         0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 1.0f,
  185.         0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f,
  186.         0.0f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f,
  187.         0.0f, 0.5f, 0.5f, 0.0f, 1.0f, 1.0f,
  188.  
  189.         0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  190.         0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  191.         0.5f, 0.0f, 0.5f, 1.0f, 0.0f, 1.0f,
  192.         0.0f, 0.0f, 0.5f, 1.0f, 0.0f, 1.0f
  193.     };
  194.     unsigned int cube_indices[] = {
  195.         0, 3, 2,
  196.         2, 1, 0,
  197.  
  198.         4, 5, 7,
  199.         7, 6, 4,
  200.  
  201.         8, 9, 10,
  202.         10, 11, 8,
  203.  
  204.         12, 13, 14,
  205.         14, 15, 12,
  206.  
  207.         16, 17, 18,
  208.         18, 19, 16,
  209.  
  210.         20, 21, 22,
  211.         22, 23, 20
  212.     };
  213.     /*unsigned int cube_indices[] = {
  214.         0, 3, 2,
  215.         2, 1, 0,
  216.  
  217.         1, 2, 6,
  218.         6, 5, 1,
  219.  
  220.         5, 6, 7,
  221.         7 ,4, 5,
  222.  
  223.         4, 7, 3,
  224.         3, 0, 4,
  225.  
  226.         6, 2, 3,
  227.         3, 7, 6,
  228.  
  229.         1, 5, 4,
  230.         4, 0, 1
  231.     };*/
  232.     /*float cube_vertices[] = {
  233.         -0.5f, -0.5f, -0.5f,
  234.          0.5f, -0.5f, -0.5f,
  235.          0.5f,  0.5f, -0.5f,
  236.          0.5f,  0.5f, -0.5f,
  237.         -0.5f,  0.5f, -0.5f,
  238.         -0.5f, -0.5f, -0.5f,
  239.  
  240.         -0.5f, -0.5f,  0.5f,
  241.          0.5f, -0.5f,  0.5f,
  242.          0.5f,  0.5f,  0.5f,
  243.          0.5f,  0.5f,  0.5f,
  244.         -0.5f,  0.5f,  0.5f,
  245.         -0.5f, -0.5f,  0.5f,
  246.  
  247.         -0.5f,  0.5f,  0.5f,
  248.         -0.5f,  0.5f, -0.5f,
  249.         -0.5f, -0.5f, -0.5f,
  250.         -0.5f, -0.5f, -0.5f,
  251.         -0.5f, -0.5f,  0.5f,
  252.         -0.5f,  0.5f,  0.5f,
  253.  
  254.          0.5f,  0.5f,  0.5f,
  255.          0.5f,  0.5f, -0.5f,
  256.          0.5f, -0.5f, -0.5f,
  257.          0.5f, -0.5f, -0.5f,
  258.          0.5f, -0.5f,  0.5f,
  259.          0.5f,  0.5f,  0.5f,
  260.  
  261.         -0.5f, -0.5f, -0.5f,
  262.          0.5f, -0.5f, -0.5f,
  263.          0.5f, -0.5f,  0.5f,
  264.          0.5f, -0.5f,  0.5f,
  265.         -0.5f, -0.5f,  0.5f,
  266.         -0.5f, -0.5f, -0.5f,
  267.  
  268.         -0.5f,  0.5f, -0.5f,
  269.          0.5f,  0.5f, -0.5f,
  270.          0.5f,  0.5f,  0.5f,
  271.          0.5f,  0.5f,  0.5f,
  272.         -0.5f,  0.5f,  0.5f,
  273.         -0.5f,  0.5f, -0.5f,
  274.     };*/
  275.     // world space positions of our cubes
  276.     /*glm::vec3 cubePositions[] = {
  277.         glm::vec3(0.0f,  0.0f,  0.0f),
  278.         glm::vec3(2.0f,  5.0f, -15.0f),
  279.         glm::vec3(-1.5f, -2.2f, -2.5f),
  280.         glm::vec3(-3.8f, -2.0f, -12.3f),
  281.         glm::vec3(2.4f, -0.4f, -3.5f),
  282.         glm::vec3(-1.7f,  3.0f, -7.5f),
  283.         glm::vec3(1.3f, -2.0f, -2.5f),
  284.         glm::vec3(1.5f,  2.0f, -2.5f),
  285.         glm::vec3(1.5f,  0.2f, -1.5f),
  286.         glm::vec3(-1.3f,  1.0f, -1.5f)
  287.     };*/
  288.     unsigned int VBO, VAO, EBO;
  289.     glGenVertexArrays(1, &VAO;);
  290.     glGenBuffers(1, &VBO;);
  291.     glGenBuffers(1, &EBO;);
  292.  
  293.     glBindVertexArray(VAO);
  294.  
  295.     glBindBuffer(GL_ARRAY_BUFFER, VBO);
  296.     glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), cube_vertices, GL_STATIC_DRAW);
  297.  
  298.     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
  299.     glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cube_indices), cube_indices, GL_STATIC_DRAW);
  300.  
  301.     // position attribute
  302.    // glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
  303.     //glEnableVertexAttribArray(0);
  304.  
  305.     // position attribute
  306.     glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
  307.     glEnableVertexAttribArray(0);
  308.  
  309.     //color attribute
  310.     glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)12);
  311.     glEnableVertexAttribArray(1);
  312.  
  313.  
  314.  
  315.     ////For Axis
  316.     //unsigned int axisVBO, axisVAO;
  317.     //glGenVertexArrays(1, &axisVAO;);
  318.     //glGenBuffers(1, &axisVBO;);
  319.     //glBindVertexArray(axisVAO);
  320.     //glBindBuffer(GL_ARRAY_BUFFER, axisVBO);
  321.     //glBufferData(GL_ARRAY_BUFFER, sizeof(axisVertices), axisVertices, GL_STATIC_DRAW);
  322.     //// position attribute
  323.     //glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
  324.     //glEnableVertexAttribArray(0);
  325.     //// color attribute
  326.     //glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));
  327.     //glEnableVertexAttribArray(1);
  328.  
  329.  
  330.     //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  331.  
  332.  
  333.  
  334.     //ourShader.use();
  335.  
  336.  
  337.     // render loop
  338.     // -----------
  339.     while (!glfwWindowShouldClose(window))
  340.     {
  341.         // per-frame time logic
  342.         // --------------------
  343.         float currentFrame = static_cast<float>(glfwGetTime());
  344.         deltaTime = currentFrame - lastFrame;
  345.         lastFrame = currentFrame;
  346.  
  347.         // input
  348.         // -----
  349.         processInput(window);
  350.  
  351.         // render
  352.         // ------
  353.         glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
  354.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  355.  
  356.  
  357.         // activate shader
  358.         ourShader.use();
  359.  
  360.         // pass projection matrix to shader (note that in this case it could change every frame)
  361.         glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
  362.         //glm::mat4 projection = glm::ortho(-2.0f, +2.0f, -1.5f, +1.5f, 0.1f, 100.0f);
  363.         ourShader.setMat4("projection", projection);
  364.  
  365.         // camera/view transformation
  366.         //glm::mat4 view = camera.GetViewMatrix();
  367.         glm::mat4 view = camera.GetViewMatrix();
  368.         ourShader.setMat4("view", view);
  369.  
  370.  
  371.  
  372.  
  373.         ////For axis
  374.         //ourShader.use();
  375.         //glm::mat4 identity = glm::mat4(1.0f); // identity matrix
  376.         //ourShader.setMat4("model", identity);
  377.         //glBindVertexArray(axisVAO);
  378.         //glDrawArrays(GL_LINES, 0, 6);
  379.  
  380.  
  381.         glBindVertexArray(VAO);
  382.  
  383.  
  384.         // Starting
  385.         glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  386.         glm::mat4 translateMatrix, scaleMatrix;
  387.         glm::vec4 color1;
  388.  
  389.         float chairZ = 0.4f;
  390.  
  391.         float fixY = 0.45f;
  392.  
  393.         float chairX = 0.1f;
  394.  
  395.  
  396.         // Middle column
  397.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f + fixY, 0.0f));
  398.         Table(ourShader, translateMatrix);
  399.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f + chairX, 0.0f + fixY, 1.0f - chairZ));
  400.         Chair(ourShader, translateMatrix);
  401.  
  402.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f + fixY, -1.35f));
  403.         Table(ourShader, translateMatrix);
  404.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f + chairX, 0.0f + fixY, -0.35f - chairZ));
  405.         Chair(ourShader, translateMatrix);
  406.  
  407.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f + fixY, -2.7f));
  408.         Table(ourShader, translateMatrix);
  409.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f + chairX, 0.0f + fixY, -1.7f - chairZ));
  410.         Chair(ourShader, translateMatrix);
  411.  
  412.         /*translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f + fixY, -4.05f));
  413.         Table(ourShader, translateMatrix);
  414.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f + fixY, -3.05f - chairZ));
  415.         Chair(ourShader, translateMatrix);*/
  416.  
  417.  
  418.  
  419.         //Right column
  420.         translateMatrix = glm::translate(identityMatrix, glm::vec3(1.5f, 0.0f + fixY, 0.0f));
  421.         Table(ourShader, translateMatrix);
  422.         translateMatrix = glm::translate(identityMatrix, glm::vec3(1.5f + chairX, 0.0f + fixY, 1.0f - chairZ));
  423.         Chair(ourShader, translateMatrix);
  424.  
  425.         translateMatrix = glm::translate(identityMatrix, glm::vec3(1.5f, 0.0f + fixY, -1.35f));
  426.         Table(ourShader, translateMatrix);
  427.         translateMatrix = glm::translate(identityMatrix, glm::vec3(1.5f + chairX, 0.0f + fixY, -0.35f - chairZ));
  428.         Chair(ourShader, translateMatrix);
  429.  
  430.         translateMatrix = glm::translate(identityMatrix, glm::vec3(1.5f, 0.0f + fixY, -2.7f));
  431.         Table(ourShader, translateMatrix);
  432.         translateMatrix = glm::translate(identityMatrix, glm::vec3(1.5f + chairX, 0.0f + fixY, -1.7f - chairZ));
  433.         Chair(ourShader, translateMatrix);
  434.  
  435.         /*translateMatrix = glm::translate(identityMatrix, glm::vec3(1.5f, 0.0f + fixY, -4.05f));
  436.         Table(ourShader, translateMatrix);
  437.         translateMatrix = glm::translate(identityMatrix, glm::vec3(1.5f - 0.1f, 0.0f + fixY, -3.05f - chairZ));
  438.         Chair(ourShader, translateMatrix);*/
  439.  
  440.  
  441.  
  442.         //Left column
  443.         translateMatrix = glm::translate(identityMatrix, glm::vec3(-1.5f, 0.0f + fixY, 0.0f));
  444.         Table(ourShader, translateMatrix);
  445.         translateMatrix = glm::translate(identityMatrix, glm::vec3(-1.5f, 0.0f + fixY, 1.0f - chairZ));
  446.         Chair(ourShader, translateMatrix);
  447.  
  448.         translateMatrix = glm::translate(identityMatrix, glm::vec3(-1.5f, 0.0f + fixY, -1.35f));
  449.         Table(ourShader, translateMatrix);
  450.         translateMatrix = glm::translate(identityMatrix, glm::vec3(-1.5f, 0.0f + fixY, -0.35f - chairZ));
  451.         Chair(ourShader, translateMatrix);
  452.  
  453.         translateMatrix = glm::translate(identityMatrix, glm::vec3(-1.5f, 0.0f + fixY, -2.7f));
  454.         Table(ourShader, translateMatrix);
  455.         translateMatrix = glm::translate(identityMatrix, glm::vec3(-1.5f, 0.0f + fixY, -1.7f - chairZ));
  456.         Chair(ourShader, translateMatrix);
  457.  
  458.         /*translateMatrix = glm::translate(identityMatrix, glm::vec3(-1.5f, 0.0f + fixY, -4.05f));
  459.         Table(ourShader, translateMatrix);
  460.         translateMatrix = glm::translate(identityMatrix, glm::vec3(-1.5f + 0.2f, 0.0f + fixY, -3.05f - chairZ));
  461.         Chair(ourShader, translateMatrix);*/
  462.  
  463.  
  464.  
  465.         //Walls
  466.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f, 0.0f));
  467.         SideWall(ourShader, translateMatrix);       //Left
  468.  
  469.         translateMatrix = glm::translate(identityMatrix, glm::vec3(4.5f, 0.0f, 0.0f));
  470.         SideWall(ourShader, translateMatrix);       //Right
  471.  
  472.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f, 0.0f));
  473.         FrontWall(ourShader, translateMatrix);       //Front
  474.  
  475.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f, 7.0f));
  476.         FrontWall(ourShader, translateMatrix);       //Back
  477.  
  478.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f, 2.0f));
  479.         color1 = glm::vec4(0.9f, 0.9f, 0.9f, 1.0f);
  480.         Roof(ourShader, translateMatrix, color1);       //Roof
  481.  
  482.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, -1.7f, 2.0f));
  483.         color1 = glm::vec4(0.38f, 0.3f, 0.3f, 1.0f);
  484.         Floor(ourShader, translateMatrix, color1);       //Floor
  485.  
  486.        
  487.  
  488.         //BlackBoard
  489.         translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f, 0.0f));
  490.         BlackBoard(ourShader, translateMatrix);
  491.  
  492.  
  493.         //Fan
  494.         Fan1(ourShader);
  495.  
  496.  
  497.         // render boxes
  498.         //for (unsigned int i = 0; i < 10; i++)
  499.         //{
  500.         //    // calculate the model matrix for each object and pass it to shader before drawing
  501.         //    glm::mat4 model = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  502.         //    model = glm::translate(model, cubePositions[i]);
  503.         //    float angle = 20.0f * i;
  504.         //    model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));
  505.         //    ourShader.setMat4("model", model);
  506.  
  507.         //    glDrawArrays(GL_TRIANGLES, 0, 36);
  508.         //}
  509.  
  510.         // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
  511.         // -------------------------------------------------------------------------------
  512.         glfwSwapBuffers(window);
  513.         glfwPollEvents();
  514.     }
  515.  
  516.     // optional: de-allocate all resources once they've outlived their purpose:
  517.     // ------------------------------------------------------------------------
  518.     glDeleteVertexArrays(1, &VAO;);
  519.     glDeleteBuffers(1, &VBO;);
  520.     glDeleteBuffers(1, &EBO;);
  521.  
  522.     // glfw: terminate, clearing all previously allocated GLFW resources.
  523.     // ------------------------------------------------------------------
  524.     glfwTerminate();
  525.     return 0;
  526. }
  527.  
  528. // process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
  529. // ---------------------------------------------------------------------------------------------------------
  530. void processInput(GLFWwindow* window)
  531. {
  532.     if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
  533.         glfwSetWindowShouldClose(window, true);
  534.  
  535.     if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {                 //Forward
  536.         camera.ProcessKeyboard(FORWARD, deltaTime);
  537.     }
  538.     if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {                 //Backward
  539.         camera.ProcessKeyboard(BACKWARD, deltaTime);
  540.     }
  541.     if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {                 //Left
  542.         camera.ProcessKeyboard(LEFT, deltaTime);
  543.     }
  544.     if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {                 //Right
  545.         camera.ProcessKeyboard(RIGHT, deltaTime);
  546.     }
  547.  
  548.     if (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS)                   //Down
  549.     {
  550.         /*if (rotateAxis_X) rotateAngle_X -= 0.1;
  551.         else if (rotateAxis_Y) rotateAngle_Y -= 0.1;
  552.         else rotateAngle_Z -= 0.1;*/
  553.  
  554.         camera.ProcessKeyboard(DOWN, deltaTime);
  555.  
  556.  
  557.     }
  558.  
  559.     if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS)                   //Pitch positive
  560.     {
  561.         /*rotateAngle_X += 1;
  562.         rotateAxis_X = 1.0;
  563.         rotateAxis_Y = 0.0;
  564.         rotateAxis_Z = 0.0;*/
  565.         camera.ProcessYPR(0.0f, 3.0f, 0.0f);
  566.     }
  567.     if (glfwGetKey(window, GLFW_KEY_C) == GLFW_PRESS)                   //Pitch negative
  568.     {
  569.         /*rotateAngle_X += 1;
  570.         rotateAxis_X = 1.0;
  571.         rotateAxis_Y = 0.0;
  572.         rotateAxis_Z = 0.0;*/
  573.         camera.ProcessYPR(0.0f, -3.0f, 0.0f);
  574.     }
  575.  
  576.     if (glfwGetKey(window, GLFW_KEY_Y) == GLFW_PRESS)                   //Yaw positive
  577.     {
  578.         /*rotateAngle_Y += 1;
  579.         rotateAxis_X = 0.0;
  580.         rotateAxis_Y = 1.0;
  581.         rotateAxis_Z = 0.0;*/
  582.         camera.ProcessYPR(3.0f, 0.0f, 0.0f);
  583.     }
  584.     if (glfwGetKey(window, GLFW_KEY_U) == GLFW_PRESS)                   //Yaw negative
  585.     {
  586.         /*rotateAngle_Y += 1;
  587.         rotateAxis_X = 0.0;
  588.         rotateAxis_Y = 1.0;
  589.         rotateAxis_Z = 0.0;*/
  590.         camera.ProcessYPR(-3.0f, 0.0f, 0.0f);
  591.     }
  592.  
  593.     if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)                   //Roll positive
  594.     {
  595.         /*rotateAngle_Z += 0.1;
  596.         rotateAxis_X = 0.0;
  597.         rotateAxis_Y = 0.0;
  598.         rotateAxis_Z = 1.0;*/
  599.         camera.ProcessYPR(0.0f, 0.0f, 0.5f);
  600.  
  601.     }
  602.     if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)                   //Roll negative
  603.     {
  604.         /*rotateAngle_Z += 0.1;
  605.         rotateAxis_X = 0.0;
  606.         rotateAxis_Y = 0.0;
  607.         rotateAxis_Z = 1.0;*/
  608.         camera.ProcessYPR(0.0f, 0.0f, -0.5f);
  609.  
  610.     }
  611.  
  612.     if (glfwGetKey(window, GLFW_KEY_H) == GLFW_PRESS)
  613.     {
  614.         eyeX += 2.5 * deltaTime;
  615.         basic_camera.changeEye(eyeX, eyeY, eyeZ);
  616.     }
  617.     if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS)                   //Rotate camera around a look at point
  618.     {
  619.         /*eyeX -= 2.5 * deltaTime;
  620.         basic_camera.changeEye(eyeX, eyeY, eyeZ);*/
  621.  
  622.  
  623.     }
  624.     if (glfwGetKey(window, GLFW_KEY_T) == GLFW_PRESS)
  625.     {
  626.         eyeZ += 2.5 * deltaTime;
  627.         basic_camera.changeEye(eyeX, eyeY, eyeZ);
  628.     }
  629.     if (glfwGetKey(window, GLFW_KEY_G) == GLFW_PRESS)                   //Rotate Fan
  630.     {
  631.         /*eyeZ -= 2.5 * deltaTime;
  632.         basic_camera.changeEye(eyeX, eyeY, eyeZ);*/
  633.         isRotate ^= true;
  634.         cout << isRotate << endl;
  635.         Sleep(100);
  636.  
  637.     }
  638.     if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
  639.     {
  640.         eyeY += 2.5 * deltaTime;
  641.         basic_camera.changeEye(eyeX, eyeY, eyeZ);
  642.     }
  643.     if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)                   //Up
  644.     {
  645.         /*eyeY -= 2.5 * deltaTime;
  646.         basic_camera.changeEye(eyeX, eyeY, eyeZ);*/
  647.         camera.ProcessKeyboard(UP, deltaTime);
  648.  
  649.     }
  650.     if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
  651.     {
  652.         lookAtX += 2.5 * deltaTime;
  653.         basic_camera.changeLookAt(lookAtX, lookAtY, lookAtZ);
  654.     }
  655.     if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS)
  656.     {
  657.         lookAtX -= 2.5 * deltaTime;
  658.         basic_camera.changeLookAt(lookAtX, lookAtY, lookAtZ);
  659.     }
  660.     if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS)
  661.     {
  662.         lookAtY += 2.5 * deltaTime;
  663.         basic_camera.changeLookAt(lookAtX, lookAtY, lookAtZ);
  664.     }
  665.     if (glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS)
  666.     {
  667.         lookAtY -= 2.5 * deltaTime;
  668.         basic_camera.changeLookAt(lookAtX, lookAtY, lookAtZ);
  669.     }
  670.     if (glfwGetKey(window, GLFW_KEY_5) == GLFW_PRESS)
  671.     {
  672.         lookAtZ += 2.5 * deltaTime;
  673.         basic_camera.changeLookAt(lookAtX, lookAtY, lookAtZ);
  674.     }
  675.     if (glfwGetKey(window, GLFW_KEY_6) == GLFW_PRESS)
  676.     {
  677.         lookAtZ -= 2.5 * deltaTime;
  678.         basic_camera.changeLookAt(lookAtX, lookAtY, lookAtZ);
  679.     }
  680.     if (glfwGetKey(window, GLFW_KEY_7) == GLFW_PRESS)
  681.     {
  682.         basic_camera.changeViewUpVector(glm::vec3(1.0f, 0.0f, 0.0f));
  683.     }
  684.     if (glfwGetKey(window, GLFW_KEY_8) == GLFW_PRESS)
  685.     {
  686.         basic_camera.changeViewUpVector(glm::vec3(0.0f, 1.0f, 0.0f));
  687.     }
  688.     if (glfwGetKey(window, GLFW_KEY_9) == GLFW_PRESS)
  689.     {
  690.         basic_camera.changeViewUpVector(glm::vec3(0.0f, 0.0f, 1.0f));
  691.     }
  692.  
  693. }
  694.  
  695. // glfw: whenever the window size changed (by OS or user resize) this callback function executes
  696. // ---------------------------------------------------------------------------------------------
  697. void framebuffer_size_callback(GLFWwindow* window, int width, int height)
  698. {
  699.     // make sure the viewport matches the new window dimensions; note that width and
  700.     // height will be significantly larger than specified on retina displays.
  701.     glViewport(0, 0, width, height);
  702. }
  703.  
  704.  
  705. // glfw: whenever the mouse moves, this callback is called
  706. // -------------------------------------------------------
  707. void mouse_callback(GLFWwindow* window, double xposIn, double yposIn)
  708. {
  709.     float xpos = static_cast<float>(xposIn);
  710.     float ypos = static_cast<float>(yposIn);
  711.  
  712.     if (firstMouse)
  713.     {
  714.         lastX = xpos;
  715.         lastY = ypos;
  716.         firstMouse = false;
  717.     }
  718.  
  719.     float xoffset = xpos - lastX;
  720.     float yoffset = lastY - ypos; // reversed since y-coordinates go from bottom to top
  721.  
  722.     lastX = xpos;
  723.     lastY = ypos;
  724.  
  725.     camera.ProcessMouseMovement(xoffset, yoffset);
  726. }
  727.  
  728. // glfw: whenever the mouse scroll wheel scrolls, this callback is called
  729. // ----------------------------------------------------------------------
  730. void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
  731. {
  732.     camera.ProcessMouseScroll(static_cast<float>(yoffset));
  733. }
  734.  
  735. void Table(Shader ourShader, glm::mat4 moveMatrix)
  736. {
  737.  
  738.     float tableY = 0.5f;
  739.     // Top
  740.     glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  741.     glm::mat4 translateMatrix, scaleMatrix, model;
  742.  
  743.     translateMatrix = glm::translate(identityMatrix, glm::vec3(0.0f, 0.0f, 0.0f));
  744.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(1.5f, 0.1f, 1.0f));
  745.     model = translateMatrix * scaleMatrix;
  746.     ourShader.setMat4("model", moveMatrix*model);
  747.     ourShader.setVec4("color", glm::vec4(0.5f, 1.0f, 1.0f, 1.0f));
  748.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  749.  
  750.  
  751.     // Leg 1
  752.     glm::mat4 identityMatrix1 = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  753.     glm::mat4 translateMatrix1, scaleMatrix1, model1;
  754.     translateMatrix1 = glm::translate(identityMatrix1, glm::vec3(0.02f, -0.46f, 0.01f));
  755.     scaleMatrix1 = glm::scale(identityMatrix1, glm::vec3(0.1f, 1.0f, 0.1f));
  756.     model1 = translateMatrix1 * scaleMatrix1;
  757.     ourShader.setMat4("model", moveMatrix * model1);
  758.     ourShader.setVec4("color", glm::vec4(1.5f, 0.0f, 0.0f, 1.0f));
  759.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  760.  
  761.  
  762.     // Leg 2
  763.     glm::mat4 identityMatrix2 = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  764.     glm::mat4 translateMatrix2, scaleMatrix2, model2;
  765.     translateMatrix2 = glm::translate(identityMatrix2, glm::vec3(0.02f, -0.46f, 0.43f));
  766.     scaleMatrix2 = glm::scale(identityMatrix2, glm::vec3(0.1f, 1.0f, 0.1f));
  767.     model2 = translateMatrix2 * scaleMatrix2;
  768.     ourShader.setMat4("model", moveMatrix * model2);
  769.     ourShader.setVec4("color", glm::vec4(1.5f, 0.0f, 0.0f, 1.0f));
  770.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  771.  
  772.  
  773.     // Leg 3
  774.     //glm::mat4 translateMatrix1, rotateXMatrix1, rotateYMatrix1, rotateZMatrix1, scaleMatrix1, model1;
  775.     translateMatrix1 = glm::translate(identityMatrix1, glm::vec3(0.69f, -0.46f, 0.01f));
  776.     scaleMatrix1 = glm::scale(identityMatrix1, glm::vec3(0.1f, 1.0f, 0.1f));
  777.     model1 = translateMatrix1 * scaleMatrix1;
  778.     ourShader.setMat4("model", moveMatrix * model1);
  779.     ourShader.setVec4("color", glm::vec4(1.5f, 0.0f, 0.0f, 1.0f));
  780.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  781.  
  782.  
  783.     // Leg 4
  784.     //glm::mat4 translateMatrix2, rotateXMatrix2, rotateYMatrix2, rotateZMatrix2, scaleMatrix2, model2;
  785.     translateMatrix2 = glm::translate(identityMatrix2, glm::vec3(0.69f, -0.46f, 0.43f));
  786.     scaleMatrix2 = glm::scale(identityMatrix2, glm::vec3(0.1f, 1.0f, 0.1f));
  787.     model2 = translateMatrix2 * scaleMatrix2;
  788.     ourShader.setMat4("model", moveMatrix * model2);
  789.     ourShader.setVec4("color", glm::vec4(1.5f, 0.0f, 0.0f, 1.0f));
  790.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  791. }
  792.  
  793. void Chair(Shader ourShader, glm::mat4 moveMatrix)
  794. {
  795.     glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  796.     glm::mat4 translateMatrix, scaleMatrix, model;
  797.  
  798.     float fixLeg = 0.7f;
  799.     float fixY = 0.1f;
  800.  
  801.     // Top
  802.     translateMatrix = glm::translate(identityMatrix, glm::vec3(0.11f, 0.0f - fixY, 0.0f));
  803.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.75f, 0.07f, 0.7f));
  804.     model = translateMatrix * scaleMatrix;
  805.     ourShader.setMat4("model", moveMatrix * model);
  806.     ourShader.setVec4("color", glm::vec4(0.9f, 0.3f, 0.0f, 1.0f));
  807.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  808.  
  809.     // Leg 1
  810.     glm::mat4 identityMatrix1 = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  811.     glm::mat4 translateMatrix1, scaleMatrix1, model1;
  812.     translateMatrix1 = glm::translate(identityMatrix1, glm::vec3(0.13f, -0.32f, 0.01f));
  813.     scaleMatrix1 = glm::scale(identityMatrix1, glm::vec3(0.07f, 0.7f * fixLeg, 0.07f));
  814.     model1 = translateMatrix1 * scaleMatrix1;
  815.     ourShader.setMat4("model", moveMatrix * model1);
  816.     ourShader.setVec4("color", glm::vec4(0.9f, 0.9f, 1.0f, 1.0f));
  817.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  818.  
  819.  
  820.     // Leg 2
  821.     glm::mat4 identityMatrix2 = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  822.     glm::mat4 translateMatrix2, scaleMatrix2, model2;
  823.     translateMatrix2 = glm::translate(identityMatrix2, glm::vec3(0.13f, -0.32f, 0.28f));
  824.     scaleMatrix2 = glm::scale(identityMatrix2, glm::vec3(0.07f, 0.7f * fixLeg, 0.07f));
  825.     model2 = translateMatrix2 * scaleMatrix2;
  826.     ourShader.setMat4("model", moveMatrix * model2);
  827.     ourShader.setVec4("color", glm::vec4(0.9f, 0.9f, 1.0f, 1.0f));
  828.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  829.  
  830.  
  831.     //// Leg 3
  832.     //glm::mat4 translateMatrix1, rotateXMatrix1, rotateYMatrix1, rotateZMatrix1, scaleMatrix1, model1;
  833.     translateMatrix1 = glm::translate(identityMatrix1, glm::vec3(0.43f, -0.32f, 0.01f));
  834.     scaleMatrix1 = glm::scale(identityMatrix1, glm::vec3(0.07f, 0.7f * fixLeg, 0.07f));
  835.     model1 = translateMatrix1 * scaleMatrix1;
  836.     ourShader.setMat4("model", moveMatrix * model1);
  837.     ourShader.setVec4("color", glm::vec4(0.9f, 0.9f, 1.0f, 1.0f));
  838.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  839.  
  840.  
  841.     // Leg 4
  842.     //glm::mat4 translateMatrix2, rotateXMatrix2, rotateYMatrix2, rotateZMatrix2, scaleMatrix2, model2;
  843.     translateMatrix2 = glm::translate(identityMatrix2, glm::vec3(0.43f, -0.32f, 0.28f));
  844.     scaleMatrix2 = glm::scale(identityMatrix2, glm::vec3(0.07f, 0.7f * fixLeg, 0.07f));
  845.     model2 = translateMatrix2 * scaleMatrix2;
  846.     ourShader.setMat4("model", moveMatrix * model2);
  847.     ourShader.setVec4("color", glm::vec4(0.9f, 0.9f, 1.0f, 1.0f));
  848.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  849.  
  850.  
  851.     //Left up
  852.     translateMatrix2 = glm::translate(identityMatrix2, glm::vec3(0.17f, 0.0f - fixY, 0.29f));
  853.     scaleMatrix2 = glm::scale(identityMatrix2, glm::vec3(0.07f, 0.25f, 0.07f));
  854.     model2 = translateMatrix2 * scaleMatrix2;
  855.     ourShader.setMat4("model", moveMatrix * model2);
  856.     ourShader.setVec4("color", glm::vec4(0.9f, 0.9f, 1.0f, 1.0f));
  857.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  858.  
  859.  
  860.     //Right up
  861.     translateMatrix2 = glm::translate(identityMatrix2, glm::vec3(0.39f, 0.0f - fixY, 0.29f));
  862.     scaleMatrix2 = glm::scale(identityMatrix2, glm::vec3(0.07f, 0.25f, 0.07f));
  863.     model2 = translateMatrix2 * scaleMatrix2;
  864.     ourShader.setMat4("model", moveMatrix * model2);
  865.     ourShader.setVec4("color", glm::vec4(0.9f, 0.9f, 1.0f, 1.0f));
  866.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  867.  
  868.     //Back support
  869.     translateMatrix = glm::translate(identityMatrix, glm::vec3(0.15f, 0.09f - fixY, 0.28f));
  870.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.6f, 0.5f, 0.1f));
  871.     model = translateMatrix * scaleMatrix;
  872.     ourShader.setMat4("model", moveMatrix * model);
  873.     ourShader.setVec4("color", glm::vec4(0.9f, 0.3f, 1.0f, 1.0f));
  874.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  875. }
  876.  
  877. void SideWall(Shader ourShader, glm::mat4 moveMatrix)
  878. {
  879.     glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  880.     glm::mat4 translateMatrix, scaleMatrix, model;
  881.  
  882.     translateMatrix = glm::translate(identityMatrix, glm::vec3(-2.0f, 0.0f, -4.0f));
  883.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.1f, 2.5f * 1.6f, 14.0f));
  884.     model = translateMatrix * scaleMatrix;
  885.     ourShader.setMat4("model", moveMatrix * model);
  886.     ourShader.setVec4("color", glm::vec4(0.97f, 0.65f, 0.53f, 1.0f));
  887.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  888. }
  889.  
  890. void FrontWall(Shader ourShader, glm::mat4 moveMatrix)
  891. {
  892.     glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  893.     glm::mat4 translateMatrix, scaleMatrix, model;
  894.  
  895.     translateMatrix = glm::translate(identityMatrix, glm::vec3(-2.0f, 0.0f, -4.0f));
  896.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(9.3f, 2.5f * 1.6f, 0.1f));
  897.     model = translateMatrix * scaleMatrix;
  898.     ourShader.setMat4("model", moveMatrix * model);
  899.     ourShader.setVec4("color", glm::vec4(0.8f, 0.9f, 0.7f, 1.0f));
  900.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  901. }
  902.  
  903. void Roof(Shader ourShader, glm::mat4 moveMatrix, glm::vec4 color)
  904. {
  905.     glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  906.     glm::mat4 translateMatrix, scaleMatrix, model;
  907.  
  908.     translateMatrix = glm::translate(identityMatrix, glm::vec3(-2.0f, 2.0f, -6.0f));
  909.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(9.3f, 0.1f, 14.0f));
  910.     model = translateMatrix * scaleMatrix;
  911.     ourShader.setMat4("model", moveMatrix * model);
  912.     ourShader.setVec4("color", color);
  913.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  914. }
  915.  
  916. void Floor (Shader ourShader, glm::mat4 moveMatrix, glm::vec4 color)
  917. {
  918.     glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  919.     glm::mat4 translateMatrix, scaleMatrix, model;
  920.  
  921.     translateMatrix = glm::translate(identityMatrix, glm::vec3(-2.0f, 1.25f + 0.45f, -6.0f));
  922.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(9.3f, 0.1f, 14.0f));
  923.     model = translateMatrix * scaleMatrix;
  924.     ourShader.setMat4("model", moveMatrix * model);
  925.     ourShader.setVec4("color", color);
  926.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  927. }
  928.  
  929. void BlackBoard(Shader ourShader, glm::mat4 moveMatrix)
  930. {
  931.     glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  932.     glm::mat4 translateMatrix, scaleMatrix, model;
  933.  
  934.     float fixY = 0.4f;
  935.  
  936.     translateMatrix = glm::translate(identityMatrix, glm::vec3(-1.3f, 0.2f + fixY, -3.99f));        //Frame
  937.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(6.3f, 1.5f, 0.1f));
  938.     model = translateMatrix * scaleMatrix;
  939.     ourShader.setMat4("model", moveMatrix * model);
  940.     ourShader.setVec4("color", glm::vec4(0.4f, 0.16f, 0.0f, 1.0f));
  941.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  942.  
  943.     translateMatrix = glm::translate(identityMatrix, glm::vec3(-1.23f, 0.26f + fixY, -3.98f));        //Board
  944.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(6.0f, 1.3f, 0.1f));
  945.     model = translateMatrix * scaleMatrix;
  946.     ourShader.setMat4("model", moveMatrix * model);
  947.     ourShader.setVec4("color", glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
  948.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  949. }
  950.  
  951. void Fan1(Shader ourShader)
  952. {
  953.     glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  954.     glm::mat4 translateToPivot, translateFromPivot, rotateYMatrix, scaleMatrix, model, moveModel;
  955.  
  956.     //Handle
  957.     moveModel = glm::translate(identityMatrix, glm::vec3(0.0f, 1.77f, 0.0f));
  958.     //rotateYMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_Y), glm::vec3(0.0f, 1.0f, 0.0f));
  959.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.1f, 0.5f, 0.1f));
  960.     model = moveModel * scaleMatrix;
  961.     ourShader.setMat4("model",  model);
  962.     ourShader.setVec4("color", glm::vec4(0.2f, 0.2f, 0.2f, 1.0f));
  963.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  964.  
  965.     if (isRotate)
  966.     {
  967.         rotateAngle_Y += fanSpeed;
  968.         rotateAngle_Y = fmod(rotateAngle_Y, 360);
  969.     }
  970.    
  971.  
  972.  
  973.     //Center
  974.     translateToPivot = glm::translate(identityMatrix, glm::vec3(-0.125f, -0.075f, -0.125f));
  975.     translateFromPivot = glm::translate(identityMatrix, glm::vec3(0.125f, 0.075f, 0.125f));
  976.     moveModel = glm::translate(identityMatrix, glm::vec3(-0.1f, 1.65f, -0.1f));
  977.     rotateYMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_Y), glm::vec3(0.0f, 1.0f, 0.0f));
  978.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.5f, 0.3f, 0.5f));
  979.     model = moveModel * translateFromPivot * rotateYMatrix * translateToPivot * scaleMatrix;
  980.     //model = moveModel * rotateYMatrix * scaleMatrix;
  981.     //model =  translateFromPivot * rotateYMatrix * translateToPivot;
  982.     ourShader.setMat4("model", model);
  983.     ourShader.setVec4("color", glm::vec4(0.2f, 1.0f, 0.2f, 1.0f));
  984.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  985.  
  986.     //One hand
  987.     translateToPivot = glm::translate(identityMatrix, glm::vec3(-0.7f, -0.025f, -0.075f));
  988.     translateFromPivot = glm::translate(identityMatrix, glm::vec3(0.7f, 0.025f, 0.075f));
  989.     moveModel = glm::translate(identityMatrix, glm::vec3(-0.65f, 1.67f, -0.05f));
  990.     rotateYMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_Y), glm::vec3(0.0f, 1.0f, 0.0f));
  991.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(2.8f, 0.1f, 0.3f));
  992.     model = moveModel * translateFromPivot * rotateYMatrix * translateToPivot * scaleMatrix;
  993.     ourShader.setMat4("model", model);
  994.     ourShader.setVec4("color", glm::vec4(0.2f, 0.2f, 1.0f, 1.0f));
  995.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  996.  
  997.     //Second hand
  998.     translateToPivot = glm::translate(identityMatrix, glm::vec3(-0.075f, -0.025f, -0.7f));
  999.     translateFromPivot = glm::translate(identityMatrix, glm::vec3(0.075f, 0.025f, 0.7f));
  1000.     moveModel = glm::translate(identityMatrix, glm::vec3(-0.05f, 1.67f, -0.65f));
  1001.     rotateYMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_Y), glm::vec3(0.0f, 1.0f, 0.0f));
  1002.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.3f, 0.1f, 2.8f));
  1003.     model = moveModel * translateFromPivot * rotateYMatrix * translateToPivot * scaleMatrix;
  1004.     ourShader.setMat4("model", model);
  1005.     ourShader.setVec4("color", glm::vec4(0.2f, 0.2f, 1.0f, 1.0f));
  1006.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  1007.  
  1008. }
  1009.  
  1010. void Fan2(Shader ourShader)
  1011. {
  1012.     glm::mat4 identityMatrix = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
  1013.     glm::mat4 translateToPivot, translateFromPivot, rotateYMatrix, scaleMatrix, model, moveModel;
  1014.  
  1015.     //Handle
  1016.     moveModel = glm::translate(identityMatrix, glm::vec3(0.0f, 1.77f, 0.0f));
  1017.     //rotateYMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_Y), glm::vec3(0.0f, 1.0f, 0.0f));
  1018.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.1f, 0.5f, 0.1f));
  1019.     model = moveModel * scaleMatrix;
  1020.     ourShader.setMat4("model", model);
  1021.     ourShader.setVec4("color", glm::vec4(0.2f, 0.2f, 0.2f, 1.0f));
  1022.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  1023.  
  1024.     if (isRotate)
  1025.     {
  1026.         rotateAngle_Y += 2.7f;
  1027.         rotateAngle_Y = fmod(rotateAngle_Y, 360);
  1028.     }
  1029.  
  1030.  
  1031.     translateToPivot = glm::translate(identityMatrix, glm::vec3(-0.25f, -0.25f, -0.25f));
  1032.     translateFromPivot = glm::translate(identityMatrix, glm::vec3(0.25f, 0.25f, 0.25f));
  1033.  
  1034.     //Another way
  1035.  
  1036.     float fixX = 0.0;
  1037.     float fixZ = 0.0f;
  1038.  
  1039.     //Center
  1040.     moveModel = glm::translate(identityMatrix, glm::vec3(-0.1f, 1.65f, -0.1f));
  1041.     rotateYMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_Y), glm::vec3(0.0f, 1.0f, 0.0f));
  1042.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.5f, 0.3f, 0.5f));
  1043.     model = moveModel * scaleMatrix * translateFromPivot * rotateYMatrix * translateToPivot;
  1044.     ourShader.setMat4("model", model);
  1045.     ourShader.setVec4("color", glm::vec4(0.2f, 1.0f, 0.2f, 1.0f));
  1046.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  1047.  
  1048.     //hand 1
  1049.     moveModel = glm::translate(identityMatrix, glm::vec3(0.0f + fixX, 1.67f, -0.05f + fixZ));
  1050.     rotateYMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_Y), glm::vec3(0.0f, 1.0f, 0.0f));
  1051.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(-1.5f, 0.1f, 0.3f));
  1052.     model = moveModel * rotateYMatrix * scaleMatrix;
  1053.     ourShader.setMat4("model", model);
  1054.     ourShader.setVec4("color", glm::vec4(0.2f, 0.2f, 1.0f, 1.0f));
  1055.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  1056.  
  1057.     //hand 2
  1058.     moveModel = glm::translate(identityMatrix, glm::vec3(0.0f + fixX, 1.67f, -0.05f + fixZ));
  1059.     rotateYMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_Y), glm::vec3(0.0f, 1.0f, 0.0f));
  1060.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(1.5f, 0.1f, 0.3f));
  1061.     model = moveModel * rotateYMatrix * scaleMatrix;
  1062.     ourShader.setMat4("model", model);
  1063.     ourShader.setVec4("color", glm::vec4(0.2f, 0.2f, 1.0f, 1.0f));
  1064.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  1065.  
  1066.     //hand 3
  1067.     moveModel = glm::translate(identityMatrix, glm::vec3(-0.05f + fixX, 1.67f, 0.0f + fixZ));
  1068.     rotateYMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_Y), glm::vec3(0.0f, 1.0f, 0.0f));
  1069.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.3f, 0.1f, -1.5f));
  1070.     model = moveModel * rotateYMatrix * scaleMatrix;
  1071.     ourShader.setMat4("model", model);
  1072.     ourShader.setVec4("color", glm::vec4(0.2f, 0.2f, 1.0f, 1.0f));
  1073.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  1074.  
  1075.     //hand 4
  1076.     moveModel = glm::translate(identityMatrix, glm::vec3(-0.05f + fixX, 1.67f, 0.0f + fixZ));
  1077.     rotateYMatrix = glm::rotate(identityMatrix, glm::radians(rotateAngle_Y), glm::vec3(0.0f, 1.0f, 0.0f));
  1078.     scaleMatrix = glm::scale(identityMatrix, glm::vec3(0.3f, 0.1f, 1.5f));
  1079.     model = moveModel * rotateYMatrix * scaleMatrix;
  1080.     ourShader.setMat4("model", model);
  1081.     ourShader.setVec4("color", glm::vec4(0.2f, 0.2f, 1.0f, 1.0f));
  1082.     glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
  1083. }