• Transformations_练习二


    尝试再次调用glDrawElements画出第二个箱子,使用变换将其摆放在不同的位置。让这个箱子被摆放在窗口的左上角,并且会不断的缩放(而不是旋转)。(sin函数在这里会很有用,不过注意使用sin函数时应用负值会导致物体被翻转)

    画图代码:

     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);
    View Code

    2019/11/28

  • 相关阅读:
    navicat的快捷键
    NoSQL Redis的学习笔记
    awk的使用
    把自己的电脑做服务器发布tomcat的项目外网访问
    linux系统备份
    系统自动化配置和管理工具:SaltStack
    RSync实现文件备份同步
    传送文件
    面试题
    闭包closure
  • 原文地址:https://www.cnblogs.com/ljy08163268/p/11951030.html
Copyright © 2020-2023  润新知