基于四元数的相机不需要的胶卷 [英] Quaternion-Based-Camera unwanted roll

查看:187
本文介绍了基于四元数的相机不需要的胶卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现基于四元数的相机,但是当绕X和Y轴移动时,相机会在Z轴上产生不必要的滚动.我希望能够在所有轴上自由地环顾四周. 我已经阅读了有关此问题的其他主题(例如: http://www.flipcode.com/forums/thread/6525 ),但我没有明白通过绕WORLD轴(即绕< 1,0,0>,< 0,1,0>,< 0,0,1>,而不是您的本地坐标,无论它们是什么."

I'm trying to implement a quaternion-based camera, but when moving around the X and Y axis, the camera produces an unwanted roll on the Z axis. I want to be able to look around freely on all axis. I've read other topics about this problem (for example: http://www.flipcode.com/forums/thread/6525 ), but I'm not getting what is meant by "Fix this by continuously rebuilding the rotation matrix by rotating around the WORLD axis, i.e around <1,0,0>, <0,1,0>, <0,0,1>, not your local coordinates, whatever they might be."

//Camera.hpp
glm::quat rotation;

//Camera.cpp
void Camera::rotate(glm::vec3 vec)
{
    glm::quat paramQuat = glm::quat(vec);
    rotation = paramQuat * rotation;
}

我这样调用旋转函数:

cam->rotate(glm::vec3(0, 0.5, 0));

这必须与本地/世界坐标有关,对吗?我只是不明白,因为我认为四元数总是基于彼此(因此四元数不能位于世界"或本地"空间中吗?). 另外,我应该在一个摄像头上使用多个四元数吗?

This must have to do with local/world coordinates, right? I'm just not getting it, since I thought quaternions are always based on each other (thus a quaternion can't be in "world" or "local" space?). Also, should i use more than one quaternion for a camera?

推荐答案

据我了解,从查看您提供的代码开始,它们的意思是您不应通过应用以下增量操作来存储和应用旋转始终以旋转四元数旋转,但是要跟踪每个轴的两个四元数(世界空间中的X和Y)并计算旋转矢量作为它们的乘积.

As far as I understand it, and from looking at the code you provided, what they mean is that you shouldn't store and apply the rotation incrementally by applying rotate on the rotation quat all the time, but instead keeping track of two quaternions for each axis (X and Y in world space) and calculating the rotation vector as the product of those.

// Camera.cpp
void Camera::SetRotation(glm::quat value)
{
    rotation = value;
}

// controller.cpp --> probably a place where you'd want to translate user input and store your rotational state
xAngle += deltaX;
yAngle += deltaY;
glm::quat rotationX = QuatAxisAngle(X_AXIS, xAngle);
glm::quat rotationY = QuatAxisAngle(Y_AXIS, yAngle);
camera.SetRotation(rotationX * rotationY);

这篇关于基于四元数的相机不需要的胶卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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