linear interpolation for vectors
This commit is contained in:
parent
0a30234b26
commit
c4eb43a6f3
|
@ -12,7 +12,11 @@ colour rayColour(const ray& r)
|
||||||
{
|
{
|
||||||
vec3 unitDirection = unitVector(r.direction());
|
vec3 unitDirection = unitVector(r.direction());
|
||||||
double t = 0.5 * (unitDirection.y() + 1.0);
|
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()
|
int main()
|
||||||
|
|
|
@ -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]);
|
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)
|
inline vec3 unitVector(vec3 v)
|
||||||
{
|
{
|
||||||
return v / v.length();
|
return v / v.length();
|
||||||
|
|
Loading…
Reference in New Issue