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

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

问题描述

我正在尝试实现基于四元数的相机,但是当围绕 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;
}

我这样调用rotate函数:

I call the rotate function like this:

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天全站免登陆