00001
00002 #ifndef CHECKERMATERIAL_H
00003 #define CHECKERMATERIAL_H
00004
00005 #include "raytrace_defs.h"
00006 #include "material.h"
00007 #include "pluginfactory.h"
00008 #include "scene.h"
00009
00010 Material * new_checker_material(std::map<std::string, std::string> props);
00011 void delete_checkermaterial(Material * checker_material);
00012
00015 class CheckeredMaterial : public Material {
00016
00018 class StaticInit {
00019 public:
00021 StaticInit() {
00022 MaterialFactory::get_instance()->registerPlugin("checkered", sigc::ptr_fun(new_checker_material));
00023 }
00024 };
00026 static StaticInit m_init;
00027
00028
00029 protected:
00031 Material * m_material_one;
00032
00034 Material * m_material_two;
00035
00037
00038
00039 double m_scale;
00040
00042 int choose_material(const Point3D& intersection_point) const ;
00043
00044 public:
00049 CheckeredMaterial(Material * one, Material * two, double scale) {
00050 m_material_one = one;
00051 m_material_two = two;
00052 m_scale = scale;
00053 }
00054
00056 CheckeredMaterial(const CheckeredMaterial &other) : m_material_one(other.m_material_one),
00057 m_material_two(other.m_material_two),
00058 m_scale(other.m_scale)
00059
00060 {
00061 }
00062
00063
00064 virtual ~CheckeredMaterial() {
00065
00066 }
00067
00069 virtual Magick::Color get_color(const Point3D& intersesction_point) const;
00070
00072 virtual bool is_light(const Point3D& intersesction_point) const;
00073
00075 virtual void set_is_light(bool v);
00076
00078 virtual double get_diffuse(const Point3D& intersesction_point) const;
00079
00081 virtual void set_diffuse(double diffuse);
00082
00084 virtual double get_reflection(const Point3D& intersesction_point) const;
00085
00087 virtual double get_reflectivity(const Point3D& intersesction_point) const;
00088
00090 virtual double get_refraction_index(const Point3D& intersesction_point) const;
00091
00093 virtual double get_opacity(const Point3D& intersesction_point) const;
00094
00096 virtual void set_opacity(double opacity);
00097
00098 public:
00100 static Material * createCheckeredMaterial(std::map<std::string, std::string>);
00101 };
00102
00103 Material * new_checker_material(std::map<std::string, std::string> props) {
00104 Scene * scene = Scene::get_instance();
00105 Material * one = scene->get_material(props["material1"]);
00106 Material * two = scene->get_material(props["material2"]);
00107
00108
00109 double scale = props.count("scale") > 0 ?
00110 (double)strtod(props["scale"].c_str(), NULL) : 1.0;
00111
00112 return new CheckeredMaterial(one, two, scale);
00113
00114 }
00115
00116 #endif