我希望在物体周围实现相机旋转,但是当我向不同方向旋转相机然后应用更多旋转时,模型会相对于它的初始方向旋转而不是新方向我不知道我是否遗漏了任何东西或不,我该如何解决这个问题?
我的MVP初始化
ubo.model = attr.transformation[0];
ubo.view = glm::lookAt(glm::vec3(0.0f, 10.0f, 20.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
ubo.proj = glm::perspective(glm::radians(50.0f), extend.width / (float)extend.height, 0.1f, 100.0f);
ubo.proj[1][1] *= -1;
我的更新代码
while (accumulatedTime >= timeFPS)
{
SDL_PollEvent(&event);
if (event.type == SDL_QUIT)
{
exit = true;
}
if (event.type == SDL_MOUSEMOTION && leftMouseButtonPressed == false)
{
prev.x = event.button.x;
prev.y = event.button.y;
}
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT)
{
leftMouseButtonPressed = true;
}
if (event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_LEFT)
{
leftMouseButtonPressed = false;
}
if (event.type == SDL_MOUSEMOTION && leftMouseButtonPressed == true)
{
New.x = event.button.x;
New.y = event.button.y;
delta = New - prev;
if(delta.x != 0)
ubo.view = glm::rotate(ubo.view, timeDelta * delta.x/20, glm::vec3(0.0f, 1.0f, 0.0f));
if (delta.y != 0)
ubo.view = glm::rotate(ubo.view, timeDelta * delta.y/20, glm::vec3(1.0f, 0.0f, 0.0f));
prev = New;
}
accumulatedTime -= timeFPS;
v.updateUniformBuffer(ubo);
}
v.drawFrame();
}
我的顶点缓冲区
#version 450
#extension GL_ARB_separate_shader_objects : enable
....
void main()
{
gl_Position = ubo.proj * ubo.view * ubo.model * vec4 (inPosition, 1.0);
fragTexCoord = inTexCoord;
Normal = ubo.proj * ubo.view * ubo.model * vec4 (inNormals, 1.0);
}
答案 0 :(得分:0)
事实证明我错过了矢量旋转的一些基本部分,我的结论如下: -
您可以在Here
中找到有关此内容的精彩教程