h o m e d o c u m e n t a t i o n c l a s s h i e r a r c h y

Material.h

00001 //
00002 //  Filename         : Material.h
00003 //  Author(s)        : Stephane Grabli
00004 //  Purpose          : Class used to handle materials.
00005 //  Date of creation : 10/10/2002
00006 //
00008 
00009 
00010 //
00011 //  Copyright (C) : Please refer to the COPYRIGHT file distributed 
00012 //   with this source distribution. 
00013 //
00014 //  This program is free software; you can redistribute it and/or
00015 //  modify it under the terms of the GNU General Public License
00016 //  as published by the Free Software Foundation; either version 2
00017 //  of the License, or (at your option) any later version.
00018 //
00019 //  This program is distributed in the hope that it will be useful,
00020 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 //  GNU General Public License for more details.
00023 //
00024 //  You should have received a copy of the GNU General Public License
00025 //  along with this program; if not, write to the Free Software
00026 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 //
00029 
00030 #ifndef  MATERIAL_H
00031 # define MATERIAL_H
00032 
00033 # include "../system/FreestyleConfig.h"
00034 
00036 class Material
00037 {
00038 public:
00040   inline Material();
00054   inline Material(const float *iDiffuse,
00055                   const float *iAmbiant,
00056                   const float *iSpecular, 
00057                   const float *iEmission, 
00058                   const float iShininess);
00059 
00061   inline Material(const Material& m);
00063   virtual ~Material() {}
00064 
00065 
00067   inline const float * diffuse() const { return Diffuse; }
00069   inline const float   diffuseR() const { return Diffuse[0]; }
00071   inline const float   diffuseG() const { return Diffuse[1]; }
00073   inline const float   diffuseB() const { return Diffuse[2]; }
00075   inline const float   diffuseA() const { return Diffuse[3]; }
00076 
00078   inline const float * specular() const { return Specular; }
00080   inline const float   specularR() const { return Specular[0]; }
00082   inline const float   specularG() const { return Specular[1]; }
00084   inline const float   specularB() const { return Specular[2]; }
00086   inline const float   specularA() const { return Specular[3]; }
00087 
00089   inline const float * ambient() const { return Ambient; }
00091   inline const float   ambientR() const { return Ambient[0]; }
00093   inline const float   ambientG() const { return Ambient[1]; }
00095   inline const float   ambientB() const { return Ambient[2]; }
00097   inline const float   ambientA() const { return Ambient[3]; }
00098 
00100   inline const float * emission() const { return Emission; }
00102   inline const float   emissionR() const { return Emission[0]; }
00104   inline const float   emissionG() const { return Emission[1]; }
00106   inline const float   emissionB() const { return Emission[2]; }
00108   inline const float   emissionA() const { return Emission[3]; }
00109 
00111   inline const float shininess() const { return Shininess; }
00112 
00123   inline void SetDiffuse(const float r, const float g, const float b, const float a);
00134   inline void SetSpecular(const float r, const float g, const float b, const float a);
00145   inline void SetAmbient(const float r, const float g, const float b, const float a);
00146 
00157   inline void SetEmission(const float r, const float g, const float b, const float a);
00158 
00163   inline void SetShininess(const float s);
00164 
00165   /* operators */
00166   inline Material& operator=(const Material& m);
00167   inline bool operator!=(const Material& m) const;
00168   inline bool operator==(const Material& m) const;
00169 
00170 private:
00171 
00173   float Diffuse[4];
00174   float Specular[4];
00175   float Ambient[4];
00176   float Emission[4];
00177   float Shininess;
00178 
00179 };
00180 
00181 Material::Material()
00182 {
00183   Ambient[0] = Ambient[1] = Ambient[2] = 0.2f;
00184   Ambient[3] = 1.f;
00185 
00186   Diffuse[0] = Diffuse[1] = Diffuse[2] = 0.8f;
00187   Diffuse[3] = 1.f;
00188 
00189   Emission[0] = Emission[1] = Emission[2] = 0.f;
00190   Emission[3] = 1.f;
00191 
00192   Specular[0] = Specular[1] = Specular[2] = 0.f;
00193   Specular[3] = 1.f;
00194 
00195   Shininess = 0.f;
00196 }
00197 
00198 Material::Material(const float *iDiffuse,
00199                    const float *iAmbiant,
00200                    const float *iSpecular, 
00201                    const float *iEmission, 
00202                    const float iShininess)
00203 {
00204   for(int i=0; i<4; i++)
00205   {
00206     Diffuse[i]  = iDiffuse[i];
00207     Specular[i] = iSpecular[i];
00208     Ambient[i]  = iAmbiant[i];
00209     Emission[i] = iEmission[i];
00210   }
00211 
00212   Shininess = iShininess;
00213 }
00214 
00215 Material::Material(const Material& m)
00216 {
00217   for(int i=0; i<4; i++)
00218   {
00219     Diffuse[i]  = m.diffuse()[i];
00220     Specular[i] = m.specular()[i];
00221     Ambient[i]  = m.ambient()[i];
00222     Emission[i] = m.emission()[i];
00223   }
00224 
00225   Shininess = m.shininess();
00226 }
00227 
00228 void Material::SetDiffuse(const float r, const float g, const float b, const float a)
00229 {
00230   Diffuse[0] = r;
00231   Diffuse[1] = g;
00232   Diffuse[2] = b;
00233   Diffuse[3] = a;
00234 }
00235 
00236 void Material::SetSpecular(const float r, const float g, const float b, const float a)
00237 {
00238   Specular[0] = r;
00239   Specular[1] = g;
00240   Specular[2] = b;
00241   Specular[3] = a;
00242 }
00243   
00244 void Material::SetAmbient(const float r, const float g, const float b, const float a)
00245 {
00246   Ambient[0] = r;
00247   Ambient[1] = g;
00248   Ambient[2] = b;
00249   Ambient[3] = a;
00250 }
00251 
00252 void Material::SetEmission(const float r, const float g, const float b, const float a)
00253 {
00254   Emission[0] = r;
00255   Emission[1] = g;
00256   Emission[2] = b;
00257   Emission[3] = a;
00258 }
00259 
00260 void Material::SetShininess(const float s)
00261 {
00262   Shininess = s;
00263 }
00264 
00265 Material& Material::operator=(const Material& m)
00266 {
00267   for(int i=0; i<4; i++)
00268   {
00269     Diffuse[i]  = m.diffuse()[i];
00270     Specular[i] = m.specular()[i];
00271     Ambient[i]  = m.ambient()[i];
00272     Emission[i] = m.emission()[i];
00273   }
00274 
00275   Shininess = m.shininess();
00276 
00277   return *this;
00278 }
00279 
00280 bool Material::operator!=(const Material& m) const
00281 {
00282   if(Shininess != m.shininess())
00283     return true;
00284   for(int i=0; i<4; i++)
00285   {
00286     if(Diffuse[i]  != m.diffuse()[i])
00287       return true;
00288     if(Specular[i] != m.specular()[i])
00289       return true;
00290     if(Ambient[i]  != m.ambient()[i])
00291       return true;
00292     if(Emission[i] != m.emission()[i])
00293       return true;
00294   }
00295 
00296   return false;
00297 }
00298 
00299 bool Material::operator==(const Material& m) const
00300 {
00301   return (!((*this)!=m));
00302 }
00303 
00304 #endif // MATERIAL_H