我正在尝试实现一个 opengl 相机,它可以围绕指定的世界坐标旋转相机的位置。我正在尝试使用 glm 数学库来做到这一点;我的代码如下
void Camera::dolly(double angle_x, double angle_y, const double& loc_x, const double& loc_y, const double& loc_z, const double& dt) {
glm::vec3 target = glm::vec3(loc_x,loc_y,loc_z);
glm::quat Q;glm::vec3 axis0(0.0f,1.0f,0.0f);
glm::quat R;glm::vec3 axis1(1.0f,0.0f,0.0f);
position = position - target;
//glm::normalize(axis0);
glm::normalize(axis1);
Q = glm::gtx::quaternion::angleAxis( float(angle_x ), axis0 );;
R = glm::gtx::quaternion::angleAxis( float(andl_y ), axis1 );;
glm::quat final = R*Q;
position = final * position;
position = position + target;
cout << "\tPosition: " << position.x << " " << position.y << " " << position.z <<endl;
}
当我测试代码时,使用 quat Q 的旋转工作正常,但 quat R 会导致“不稳定”旋转。我究竟做错了什么?