<bdo id='BS1NT'></bdo><ul id='BS1NT'></ul>

<small id='BS1NT'></small><noframes id='BS1NT'>

  • <tfoot id='BS1NT'></tfoot>
    <i id='BS1NT'><tr id='BS1NT'><dt id='BS1NT'><q id='BS1NT'><span id='BS1NT'><b id='BS1NT'><form id='BS1NT'><ins id='BS1NT'></ins><ul id='BS1NT'></ul><sub id='BS1NT'></sub></form><legend id='BS1NT'></legend><bdo id='BS1NT'><pre id='BS1NT'><center id='BS1NT'></center></pre></bdo></b><th id='BS1NT'></th></span></q></dt></tr></i><div id='BS1NT'><tfoot id='BS1NT'></tfoot><dl id='BS1NT'><fieldset id='BS1NT'></fieldset></dl></div>
  • <legend id='BS1NT'><style id='BS1NT'><dir id='BS1NT'><q id='BS1NT'></q></dir></style></legend>

        OpenGL 中的 glm 旋转用法

        时间:2023-09-17

          • <legend id='6Xk96'><style id='6Xk96'><dir id='6Xk96'><q id='6Xk96'></q></dir></style></legend>

            1. <small id='6Xk96'></small><noframes id='6Xk96'>

                <bdo id='6Xk96'></bdo><ul id='6Xk96'></ul>
                  <tbody id='6Xk96'></tbody>
                <i id='6Xk96'><tr id='6Xk96'><dt id='6Xk96'><q id='6Xk96'><span id='6Xk96'><b id='6Xk96'><form id='6Xk96'><ins id='6Xk96'></ins><ul id='6Xk96'></ul><sub id='6Xk96'></sub></form><legend id='6Xk96'></legend><bdo id='6Xk96'><pre id='6Xk96'><center id='6Xk96'></center></pre></bdo></b><th id='6Xk96'></th></span></q></dt></tr></i><div id='6Xk96'><tfoot id='6Xk96'></tfoot><dl id='6Xk96'><fieldset id='6Xk96'></fieldset></dl></div>
                  <tfoot id='6Xk96'></tfoot>
                1. 本文介绍了OpenGL 中的 glm 旋转用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在渲染一个圆锥体,我想将它逆时针旋转 90 度,使尖端朝西!我使用的是 OpenGL 3+.

                  到目前为止,这是我在 Cone.cpp 中的代码:

                  //投影glm::mat4 投影 = glm::perspective(45.0f, 1.0f, 0.1f, 100.0f);//看法glm::mat4 视图 = glm::mat4(1.);View = glm::translate(View, glm::vec3(2.0f,4.0f, -25.0f));//模型glm::mat4 模型 = glm::mat4(1.0);//按因子 0.5 缩放模型 = glm::scale(glm::mat4(1.0f),glm::vec3(0.5f));glm::mat4 MVP = 投影 * 视图 * 模型;glUniformMatrix4fv(glGetUniformLocation(shaderprogram_spaceship, "MVP_matrix"), 1, GL_FALSE, glm::value_ptr(MVP));glClearColor(0.0, 0.0, 0.0, 1.0);glDrawArrays(GL_LINE_STRIP, start_cone, end_cone );

                  未显示所有代码.

                  有人可以指导我完成轮换吗?我必须乘以视图矩阵吗?带有glm 旋转"功能?

                  解决方案

                  您需要乘以您的模型矩阵.因为那是模型位置、缩放和旋转的位置(这就是为什么它被称为模型矩阵).

                  您需要做的就是(参见此处)

                  Model = glm::rotate(Model, angle_in_radians, glm::vec3(x, y, z));//其中 x, y, z 是旋转轴(例如 0 1 0)

                  <块引用>

                  注意要从度数转换为弧度,使用 glm::radians(degrees)

                  这需要模型矩阵并在其中已有的所有操作之上应用旋转.其他函数 translate 和 scale 做同样的事情.这样就可以在一个矩阵中组合许多变换.

                  注意:早期版本接受以度为单位的角度.这已被弃用,因为 0.9.6

                  Model = glm::rotate(Model, angle_in_degrees, glm::vec3(x, y, z));//其中 x, y, z 是旋转轴(例如 0 1 0)

                  I am rendering a cone, and I would like to rotate it, 90 degrees anti-clockwise, so that the pointy end faces west! I am using OpenGL 3+.

                  Here is my code in my Cone.cpp so far:

                  //PROJECTION
                      glm::mat4 Projection = glm::perspective(45.0f, 1.0f, 0.1f, 100.0f);
                  
                      //VIEW
                      glm::mat4 View = glm::mat4(1.);
                      View = glm::translate(View, glm::vec3(2.0f,4.0f, -25.0f));
                  
                      //MODEL
                      glm::mat4 Model = glm::mat4(1.0);
                      //Scale by factor 0.5
                      Model = glm::scale(glm::mat4(1.0f),glm::vec3(0.5f));
                  
                      glm::mat4 MVP = Projection * View * Model;
                      glUniformMatrix4fv(glGetUniformLocation(shaderprogram_spaceship, "MVP_matrix"), 1, GL_FALSE, glm::value_ptr(MVP));
                  
                      glClearColor(0.0, 0.0, 0.0, 1.0);
                  
                      glDrawArrays(GL_LINE_STRIP, start_cone, end_cone );
                  

                  Not all of the code is shown.

                  Can somebody guide me through the rotation? I do have to multiply the View matrix right ? with "glm rotate" function ?

                  解决方案

                  You need to multiply your Model matrix. Because that is where model position, scaling and rotation should be (that's why it's called the model matrix).

                  All you need to do is (see here)

                  Model = glm::rotate(Model, angle_in_radians, glm::vec3(x, y, z)); // where x, y, z is axis of rotation (e.g. 0 1 0)
                  

                  Note that to convert from degrees to radians, use glm::radians(degrees)

                  That takes the Model matrix and applies rotation on top of all the operations that are already in there. The other functions translate and scale do the same. That way it's possible to combine many transformations in a single matrix.

                  note: earlier versions accepted angles in degrees. This is deprecated since 0.9.6

                  Model = glm::rotate(Model, angle_in_degrees, glm::vec3(x, y, z)); // where x, y, z is axis of rotation (e.g. 0 1 0)
                  

                  这篇关于OpenGL 中的 glm 旋转用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:OpenGL 忽略四边形并使它们成为三角形 下一篇:透视投影中的 3D 场景平移 (OpenGL)

                  相关文章

                  最新文章

                  <small id='USWkU'></small><noframes id='USWkU'>

                  1. <i id='USWkU'><tr id='USWkU'><dt id='USWkU'><q id='USWkU'><span id='USWkU'><b id='USWkU'><form id='USWkU'><ins id='USWkU'></ins><ul id='USWkU'></ul><sub id='USWkU'></sub></form><legend id='USWkU'></legend><bdo id='USWkU'><pre id='USWkU'><center id='USWkU'></center></pre></bdo></b><th id='USWkU'></th></span></q></dt></tr></i><div id='USWkU'><tfoot id='USWkU'></tfoot><dl id='USWkU'><fieldset id='USWkU'></fieldset></dl></div>

                      <legend id='USWkU'><style id='USWkU'><dir id='USWkU'><q id='USWkU'></q></dir></style></legend>

                      <tfoot id='USWkU'></tfoot>
                      • <bdo id='USWkU'></bdo><ul id='USWkU'></ul>