如何在opengl中使用四元数围绕屏幕中心旋转? [英] How to rotate about the center of screen using quaternions in opengl?

查看:488
本文介绍了如何在opengl中使用四元数围绕屏幕中心旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现arcball/trackball旋转,但是中心位置有问题 回转.无论如何,我都希望中心成为屏幕的中心.

I am trying implement arcball/trackball rotation but I have a problem with the center of rotation. I want the center to be the center of my screen no matter what.

让我解释一下到目前为止我做了什么.

Let me explain what I have done so far.

我创建了一个四分位数 (旋转轴:vector_start x vector_end,角度:vector_start * vector_end)

I've created a quaterion (rotation axis: vector_start x vector_end, angle: vector_start * vector_end)

根据该四元数,我创建了一个旋转矩阵,以便将其与glMultMatrixf(matrix)结合使用并获得所需的旋转.

From that quaternion I've created a rotation matrix in order to use it with glMultMatrixf(matrix) and get the desired rotation.

问题是,虽然我的模型似乎在弧线球旋转中旋转,但它始终围绕其本地原点旋转.我如何使其绕屏幕中心旋转 不管它的原产地在哪里?

The problem is that while my model seems to arcball rotate as it should it always rotates around its local origin. How could I make it rotate around the center of my screen no matter where its local origin is located?

我想解决这个问题的方法可能是平移整个旋转轴 在屏幕的中央,然后进行旋转,但这可行吗? 我在这里想念什么吗?

I suppose a solution to that problem could be to translate the whole rotation axis in the center of the screen and then apply the rotation but is this possible? Do I miss something here?

推荐答案

您应该能够通过以正确的顺序应用旋转和平移矩阵来解决此问题. 在您的代码中,您可以平移回原点T(-pos_x,-pos_y,-pos_z),进行旋转,然后再次平移到对象中心T(pos_x,pos_y,pos_z).通常,这应该可以工作,而与旋转矩阵的构造方式无关.

You should be able to solve this by applying rotation and translation matrices in the correct order. In your code you could translate back to the origin T(-pos_x, -pos_y, -pos_z), apply your rotation, and translate to the object center again T(pos_x, pos_y, pos_z). This should work in general, independent of how your rotation matrix is constructed.

这篇关于如何在opengl中使用四元数围绕屏幕中心旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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