OpenGL旋转一点 [英] Opengl rotation at a point

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

问题描述

我想在opengl中旋转一个形状,但是我想在某个点旋转它.也就是说,我有一个圆柱体,我想旋转它,以使其看起来像在底部旋转,并且旋转大小"增加,直到物体掉到地面上为止.我将如何在opengl中进行这种轮换?

解决方案

  1. 翻译成原点
  2. 旋转
  3. 向后翻译

因此,如果要绕(a,b,c)旋转,则可以在步骤1中平移(-a,-b,-c),而在步骤3中平移(a,b,c).

(顺便说一下,不要害怕操作的数量.内部要做的就是将变换矩阵乘以3倍,但是变换顶点的管道不知道您执行了多少操作,它仍然只是使用最后一个矩阵.使用矩阵进行转换的神奇之处.)

I want to rotate a shape in opengl, but I want to rotate it at a point. Namely I have a cylinder and I want to rotate it so it looks like it is spinning at the bottom and the spin 'size' increases until the object falls to the ground. How would I do this kind of rotation in opengl?

解决方案

  1. Translate to the origin
  2. Rotate
  3. Translate back

So, if you want to rotate around (a,b,c), you would translate (-a,-b,-c) in step 1, and (a,b,c) in step 3.

(Don't be afraid of the number of operations, by the way. Internally all you do is multiply the transform matrix three times, but the pipeline that transforms the vertices is agnostic of how many operations you did, it still only uses the one final matrix. The magic of using a matrix for transformation.)

这篇关于OpenGL旋转一点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆