gluLookAt is defined as follows
void gluLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ,
GLdouble centerX, GLdouble centerY, GLdouble centerZ,
GLdouble upX, GLdouble upY, GLdouble upZ
);
I have two different cameras parameters corresponding to gluLookAt,I am confused about how to implement a smooth transition between views of these two camera parameters.
I hope that somebody can give me some cue or some code example.
I would consider using Spherical Linear Interpolation (slerp) on the rotations produced by gluLookAt (...). The GLM math library (C++) provides everything you need for this, including an implementation of LookAt.
// 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With