00001 #ifndef SOLIDMATERIAL_H
00002 #define SOLIDMATERIAL_H
00003
00004 #include "material.h"
00005 #include "pluginfactory.h"
00006
00007 #include <iostream>
00008
00009 inline Material * new_solid_material(std::map<std::string, std::string> props);
00010
00015 class SolidMaterial : public Material
00016 {
00018 class SolidMaterialStaticInit
00019 {
00020 public:
00022 SolidMaterialStaticInit()
00023 {
00024 MaterialFactory::get_instance()->registerPlugin("solid", sigc::ptr_fun(new_solid_material));
00025 }
00026 };
00027
00028 private:
00030 static SolidMaterialStaticInit m_init;
00031
00032 protected:
00036 double m_reflection_coefficient;
00037
00041 double m_diffusion_factor;
00042
00045 double m_reflectivity;
00046
00048 Magick::Color m_color;
00049
00051 bool m_is_light_source;
00052
00055 double m_opacity;
00056
00058 double m_refraction_index;
00059
00061 virtual void normalize_opacity() {
00062 m_opacity = m_opacity > TRANSPARENT ? TRANSPARENT
00063 : m_opacity < OPAQUE ? OPAQUE
00064 : m_opacity;
00065 }
00066
00067 public:
00068
00069
00070
00071
00072
00073 SolidMaterial(bool is_light)
00074 : m_reflection_coefficient(1.0),
00075 m_diffusion_factor(0.25f),
00076 m_color(),
00077 m_is_light_source(is_light),
00078 m_reflectivity(35.0),
00079 m_refraction_index(1.35),
00080 m_opacity(OPAQUE) {}
00081
00082 SolidMaterial(Magick::Color m_color, double reflect = 1.0f, double diffuse = 0.25f, bool is_light = false, double opacity = OPAQUE)
00083 : m_reflection_coefficient(reflect),
00084 m_diffusion_factor(diffuse),
00085 m_color(m_color),
00086 m_is_light_source(is_light),
00087 m_reflectivity(35.0),
00088 m_refraction_index(1.35),
00089 m_opacity(opacity) {}
00090
00092
00093
00094 SolidMaterial(Magick::Color m_color,
00095 bool is_light ,
00096 double reflection,
00097 double diffuse ,
00098 double reflectivity,
00099 double refraction,
00100 double opacity) :
00101 m_color(m_color),
00102 m_is_light_source(is_light),
00103 m_reflection_coefficient(reflection),
00104 m_diffusion_factor(diffuse),
00105 m_reflectivity(reflectivity),
00106 m_refraction_index(refraction),
00107 m_opacity(opacity) {}
00108
00110 SolidMaterial(const SolidMaterial &other)
00111 : m_reflection_coefficient(other.m_reflection_coefficient),
00112 m_diffusion_factor(other.m_diffusion_factor),
00113 m_color(other.m_color),
00114 m_is_light_source(other.m_is_light_source),
00115 m_reflectivity(other.m_reflectivity),
00116 m_opacity(other.m_opacity) {}
00117
00118 virtual ~SolidMaterial() {
00119 }
00120
00123 virtual Magick::Color get_color(const Point3D& intersection_point) const;
00124
00130 virtual bool is_light(const Point3D& intersection_point) const;
00131
00136 virtual void set_is_light(bool v);
00137
00141 virtual double get_diffuse(const Point3D& intersection_point) const;
00142
00145 virtual void set_diffuse(double diffuse);
00146
00150 virtual double get_reflection(const Point3D& intersection_point) const;
00151
00155 virtual double get_reflectivity(const Point3D& intersection_point) const;
00156
00162 virtual double get_refraction_index(const Point3D& intersection_point) const;
00163
00167 virtual double get_opacity(const Point3D& intersection_point) const;
00168
00173 virtual void set_opacity(double opacity);
00174
00175 #if 0
00176 Stub out specular methods.
00181 virtual double get_specular_coeffiecient() ;
00182
00187 virtual double get_specular_power() ;
00188 #endif
00189
00190 };
00191
00192 inline Material * new_solid_material(std::map<std::string, std::string> props) {
00193 bool isLight = props.count("light") > 0;
00194 Magick::Color color(props["color"]);
00195
00196 double reflection = props.count("reflection") > 0 ?
00197 (double)strtod(props["reflection" ].c_str(), NULL) : 1.0;
00198
00199 double diffusion = props.count("diffusion") > 0 ?
00200 (double)strtod(props["diffusion"].c_str(), NULL) : 1.0;
00201
00202 double reflectivity = props.count("reflectivity") > 0 ?
00203 (double)strtod(props["reflectivity"].c_str(), NULL) : 35.0;
00204
00205 double refraction = props.count("refraction") > 0 ?
00206 (double)strtod(props["refraction"].c_str(), NULL) : 1.0;
00207
00208 double opacity = props.count("opacity") > 0 ?
00209 (double)strtod(props["opacity"].c_str(), NULL) : OPAQUE;
00210
00211 log_debug("Creating material '%s' with:", props["name"].c_str());
00212 log_debug(" reflection: %2.2f", reflection );
00213 log_debug(" diffusion: %2.2f", diffusion );
00214 log_debug(" reflectivity: %2.2f", reflectivity);
00215 log_debug(" refraction: %2.2f", refraction );
00216 log_debug(" opacity: %2.2f", opacity );
00217
00218 return new SolidMaterial( color,
00219 isLight,
00220 reflection,
00221 diffusion,
00222 reflectivity,
00223 refraction,
00224 opacity
00225 );
00226 }
00227
00228 #endif