I'm trying to interpolate between two points on a sphere to make a simple camera following an arc. Quaternions are utterly incomprehensible to me, so I've been trying to hack something together through trial and error.
Here's the gist of the code:
glm::vec3 camera_start_pos = {-0.282546, 1.525186, -2.946500};
glm::vec3 camera_end_pos = {-2.086190, 1.957833, 1.466586};
camera_pos_start_q = glm::rotation(camera_start_pos, vec3(1,1,1));
camera_pos_end_q = glm::rotation(camera_end_pos, vec3(1,1,1));
float cur_time = (sin(glfwGetTime())+1.f)/2.f;
auto pos_slerp = glm::slerp(camera_pos_start_q, camera_pos_end_q, cur_time);
camera_pos = pos_slerp * vec3(1,1,1);
view = glm::lookAt(camera_pos,
camera_pos + camera_front,
camera_up);
This code does produce some interpolated movement, but not between the positions I want to.
What vectors do I need to use in the calls to glm::rotation to get the right quaternions? What do i need to multiply pos_slerp by to interpolate between camera_start_pos and camera_end_pos?
Is there a way to interpolate between these two points in an arc-like manner without quaternions (or including some spline library)?
I don't now the library you use but here is the method.
I found this method in a R package and I have to say I don't understand everything:
x1andx2are the endpoints of the arc, then bothlspandlepshould be equal toRs1ands2have been normalized, the denominator in the calculation ofphiis useless