首页 > 解决方案 > 如何用 glm 旋转相机视图?

问题描述

我试图旋转我的相机,目的是看到一个物体在我的凸轮周围旋转,我开发的问题是它不起作用。

所以我尝试使用 glm::rotation 矩阵并将值

m_View = glm::rotate(m_View, a * glm::radians(180.0f), glm::vec3(0.0f, 1.0f, 0.0f))

但它也不起作用:

void CCam::setView()
{

    Front = glm::normalize(Eye - At);
    Right = glm::normalize(glm::cross(Up, Front));
    up = glm::cross(Front, Right); // Up Verdadero


    m_View = glm::lookAt(
        Eye,    // Camera Position
        (Eye + Front),      // Where the camera looks
        up      // This is another way to say camera is not rotated 
    );


    newAt = glm::vec4(At, 1.0f);


    //m_View = m_View * GLMatrixRotationY(a);
    m_View = glm::rotate(m_View, a * glm::radians(180.0f), glm::vec3(0.0f, 1.0f, 0.0f));
}

glm::mat4 CCam::GLMatrixRotationX(float Angle)
{
    matrizRotacionX = glm::mat4(
        1, 0, 0, 0,
        0, cos(Angle), -sin(Angle), 0,
        0, sin(Angle), cos(Angle), 0,
        0, 0, 0, 1
    );

    return matrizRotacionX;
}

我希望看到我的网格围绕相机旋转,但我只让凸轮围绕网格旋转。

标签: c++openglglm-math

解决方案


推荐阅读