T2 Add a lambertian material inherits class material

T2.1 Add a function near_zero() in vec.h to check if a vector is close to zero in length

class vec3 {
    ...

    double length_squared() const {
        return e[0]*e[0] + e[1]*e[1] + e[2]*e[2];
    }

    // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    bool near_zero() const {
        // Return true if the vector is close to zero in all dimensions.
        auto s = 1e-8;
        return (std::fabs(e[0]) < s) && (std::fabs(e[1]) < s) && (std::fabs(e[2]) < s);
    }
    // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    ...
};

T2.2 Add a lambertian class in material.h

The lambertian class inherits from material and implements the scatter() method.

It calculates a random scattered ray direction at the hit point and sets the attenuation to its albedo colour.

Last updated