翻译鼠标拖拽移动到物体的3D旋转的最佳方式 [英] Best way to translate mouse drag motion into 3d rotation of an object

查看:374
本文介绍了翻译鼠标拖拽移动到物体的3D旋转的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我希望能够在三维绕3D对象。最简单的方法就是直接转换X和Y鼠标移动至Y和X轴的旋转,但如果有沿两个轴部分旋转,模型旋转的方式变得非常违反直觉的(也就是说,如果你把目标约180度轴,你的运动,沿另一个轴是相反的)。

I have a 3d object that I wish to be able to rotate around in 3d. The easiest way is to directly translate X and Y mouse motion to rotation about the Y and X axes, but if there is some rotation along both axes, the way the model rotates becomes highly counterintuitive (i.e. if you flip the object 180 degrees about one axis, your motion along the other axis is reversed).

我可以简单地做上面的方法,但不是存储量绕着两个轴,我可以存储完整的旋转矩阵和公正的进一步沿每个鼠标拖动同一轴线旋转,但我很担心,这将很快有precision问题。

I could simply do the above method, but instead of storing the amount to rotate about the two axes, I could store the full rotation matrix and just further rotate it along the same axes for each mouse drag, but I'm concerned that that would quickly have precision issues.

推荐答案

创建一个累加器矩阵,与身份对其进行初始化。

Create an accumulator matrix and initialize it with the identity.

每个框架,应用到你的模型视点/世界矩阵状态绘制对象之前。

Each frame, apply that to your modelview/world matrix state before drawing the object.

当鼠标移动,构造大约与一些sensitivity_constant * delta_x X轴的旋转矩阵。构造有关的其它部件在Y轴的另一旋转矩阵。乘1,那么其他到累加器

Upon mouse motion, construct a rotation matrix about the X axis with some sensitivity_constant * delta_x. Construct another rotation matrix about the Y axis for the other component. Multiply one, then the other onto the accumulator.

当您移动鼠标累加器将改变。当画,它将如您所愿定位的对象。

The accumulator will change as you move the mouse. When drawing, it will orient the object as you expect.

此外,谈到四元数的人是正确的;这看起来只适合小的增量变化。如果快速拖动它的对角线,它不会旋转挺你期望的方式。

Also, the person talking about quaternions is right; this will look good only for small incremental changes. If you drag it quickly on a diagonal, it won't rotate quite the way you expect.

这篇关于翻译鼠标拖拽移动到物体的3D旋转的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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