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

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

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

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

        从四元数到 OpenGL 旋转

        时间:2023-09-17
          1. <i id='95tI7'><tr id='95tI7'><dt id='95tI7'><q id='95tI7'><span id='95tI7'><b id='95tI7'><form id='95tI7'><ins id='95tI7'></ins><ul id='95tI7'></ul><sub id='95tI7'></sub></form><legend id='95tI7'></legend><bdo id='95tI7'><pre id='95tI7'><center id='95tI7'></center></pre></bdo></b><th id='95tI7'></th></span></q></dt></tr></i><div id='95tI7'><tfoot id='95tI7'></tfoot><dl id='95tI7'><fieldset id='95tI7'></fieldset></dl></div>
          2. <legend id='95tI7'><style id='95tI7'><dir id='95tI7'><q id='95tI7'></q></dir></style></legend>

              <bdo id='95tI7'></bdo><ul id='95tI7'></ul>
                <tbody id='95tI7'></tbody>

              1. <small id='95tI7'></small><noframes id='95tI7'>

                • <tfoot id='95tI7'></tfoot>

                  本文介绍了从四元数到 OpenGL 旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个要通过按键旋转的对象.物体应该偏航、俯仰和滚动.尝试了很多之后,我发现 glRotate 有它的局限性,用那个函数不可能实现类似的东西.

                  I have an object which I want to rotate via keys. The object should yaw, pitch and roll. After trying a lot, I figured out that glRotate has its limitations and it won't be possible to implement something like that with that function.

                  我研究了一下,发现了基于四元数的旋转.也可以通过旋转矩阵进行旋转,但几乎每个人都将四元数描述为有史以来最好的.

                  I've researched a bit and found out about quaternion-based rotation. It would be also possible to rotate via a rotation matrix, but almost everyone describes the quaternions as the best ever.

                  我已经阅读了四元数并且对它们相当了解,但是如何在我的 OpenGL 程序中实现它们仍然是一个谜.有谁知道一个小例子?不是如何实现四元数类,而是如何使用它.我不知道如何把这些东西放在一起.

                  I have read about the quaternions and understood them fairly well, but how to implement them in my OpenGL program is still a mystery. Does anyone know a small example? Not how to implement the quaternion class but how to use it. I don't get how to put the things together.

                  推荐答案

                  最重要的是实现从四元数构建旋转矩阵的方法.然后,就像使用普通旋转矩阵一样,只需将其与模型视图矩阵相乘即可​​.

                  The most important is to implement method that will build rotation matrices from quaternion. Then, as you'll do with normal rotation matrix, just multiply it with your modelview matrix.

                  这是一个简单的例子,用于通过鼠标移动来旋转立方体.如您所见,我需要实现三种方法:toMatrixquaternionFromAxismultiplyWith.假设您了解四元数,这应该很清楚它们的作用.

                  This is simple example that was used to rotate cube with mouse movement. As you see I've needed to implement three methods: toMatrix, quaternionFromAxis, multiplyWith. Assuming that you understand quaternions, this should be clear what they do.

                  void display() {
                  
                      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                      glPushMatrix();
                  
                      // Multiply quaternion with current modelview matrix    
                      glMultMatrixf(cameraQuaternion.toMatrix());
                  
                      // Some other transformations
                      glTranslatef(-0.5f, -0.5f, -0.5f);
                  
                      // Draw something, i.e. cube
                      glDrawArrays(GL_TRIANGLES, 0, 36);
                      glDrawArrays(GL_TRIANGLES, 0, 36);
                  
                      glPopMatrix();
                  }
                  
                  void mouseMoved(float dx, float dy) {
                      float axisY[] = { 0, 1, 0 },
                            axisX[] = { 1, 0, 0 };
                  
                      float sensitivity = 0.005f;
                      Quaternion *q1 = Quaternion.quaternionFromAxis(axisY, dx * sensitivity];
                      Quaternion *q2 = Quaternion.quaternionFromAxis(axisX, dy * sensitivity];
                  
                      // Multiply two quaternions with camera
                      cameraQuaternion = (q1.multiplyWith(q2)).multiplyWith(cameraQuaternion);
                  }
                  

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

                  上一篇:从 Windows 中的 OpenGL 窗口捕获视频 下一篇:如何在 Windows 7 中使用 OpenGL、Glut 和 Visual Studio

                  相关文章

                  最新文章

                  <legend id='jYISf'><style id='jYISf'><dir id='jYISf'><q id='jYISf'></q></dir></style></legend>
                    <bdo id='jYISf'></bdo><ul id='jYISf'></ul>

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

                • <small id='jYISf'></small><noframes id='jYISf'>

                      <tfoot id='jYISf'></tfoot>