如何在相机中添加滚动 class
How to add roll in camera class
我正在构建一个相机 class 并已从在线教程中获得构建此相机的帮助 class。
现在我想在相机中添加滚动,但找不到任何解释如何在相机中添加滚动的读物material。
Camera(glm::vec3 position = glm::vec3(0.0f, 0.0f, 500.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), Zoom(ZOOM)
{
Position = position;
WorldUp = up;
Yaw = yaw;
Pitch = pitch;
updateCameraVectors();
}
glm::mat4 GetViewMatrix()
{
return glm::lookAt(Position, Position + Front , Up);
}
void updateCameraVectors()
{
glm::vec3 front;
front.x = cos(glm::radians(Yaw - 90)) * cos(glm::radians(Pitch));
front.y = sin(glm::radians(Pitch));
front.z = sin(glm::radians(Yaw - 90)) * cos(glm::radians(Pitch)) ;
Front = glm::normalize(front);
Right = glm::normalize(glm::cross(Front, WorldUp));
Up = glm::normalize(glm::cross(Right, Front));
}
如果有人可以解释如何在此 class 中添加 ROll 或指导我阅读一些内容,我将不胜感激 material。
对于 roll 视图,您已围绕视线 (Front
) 旋转向上矢量 (Up
)。
通过Roll
:
围绕Front
定义一个旋转矩阵
glm::mat4 roll_mat = glm::rotate(glm::mat4(1.0f), glm::radians(Roll), Front);
通过矩阵变换Up
向量:
Up = glm::mat3(roll_mat) * Up;
我正在构建一个相机 class 并已从在线教程中获得构建此相机的帮助 class。
现在我想在相机中添加滚动,但找不到任何解释如何在相机中添加滚动的读物material。
Camera(glm::vec3 position = glm::vec3(0.0f, 0.0f, 500.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), Zoom(ZOOM)
{
Position = position;
WorldUp = up;
Yaw = yaw;
Pitch = pitch;
updateCameraVectors();
}
glm::mat4 GetViewMatrix()
{
return glm::lookAt(Position, Position + Front , Up);
}
void updateCameraVectors()
{
glm::vec3 front;
front.x = cos(glm::radians(Yaw - 90)) * cos(glm::radians(Pitch));
front.y = sin(glm::radians(Pitch));
front.z = sin(glm::radians(Yaw - 90)) * cos(glm::radians(Pitch)) ;
Front = glm::normalize(front);
Right = glm::normalize(glm::cross(Front, WorldUp));
Up = glm::normalize(glm::cross(Right, Front));
}
如果有人可以解释如何在此 class 中添加 ROll 或指导我阅读一些内容,我将不胜感激 material。
对于 roll 视图,您已围绕视线 (Front
) 旋转向上矢量 (Up
)。
通过Roll
:
Front
定义一个旋转矩阵
glm::mat4 roll_mat = glm::rotate(glm::mat4(1.0f), glm::radians(Roll), Front);
通过矩阵变换Up
向量:
Up = glm::mat3(roll_mat) * Up;