#ifndef TEXTURE_H #define TEXTURE_H #include #include "vec3.h" class Texture { public: virtual Color value(double u, double v, const Point3& p) const = 0; }; class Solid_color : public Texture { public: Solid_color() {} Solid_color(Color c) : color_value(c) {} Solid_color(double red, double green, double blue) : Solid_color(Color(red, green, blue)) {} virtual Color value(double u, double v, const Vec3& p) const { return color_value; } private: Color color_value; }; class Checker_texture : public Texture { public: Checker_texture() {} Checker_texture(std::shared_ptr t0, std::shared_ptr t1) : even(t0), odd(t1) {} virtual Color value(double u, double v, const Vec3& p) const { auto sines = std::sin(10*p.x())*std::sin(10*p.y())*std::sin(10*p.z()); if (sines < 0) return odd->value(u, v, p); else return even->value(u, v, p); } private: std::shared_ptr even; std::shared_ptr odd; }; #endif // TEXTURE_H