Interpolating vectors
Two vectors can be interpolated linearly by scaling the difference between the two vectors and adding the result back to the original vector. This linear interpolation is often abbreviated to lerp
. The amount to lerp
by is a normalized value between 0 and 1; this normalized value is often represented by the letter t. The following figure shows lerp
between two vectors with several values for t:
When t = 0, the interpolated vector is the same as the starting vector. When t = 1, the interpolated vector is the same as the end vector.
Implement the lerp
function in vec3.cpp
. Don't forget to add the function declaration to vec3.h
:
vec3 lerp(const vec3 &s, const vec3 &e, float t) { return vec3( s.x + (e.x - s.x) * t, s.y + (e.y - s.y) * t, ...