GlDrawElements try to call again draw the second case, only use transformation to be placed in a different location. Let the box was placed in the upper left corner of the window, and will continue zooming (instead of rotating). ( sin
Function can be useful here, but note that the use of sin
application functions can lead to a negative value when the object is flipped)
Paint Code:
1 //the first one 2 // create transformations 3 glm::mat4 transform = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first 4 transform = glm::translate(transform, glm::vec3(0.5f, -0.5f, 0.0f)); 5 transform = glm::rotate(transform, (float)glfwGetTime(), glm::vec3(0.0f, 0.0f, 1.0f)); 6 7 // get matrix's uniform location and set matrix 8 ourShader.use(); 9 unsigned int transformLoc = glGetUniformLocation(ourShader.ID, "transform"); 10 glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(transform)); 11 12 // render container 13 glBindVertexArray(VAO); 14 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); 15 16 //the second one 17 // create transformations 18 transform = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first 19 transform = glm::translate(transform, glm::vec3(-0.5f, 0.5f, 0.0f)); 20 float scaleAmount = sin((float)glfwGetTime()); 21 if (scaleAmount < 0) 22 transform = glm::scale(transform, glm::vec3(-scaleAmount, -scaleAmount, -scaleAmount)); 23 else 24 transform = glm::scale(transform, glm::vec3(scaleAmount, scaleAmount, scaleAmount)); 25 26 // get matrix's uniform location and set matrix 27 ourShader.use(); 28 glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(transform)); 29 30 // render container 31 glBindVertexArray(VAO); 32 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
2019/11/28