有人可以解释一下如何使用Quanternions使用鼠标来看看像一个FPS? [英] Can someone explain how I can use Quanternions to use the mouse to look around like a FPS?

查看:231
本文介绍了有人可以解释一下如何使用Quanternions使用鼠标来看看像一个FPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我问:

Yesterday I asked: How could simply calling Pitch and Yaw cause the camera to roll?

基本上,我发现因为云台锁定,如果你俯仰+偏航你将不可避免地产生滚动效应。有关详细信息,您可以阅读此问题。

Basically, I found out because of "Gimbal Lock" that if you pitch + yaw you will inevitably produce a rolling effect. For more information you can read that question.

我试图阻止这种情况发生。当你在一个正常的FPS射手环顾四周,你没有你的相机滚动的地方!

I'm trying to stop this from happening. When you look around in a normal FPS shooter you don't have your camera rolling all over the place!

这是我当前的被动鼠标功能:

Here is my current passive mouse func:

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();

}

这会导致相机基于鼠标移动(同时保持光标在中心)。我也张贴了原来的相机类这里

Which causes the camera to pitch/yaw based on the mouse movement (while keeping the cursor in the center). I've also posted my original camera class here.

该帖子中的某位建议我使用四元数来防止此效果发生,但在阅读维基百科页面之后,

Someone in that thread suggested I use Quaternions to prevent this effect from happening but after reading the wikipedia page on them I simply don't grok them.

如何在我的OpenGL / Glut应用程序中创建四元数,以便我可以正确地使我的相机环绕

How could I create a Quaternions in my OpenGL/Glut app so I can properly make my "Camera" look around without unwanted roll?

推荐答案

一个简单的基于四元数的相机,设计用于gluLookAt。

A Simple Quaternion-Based Camera, designed to be used with gluLookAt.

http://www.gamedev.net/reference/ articles / article1997.asp

这篇关于有人可以解释一下如何使用Quanternions使用鼠标来看看像一个FPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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