仅仅调用Pitch()和Yaw()怎么会导致摄像机最终Roll()? [英] How could simply calling Pitch() and Yaw() cause the camera to eventually Roll()?

查看:157
本文介绍了仅仅调用Pitch()和Yaw()怎么会导致摄像机最终Roll()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个基本的OpenGL游戏,并且我有一些可以在移动相机方面处理鼠标的代码.

I'm coding a basic OpenGL game and I've got some code that handles the mouse in terms of moving the camera.

我正在使用以下方法:

int windowWidth = 640;
int windowHeight = 480;

int oldMouseX = -1;
int oldMouseY = -1;

void mousePassiveHandler(int x, int y)
{
    int snapThreshold = 50;

    if (oldMouseX != -1 && oldMouseY != -1)
    {
        cam.yaw((x - oldMouseX)/10.0);
        cam.pitch((y - oldMouseY)/10.0);


        oldMouseX = x;
        oldMouseY = y;

        if ((fabs(x - (windowWidth / 2)) > snapThreshold) || (fabs(y - (windowHeight / 2)) > snapThreshold))
        {
            oldMouseX = windowWidth / 2;
            oldMouseY = windowHeight / 2;
            glutWarpPointer(windowWidth / 2, windowHeight / 2);
        }
    }
    else
    {
        oldMouseX = windowWidth / 2;
        oldMouseY = windowHeight / 2;
        glutWarpPointer(windowWidth / 2, windowHeight / 2);
    }


    glutPostRedisplay();

}

但是,环顾四周后,您会发现相机开始滚动"(旋转).由于我只打电话给Pitch和Yaw,所以我不知道这怎么可能.

However, after looking around in circles you'll find the camera starts to "roll" (rotate). Since I'm only calling Pitch and Yaw, I don't see how this is possible.

这是我用于我的Camera类的代码: http://pastebin.com/m20d2b01e

Here is the code I'm using for my Camera class: http://pastebin.com/m20d2b01e

据我所知,我的相机不会滚动".它应该简单地上下倾斜或左右偏航.不滚动.

As far as I know, my camera "rolling" shouldn't happen. It should simply pitch up and down or yaw left and right. NOT roll.

这可能是什么原因造成的?

What could be causing this?

推荐答案

祝贺您-您已经发现了李群理论!

Congratulations -- you have discovered Lie group theory!

是的,有可能.一系列转型的结果 取决于执行顺序.推销 其次是偏航与进行偏航不一样,其次 间距.实际上,在无限偏航的范围内 和音高,差异等于纯滚动;一般 情况要复杂一些.

Yes, it's possible. The outcome of a series of transformations depends on the order in which they're executed. Doing a pitch followed by a yaw is not the same as a doing a yaw, followed by a pitch. In fact, in the limit of infinitesimally small yaws and pitches, the difference amounts to a pure roll; the general case is a little more complicated.

(物理学家称之为 旋转组".

(Physicists call this the "commutation relationships of the rotational group".)

如果您熟悉旋转矩阵,则可以解决 很容易

If you're familiar with rotation matrices, you can work it out quite easily.

这篇关于仅仅调用Pitch()和Yaw()怎么会导致摄像机最终Roll()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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