简体   繁体   English

如何添加滚动相机 class

[英]How to add roll in camera class

I am building a camera class and have taken help from the online tutorials for building this class.我正在构建一个摄像头 class,并从在线教程中获得了构建这个 class 的帮助。

Now i want to add roll in the camera and could not find any reading material which would explain how to add Roll in camera.现在我想在相机中添加滚动并且找不到任何可以解释如何在相机中添加滚动的阅读材料。

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));
    }

I would be thankful if someone can explain how to add ROll in this class or guide me to some reading material.如果有人能解释如何在这个 class 中添加 ROll 或指导我阅读一些阅读材料,我将不胜感激。

To roll the view, you have rotate the up vector ( Up ) around the line of sight ( Front ).滚动视图,您需要围绕视线 ( Front ) 旋转向上矢量 ( Up )。

Define a rotation matrix around Front by Roll :通过Roll定义围绕Front的旋转矩阵:

glm::mat4 roll_mat = glm::rotate(glm::mat4(1.0f), glm::radians(Roll), Front);

Transform the Up vector by the matrix:通过矩阵变换Up向量:

Up = glm::mat3(roll_mat) * Up;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM