如何在opengl中实现两个不同摄像机视图之间的平滑过渡

时间:2014-11-28 09:00:48

标签: opengl view transition

gluLookAt定义如下

void gluLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ,
               GLdouble centerX, GLdouble centerY, GLdouble centerZ,
               GLdouble upX, GLdouble upY, GLdouble upZ
              );

我有两个与gluLookAt相对应的不同摄像机参数,我对如何在这两个摄像机参数的视图之间实现平滑过渡感到困惑。

我希望有人可以给我一些提示或一些代码示例。

1 个答案:

答案 0 :(得分:1)

我会考虑在gluLookAt (...)生成的轮换中使用Spherical Linear Interpolation(slerp)。 GLM数学库(C ++)提供了您需要的所有内容,包括LookAt的实现。

非常粗略地说,这就是基于GLM的实现可能的样子:

// Create quaternions from the rotation matrices produced by glm::lookAt
glm::quat quat_start (glm::lookAt (eye_start, center_start, up_start));
glm::quat quat_end   (glm::lookAt (eye_end,   center_end,   up_end));

// Interpolate half way from original view to the new.
float interp_factor = 0.5; // 0.0 == original, 1.0 == new

// First interpolate the rotation
glm::quat  quat_interp = glm::slerp (quat_start, quat_end, interp_factor);

// Then interpolate the translation
glm::vec3  pos_interp  = glm::mix   (eye_start,  eye_end,  interp_factor);

glm::mat4  view_matrix = glm::mat4_cast (quat_interp); // Setup rotation
view_matrix [3]        = glm::vec4 (pos_interp, 1.0);  // Introduce translation