TAPs 0.7.7.3
TAPsOpenGLMaterial.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsOpenGLMaterial.hpp
00003 
00004 OpenGL Material Properties
00005 
00006 SUKITTI PUNAK   (10/23/2004)
00007 UPDATE          (07/16/2007)
00008 ******************************************************************************/
00021 #ifndef TAPs_OPENGL_MATERIAL_HPP
00022 #define TAPs_OPENGL_MATERIAL_HPP
00023 
00024 #include <iostream>
00025 #include <TAPs/Core/TAPsCGMath.hpp>
00026 #include "TAPsOpenGLEnumList.hpp"
00027 
00028 BEGIN_NAMESPACE_TAPs__OpenGL
00029 //=============================================================================
00030 class Material {
00031 //=============================================================================
00032     //-------------------------------------------------------------------------
00033     // put it through ostream
00034     friend std::ostream & operator<< ( std::ostream &output, Material const &o )
00035     {
00036         output  << "OpenGL::Material Class:"
00037                 << "\n  ambient    " << o.mat_ambient[0] << " " << o.mat_ambient[1] << " " 
00038                     << o.mat_ambient[2] << " " << o.mat_ambient[3]
00039                 << "\n  diffuse    " << o.mat_diffuse[0] << " " << o.mat_diffuse[1] << " " 
00040                     << o.mat_diffuse[2] << " " << o.mat_diffuse[3]
00041                 << "\n  specular   " << o.mat_specular[0] << " " << o.mat_specular[1] << " " 
00042                     << o.mat_specular[2] << " " << o.mat_specular[3]
00043                 << "\n  shininess  " << o.mat_shininess[0]
00044                 << "\n  emission   " << o.mat_emission[0] << " " << o.mat_emission[1] << " " 
00045                     << o.mat_emission[2] << " " << o.mat_emission[3]
00046                 << "\n  material color " << o.color_RGBA[0] << " " << o.color_RGBA[1] << " " 
00047                     << o.color_RGBA[2] << " " << o.color_RGBA[3]
00048                 ;
00049         return output;
00050     }
00051 //-----------------------------------------------------------------------------
00052 protected:
00053     // Data Members     ========================================================
00054     // Material properties of the model
00055     GLfloat mat_ambient[4];     // range [0.0-1.0]
00056     GLfloat mat_diffuse[4];     // range [0.0-1.0]
00057     GLfloat mat_specular[4];    // range [0.0-1.0]
00058     GLfloat mat_shininess[1];   // range [0.0-128.0]
00059     GLfloat mat_emission[4];    // range [0.0-1.0]
00060     GLfloat color_RGBA[4];      // range [0.0-1.0]
00061 //-----------------------------------------------------------------------------
00062 public:
00063     // Member Functions     ====================================================
00064     //-------------------------------------------------------------------------
00065     // Constructors
00073     Material ();
00074     Material (  GLfloat *ambient, GLfloat *diffuse, GLfloat *specular, 
00075                 GLfloat shininess, GLfloat *emission );
00076     Material (  GLfloat rAmbient,  GLfloat gAmbient,  GLfloat bAmbient,  GLfloat aAmbient,
00077                 GLfloat rDiffuse,  GLfloat gDiffuse,  GLfloat bDiffuse,  GLfloat aDiffuse,
00078                 GLfloat rSpecular, GLfloat gSpecular, GLfloat bSpecular, GLfloat aSpecular,
00079                 GLfloat shininess,
00080                 GLfloat rEmission, GLfloat gEmission, GLfloat bEmission, GLfloat aEmission );
00081 
00082     Material ( const Material & mat );      
00083     //-------------------------------------------------------------------------
00094     inline void ApplyMaterial  ( Enum::Face f = Enum::FRONT ) const
00095     {
00096         // Set Material Value
00097         glMaterialfv( f, GL_AMBIENT,   mat_ambient );
00098         glMaterialfv( f, GL_DIFFUSE,   mat_diffuse );
00099         glMaterialfv( f, GL_SPECULAR,  mat_specular );
00100         glMaterialfv( f, GL_SHININESS, mat_shininess );
00101         glMaterialfv( f, GL_EMISSION,  mat_emission );
00102     }
00103     inline void ApplyAmbient   ( Enum::Face f = Enum::FRONT ) const
00104     {   glMaterialfv( f, GL_AMBIENT,   mat_ambient );   }
00105     inline void ApplyDiffuse   ( Enum::Face f = Enum::FRONT ) const
00106     {   glMaterialfv( f, GL_DIFFUSE,   mat_diffuse );   }
00107     inline void ApplySpecular  ( Enum::Face f = Enum::FRONT ) const
00108     {   glMaterialfv( f, GL_SPECULAR,  mat_specular );  }
00109     inline void ApplyShininess ( Enum::Face f = Enum::FRONT ) const
00110     {   glMaterialfv( f, GL_SHININESS, mat_shininess ); }
00111     inline void ApplyEmission  ( Enum::Face f = Enum::FRONT ) const
00112     {   glMaterialfv( f, GL_EMISSION,  mat_emission );  }
00113     //-----------------------------------------------------
00114     // Assignment Operator
00115     Material & operator= ( Material const &mat );
00116     //-----------------------------------------------------
00117     inline void ApplyRGBAColor ()
00118     {   glColor4fv( color_RGBA );   }
00119     //-------------------------------------------------------------------------
00120     // Get/Set Fns
00132     inline void SetAmbient   ( GLfloat const m[] )
00133     {
00134         mat_ambient[0] = m[0];
00135         mat_ambient[1] = m[1];
00136         mat_ambient[2] = m[2];
00137         mat_ambient[3] = m[3];
00138     }
00139     inline void SetDiffuse   ( GLfloat const m[] )
00140     {
00141         mat_diffuse[0] = m[0];
00142         mat_diffuse[1] = m[1];
00143         mat_diffuse[2] = m[2];
00144         mat_diffuse[3] = m[3];
00145     }
00146     inline void SetSpecular  ( GLfloat const m[] )
00147     {
00148         mat_specular[0] = m[0];
00149         mat_specular[1] = m[1];
00150         mat_specular[2] = m[2];
00151         mat_specular[3] = m[3];
00152     }
00153     inline void SetShininess ( GLfloat const m[] )
00154     {
00155         mat_shininess[0] = m[0];
00156     }
00157     inline void SetEmission  ( GLfloat const m[] )
00158     {
00159         mat_emission[0] = m[0];
00160         mat_emission[1] = m[1];
00161         mat_emission[2] = m[2];
00162         mat_emission[3] = m[3];
00163     }
00164     inline void SetAmbient   ( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
00165     {
00166         mat_ambient[0] = r;
00167         mat_ambient[1] = g;
00168         mat_ambient[2] = b;
00169         mat_ambient[3] = a;
00170     }
00171     inline void SetDiffuse   ( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
00172     {
00173         mat_diffuse[0] = r;
00174         mat_diffuse[1] = g;
00175         mat_diffuse[2] = b;
00176         mat_diffuse[3] = a;
00177     }
00178     inline void SetSpecular  ( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
00179     {
00180         mat_specular[0] = r;
00181         mat_specular[1] = g;
00182         mat_specular[2] = b;
00183         mat_specular[3] = a;
00184     }
00185     inline void SetShininess ( GLfloat s )
00186     {
00187         mat_shininess[0] = s;
00188     }
00189     inline void SetEmission  ( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
00190     {
00191         mat_emission[0] = r;
00192         mat_emission[1] = g;
00193         mat_emission[2] = b;
00194         mat_emission[3] = a;
00195     }
00196     inline void SetAllMat ( GLfloat const ma[],     // ambient
00197                             GLfloat const md[],     // diffuse
00198                             GLfloat const ms[],     // specular
00199                             GLfloat const s[],      // shininess
00200                             GLfloat const me[]      // emission
00201                           )
00202     {
00203         SetAmbient( ma );
00204         SetDiffuse( md );
00205         SetSpecular( ms );
00206         SetShininess( s );
00207         SetEmission( me );
00208     }
00209     inline void SetAllMat ( GLfloat const ma[],     // ambient
00210                             GLfloat const md[],     // diffuse
00211                             GLfloat const ms[],     // specular
00212                             GLfloat s,              // shininess
00213                             GLfloat const me[]      // emission
00214                           )
00215     {
00216         SetAmbient( ma );
00217         SetDiffuse( md );
00218         SetSpecular( ms );
00219         SetShininess( s );
00220         SetEmission( me );
00221     }
00222 
00224     inline void SetToTheRGBAColor ( 
00225         bool ambient = true, 
00226         bool diffuse = true, 
00227         bool specular = false, 
00228         bool emission = false, 
00229         Vector4<GLfloat> vScale = Vector4<GLfloat>(1,1,1,1)
00230     ) {
00231         GLfloat RGBA[4] = { color_RGBA[0]*vScale[0], color_RGBA[1]*vScale[1], color_RGBA[2]*vScale[2], color_RGBA[3]*vScale[3] };
00232         if ( ambient )  SetAmbient(  RGBA );
00233         if ( diffuse )  SetDiffuse(  RGBA );
00234         if ( specular ) SetSpecular( RGBA );
00235         if ( emission ) SetEmission( RGBA );
00236     }
00237     //---------------------------------------------------------------
00238     inline void GetAmbient   ( GLfloat m[4] ) const
00239     {
00240         m[0] = mat_ambient[0];
00241         m[1] = mat_ambient[1];
00242         m[2] = mat_ambient[2];
00243         m[3] = mat_ambient[3];
00244     }
00245     inline void GetDiffuse   ( GLfloat m[4] ) const
00246     {
00247         m[0] = mat_diffuse[0];
00248         m[1] = mat_diffuse[1];
00249         m[2] = mat_diffuse[2];
00250         m[3] = mat_diffuse[3];
00251     }
00252     inline void GetSpecular  ( GLfloat m[4] ) const
00253     {
00254         m[0] = mat_specular[0];
00255         m[1] = mat_specular[1];
00256         m[2] = mat_specular[2];
00257         m[3] = mat_specular[3];
00258     }
00259     inline void GetShininess ( GLfloat m[1] ) const
00260     {   m[0] = mat_shininess[0];    }
00261     inline void GetEmission  ( GLfloat m[4] ) const
00262     {
00263         m[0] = mat_emission[0];
00264         m[1] = mat_emission[1];
00265         m[2] = mat_emission[2];
00266         m[3] = mat_emission[3];
00267     }
00268     inline GLfloat GetAmbient   ( int i )   { return mat_ambient[i]; }
00269     inline GLfloat GetDiffuse   ( int i )   { return mat_diffuse[i]; }
00270     inline GLfloat GetSpecular  ( int i )   { return mat_specular[i]; }
00271     inline GLfloat GetShininess ()          { return mat_shininess[0]; }
00272     inline GLfloat GetEmission  ( int i )   { return mat_emission[i]; }
00273     //---------------------------------------------------------------
00274     inline void SetAmbient   ( int i, GLfloat m ) { mat_ambient[i] = m; }
00275     inline void SetDiffuse   ( int i, GLfloat m ) { mat_diffuse[i] = m; }
00276     inline void SetSpecular  ( int i, GLfloat m ) { mat_specular[i] = m; }
00277     inline void SetEmission  ( int i, GLfloat m ) { mat_emission[i] = m; }
00278     //---------------------------------------------------------------
00279     // Color RGBA
00280     inline void SetColorRGBA ( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
00281     {
00282         color_RGBA[0] = red;
00283         color_RGBA[1] = green;
00284         color_RGBA[2] = blue;
00285         color_RGBA[3] = alpha;
00286     }
00287     inline void SetColorRGB  ( GLfloat red, GLfloat green, GLfloat blue )
00288     {
00289         color_RGBA[0] = red;
00290         color_RGBA[1] = green;
00291         color_RGBA[2] = blue;
00292     }
00293     inline void GetColorRGBA ( GLfloat & red, GLfloat & green, GLfloat & blue, GLfloat & alpha ) const
00294     {
00295         red   = color_RGBA[0];
00296         green = color_RGBA[1];
00297         blue  = color_RGBA[2];
00298         alpha = color_RGBA[3];
00299     }
00300     inline void GetColorRGB  ( GLfloat & red, GLfloat & green, GLfloat & blue ) const
00301     {
00302         red   = color_RGBA[0];
00303         green = color_RGBA[1];
00304         blue  = color_RGBA[2];
00305     }
00306     inline void SetColorRGBA ( const GLfloat c[4] )
00307     {
00308         color_RGBA[0] = c[0];
00309         color_RGBA[1] = c[1];
00310         color_RGBA[2] = c[2];
00311         color_RGBA[3] = c[3];
00312     }
00313     inline void SetColorRGB  ( const GLfloat c[3] )
00314     {
00315         color_RGBA[0] = c[0];
00316         color_RGBA[1] = c[1];
00317         color_RGBA[2] = c[2];
00318     }
00319     inline void GetColorRGBA ( GLfloat c[4] ) const
00320     {
00321         c[0] = color_RGBA[0];
00322         c[1] = color_RGBA[1];
00323         c[2] = color_RGBA[2];
00324         c[3] = color_RGBA[3];
00325     }
00326     inline void GetColorRGB  ( GLfloat c[3] ) const
00327     {
00328         c[0] = color_RGBA[0];
00329         c[1] = color_RGBA[1];
00330         c[2] = color_RGBA[2];
00331     }
00332     //---------------------------------------------------------------
00333     void SetMaterial( Enum::MaterialType = Enum::METAL_SILVER );
00334     //---------------------------------------------------------------
00335 }; // end class Material
00336 //=============================================================================
00337 END_NAMESPACE_TAPs__OpenGL
00338 //-----------------------------------------------------------------------------
00339 // Include definition if TAPs_USE_EXPORT is not defined
00340 #if !defined( TAPs_USE_EXPORT )
00341     #include "TAPsOpenGLMaterial.cpp"
00342 #endif
00343 //-----------------------------------------------------------------------------
00344 #endif
00345 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00346 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines