C++ 绕轴旋转相机?

C++ 绕轴旋转相机?,c++,opengl,C++,Opengl,如何在轴上旋转摄影机?我要乘什么矩阵 我正在使用glm::lookAt构建viewMatrix,但我尝试将其与旋转矩阵相乘,但什么也没有发生 glm::mat4 GetViewMatrix() { return glm::lookAt(this->Position, this->Position + this->Front, glm::vec3(0.0f, 5.0f, 0.0f)); } glm::mat4 ProjectionMatrix = glm::perspe

如何在轴上旋转摄影机?我要乘什么矩阵

我正在使用glm::lookAt构建viewMatrix,但我尝试将其与旋转矩阵相乘,但什么也没有发生

glm::mat4 GetViewMatrix()
{
    return glm::lookAt(this->Position, this->Position + this->Front, glm::vec3(0.0f, 5.0f, 0.0f));
}

glm::mat4 ProjectionMatrix = glm::perspective(actual_camera->Zoom, (float)g_nWidth / (float)g_nHeight, 0.1f, 1000.0f);
glm::mat4 ViewMatrix = actual_camera->GetViewMatrix();
glm::mat4 ModelMatrix = glm::mat4(1.0);
glm::mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;

使用以下方法旋转相机的前向和上向矢量:

或者,您可以将旋转矩阵的乘法添加到MVP构造中:

glm::mat4 MVP = ProjectionMatrix * glm::transpose(Rotation) * ViewMatrix * ModelMatrix;
重要的是,旋转发生在视图矩阵之后,因此所有对象都将相对于摄影机的位置旋转。此外,还必须使用转置(旋转)(旋转矩阵的逆方向是其转置),因为例如,顺时针旋转摄影机相当于逆时针旋转所有对象

glm::mat4 MVP = ProjectionMatrix * glm::transpose(Rotation) * ViewMatrix * ModelMatrix;