Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenGL摄像机俯仰、偏航和滚动旋转_C++_Opengl_Camera_Rotation_Trigonometry - Fatal编程技术网

C++ OpenGL摄像机俯仰、偏航和滚动旋转

C++ OpenGL摄像机俯仰、偏航和滚动旋转,c++,opengl,camera,rotation,trigonometry,C++,Opengl,Camera,Rotation,Trigonometry,我正在尝试创建一个类来控制OpenGL中的相机。 我有三种方法来改变相机的俯仰、偏航和滚动。 这些方法使用float参数作为要添加的旋转量 这些方法中的代码就是我需要帮助的地方。旋转存储在矢量3中。 到目前为止,对于改变音高的方法,我有: void changePitch(float degrees) { float rads = MathHelp::degreesToRadians(degrees); m_rotation.x += cos(m_rotation.y) * ra

我正在尝试创建一个类来控制OpenGL中的相机。 我有三种方法来改变相机的俯仰、偏航和滚动。 这些方法使用float参数作为要添加的旋转量

这些方法中的代码就是我需要帮助的地方。旋转存储在矢量3中。 到目前为止,对于改变音高的方法,我有:

void changePitch(float degrees)
{
    float rads = MathHelp::degreesToRadians(degrees);
    m_rotation.x += cos(m_rotation.y) * rads;
}
这是我一个人所能做到的。它的工作原理是,相机朝上或朝下z轴时上下观察,而不是朝下x轴时。我尝试添加z旋转:

m_rotation.z += sin(m_rotation.y) * rads;

但这并不顺利。

假设你有
上方向向量
看方向向量
右方向向量
3D向量指向上,看你相机的方向和右边。然后,要正确增加螺距,应按如下方式进行计算:

void changePitch(angle) {
    angle = DegreeToRadian(angle);

    // Rotate lookAtVector around the right vector
    // This is where we actually change pitch
    lookAtVector = Normalize3dVector(viewDir * cos(angle) + UpVector * sin(angle));

    // Now update the upVector
    upVector = CrossProduct(rightVector, lookAtVector);
}

在上面的摘录中,任意使用的函数的名称是不言自明的。

在进入三角函数之前,必须应用从度到弧度的转换。不与sin、cos或tan的结果相乘。角度以弧度的形式存储在向量中。那么
rads
是一个常数,它将乘以进入sin的角度,而不是sin的结果,即`cos(m_rotation.y*rads)`–但是你不能简单地“添加”旋转。这根本不是它的工作原理。旋转的串联是乘法。rads是将参数(浮动度)转换为弧度。这是转动的量。这个方法将被用来改变音高,以度为单位,如果这样更容易理解的话。啊,好的,这对我来说是有意义的。我以后会试试的!如何将这些添加到最终相机矩阵以应用旋转?但什么是“viewDir”?