From c4eb43a6f3fd5bfd9a5ad68fbe7fc87a3744d24b Mon Sep 17 00:00:00 2001 From: K Tyl Date: Thu, 4 Jun 2020 00:47:33 +0100 Subject: [PATCH] linear interpolation for vectors --- src/main.cpp | 6 +++++- src/vec3.h | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index bcdf74c..5c5ff72 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -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() diff --git a/src/vec3.h b/src/vec3.h index 5045353..08d3f46 100755 --- a/src/vec3.h +++ b/src/vec3.h @@ -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();