linear interpolation for vectors

This commit is contained in:
K Tyl 2020-06-04 00:47:33 +01:00
parent 0a30234b26
commit c4eb43a6f3
2 changed files with 10 additions and 1 deletions

View File

@ -12,7 +12,11 @@ colour rayColour(const ray& r)
{
vec3 unitDirection = unitVector(r.direction());
double t = 0.5 * (unitDirection.y() + 1.0);
return (1.0-t) * colour(1.0,1.0,1.0) + t*colour(0.5, 0.7, 1.0);
auto a = colour(1.0, 1.0, 1.0);
auto b = colour(0.0, 0.0, 0.0);
return lerp(a, b, t);
}
int main()

View File

@ -107,6 +107,11 @@ inline vec3 cross(const vec3 &u, const vec3 &v)
u.e[0] * v.e[1] - u.e[1] * v.e[0]);
}
inline vec3 lerp(const vec3 &a, const vec3 &b, double t)
{
return (1.0 - t) * a + t * b;
}
inline vec3 unitVector(vec3 v)
{
return v / v.length();