00001
00002
00003 #ifndef __MATERIAL_H
00004 #define __MATERIAL_H
00005
00006 #include <esg/visitor/Visitor.h>
00007 #include <esg/ESGObject.h>
00008
00009 namespace esg {
00010
00011
00012
00013
00014
00015 typedef Roughness Shininess;
00016 typedef Transparency Transmission;
00017
00018
00019
00020
00021
00022 class OGSCENE_EXPORT Material : public ESGObject{
00023 protected:
00024 virtual void _duplicate_attributes (const Material&) {}
00025
00026 public:
00027 virtual ~Material() {}
00028 virtual void acceptVisitor (Visitor&) = 0;
00029 virtual Material* clone () const = 0;
00030 };
00031
00032
00033
00034
00035
00036
00037 class OGSCENE_EXPORT _ScalarMat : public Material {
00038 protected:
00039 float _val;
00040
00041 protected:
00042 virtual void _duplicate_attributes (const Material& src) {
00043 Material::_duplicate_attributes(src);
00044 _val = ((_ScalarMat&)src)._val;
00045 }
00046
00047 public:
00048 _ScalarMat (float v = 0.0) : _val(v) {}
00049
00050 virtual void acceptVisitor (Visitor&) = 0;
00051 virtual Material* clone () const = 0;
00052 virtual float value () const { return _val; }
00053 virtual void setValue (float v) { _val = v; }
00054 };
00055
00056
00057
00058
00059
00060
00061 class OGSCENE_EXPORT Roughness : public _ScalarMat {
00062 public:
00063 Roughness (float v = 0.0) : _ScalarMat(v) {}
00064 Roughness (int v) : _ScalarMat(v/128.0) {}
00065
00066 virtual void acceptVisitor (Visitor& v) { v.visitRoughness(this); }
00067 virtual Material* clone (void) const { return new Roughness(_val); }
00068 virtual int intValue (void) const { return (int)(_val * 128.0); }
00069 };
00070
00071
00072
00073
00074 class OGSCENE_EXPORT IndexOfRefraction : public _ScalarMat {
00075 public:
00076 IndexOfRefraction (float v = 0.0) : _ScalarMat(v) {}
00077
00078 virtual void acceptVisitor (Visitor& v) { v.visitIndexOfRefraction(this); }
00079 virtual Material* clone (void) const { return new IndexOfRefraction(_val); }
00080 };
00081
00082
00083
00084
00085
00086
00087
00088
00089 class OGSCENE_EXPORT _VectorMat : public Material {
00090 protected:
00091 Vector3 _val;
00092 double _avgVal;
00093
00094 protected:
00095 virtual void _duplicate_attributes (const Material& src) {
00096 Material::_duplicate_attributes(src);
00097 _val.set(((_VectorMat&)src)._val);
00098 }
00099
00100 public:
00101 _VectorMat (Vector3 v)
00102 : _val(v), _avgVal((v.x+v.y+v.z)/3.) {}
00103
00104 _VectorMat (float x=.0, float y=.0, float z=.0) :
00105 _val(x,y,z), _avgVal((x+y+z)/3.) {}
00106
00107 virtual void acceptVisitor (Visitor&) = 0;
00108 virtual Material* clone (void) const = 0;
00109 virtual const Vector3& value (void) const { return _val; }
00110
00111 virtual void setValue (const Vector3& v) {
00112 _val.set(v);
00113 _avgVal = (v.x+v.y+v.z) / 3.;
00114 }
00115
00116 virtual void setValue (float x, float y, float z) {
00117 _val.set(x, y, z);
00118 _avgVal = (x+y+z) / 3.;
00119 }
00120
00121 double avgValue (void) const { return _avgVal; }
00122 };
00123
00124
00125
00126
00127
00128 class OGSCENE_EXPORT Specular : public _VectorMat {
00129 public:
00130 Specular (Vector3 v) : _VectorMat(v) {}
00131 Specular (float x=.0, float y=.0, float z=.0) : _VectorMat(x,y,z) {}
00132
00133 virtual void acceptVisitor (Visitor& v) { v.visitSpecular(this); }
00134 virtual Material* clone (void) const { return new Specular(_val); }
00135 };
00136
00137
00138
00139
00140
00141 class OGSCENE_EXPORT Diffuse : public _VectorMat {
00142 public:
00143 Diffuse (Vector3 v) : _VectorMat(v) {}
00144 Diffuse (float x=.8, float y=.8, float z=.8) : _VectorMat(x,y,z) {}
00145
00146 virtual void acceptVisitor (Visitor& v) { v.visitDiffuse(this); }
00147 virtual Material* clone (void) const { return new Diffuse(_val); }
00148 };
00149
00150
00151
00152
00153 class OGSCENE_EXPORT Ambient : public _VectorMat {
00154 public:
00155 Ambient (Vector3 v) : _VectorMat(v) {}
00156 Ambient (float x=.2, float y=.2, float z=.2) : _VectorMat(x,y,z) {}
00157
00158 virtual void acceptVisitor (Visitor& v) { v.visitAmbient(this); }
00159 virtual Material* clone (void) const { return new Ambient(_val); }
00160 };
00161
00162
00163
00164
00165 class OGSCENE_EXPORT Transparency : public _VectorMat {
00166 public:
00167 Transparency (Vector3 v) : _VectorMat(v) {}
00168 Transparency (float x=.0, float y=.0, float z=.0) : _VectorMat(x,y,z) {}
00169
00170 virtual void acceptVisitor (Visitor& v) { v.visitTransparency(this); }
00171 virtual Material* clone (void) const { return new Transparency(_val); }
00172 };
00173
00174
00175
00176
00177 class OGSCENE_EXPORT Reflection : public _VectorMat {
00178 public:
00179 Reflection (Vector3 v) : _VectorMat(v) {}
00180 Reflection (float x=.0, float y=.0, float z=.0) : _VectorMat(x,y,z) {}
00181
00182 virtual void acceptVisitor (Visitor& v) { v.visitReflection(this); }
00183 virtual Material* clone (void) const { return new Reflection(_val); }
00184 };
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 class OGSCENE_EXPORT FresnelTerm : public _VectorMat {
00200 public:
00201 FresnelTerm (Vector3 v) : _VectorMat(v) {}
00202 FresnelTerm (float x=1.0, float y=1.0, float z=1.0) : _VectorMat(x,y,z) {}
00203
00204 virtual void acceptVisitor (Visitor& v) { v.visitFresnelTerm(this); }
00205 virtual Material* clone (void) const { return new FresnelTerm(_val); }
00206 };
00207
00208
00209
00210
00211
00212
00213
00214 class OGSCENE_EXPORT GaussianCoef : public _VectorMat {
00215 public:
00216 GaussianCoef (Vector3 v) : _VectorMat(v) {}
00217 GaussianCoef (float x=1.0, float y=1.0, float z=1.0) : _VectorMat(x,y,z) {}
00218
00219 virtual void acceptVisitor (Visitor& v) { v.visitGaussianCoef(this); }
00220 virtual Material* clone (void) const { return new GaussianCoef(_val); }
00221 };
00222
00223
00224 };
00225
00226 #endif // __MATERIAL_H