我正在尝试旋转摄像机,目的是看到一个物体通过旋转矩阵绕着我的凸轮旋转。我开发的问题是它不起作用。
所以我尝试使用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;
}
我希望看到我的网格围绕相机旋转,但是我只让凸轮围绕网格旋转。
答案 0 :(得分:0)
如果要围绕点旋转对象,则必须为该对象设置模型矩阵。
定义振幅,即物体轨道的半径。必须通过原点的半径平移对象。然后必须旋转它。最后,动画系统(绕行对象)必须移动到枢轴。在您的情况下,枢轴会指向视点(相机位置):
model = translate(eye) * rotation * translate(radius)
modelView = view * model;
float radius = (...);
glm::mat4 model(1.0f);
glm::translate(model, Eye);
glm::rotate(model, a * glm::radians(180.0f), glm::vec3(0.0f, 1.0f, 0.0f));
glm::translate(model, glm::vec3(radius, 0.0f, 0.0f));
glm::mat4 modelView = m_View * model;