basic/opengl/GL_Material.cpp

Go to the documentation of this file.
00001 //## begin module%373B17C102DE.cm preserve=no
00002 //        %X% %Q% %Z% %W%
00003 //## end module%373B17C102DE.cm
00004 
00005 //## begin module%373B17C102DE.cp preserve=no
00006 //## end module%373B17C102DE.cp
00007 
00008 //## Module: GL_Material%373B17C102DE; Pseudo Package body
00009 //## Source file: C:\project\mpk\code\OpenGL\GL_Material.cpp
00010 
00011 //## begin module%373B17C102DE.additionalIncludes preserve=no
00012 //## end module%373B17C102DE.additionalIncludes
00013 
00014 //## begin module%373B17C102DE.includes preserve=yes
00015 #include <assert.h>
00016 #include "glos.h"
00017 #include <gl/gl.h>
00018 //## end module%373B17C102DE.includes
00019 
00020 // GL_Material
00021 #include "OpenGL\GL_Material.h"
00022 //## begin module%373B17C102DE.additionalDeclarations preserve=yes
00023 GL_Material GL_Material::matGrayPlastic;
00024 //## end module%373B17C102DE.additionalDeclarations
00025 
00026 
00027 // Class GL_Material 
00028 
00029 
00030 
00031 
00032 
00033 
00034 //## begin GL_Material::matRedPlastic%373B23B9012B.role preserve=no  public: static GL_Material { -> 1VFHAN}
00035 GL_Material GL_Material::matRedPlastic;
00036 //## end GL_Material::matRedPlastic%373B23B9012B.role
00037 
00038 
00039 //## begin GL_Material::matGreenPlastic%373B25880069.role preserve=no  public: static GL_Material { -> 1VFHAN}
00040 GL_Material GL_Material::matGreenPlastic;
00041 //## end GL_Material::matGreenPlastic%373B25880069.role
00042 
00043 
00044 GL_Material::GL_Material ()
00045   //## begin GL_Material::GL_Material%926619736.hasinit preserve=no
00046   //## end GL_Material::GL_Material%926619736.hasinit
00047   //## begin GL_Material::GL_Material%926619736.initialization preserve=yes
00048   :shininess( 10 )
00049   //## end GL_Material::GL_Material%926619736.initialization
00050 {
00051   //## begin GL_Material::GL_Material%926619736.body preserve=yes
00052         ambient[ 0 ] = static_cast< float>( 0.1 );
00053         ambient[ 1 ] = static_cast< float>( 0.1 );
00054         ambient[ 2 ] = static_cast< float>( 0.1 );
00055         ambient[ 3 ] = static_cast< float>( 1 );
00056 
00057         diffuse[ 0 ] = static_cast< float>( 0.5 );
00058         diffuse[ 1 ] = static_cast< float>( 0.5 );
00059         diffuse[ 2 ] = static_cast< float>( 0.5 );
00060         diffuse[ 3 ] = static_cast< float>( 1 );
00061 
00062         specular[ 0 ] = static_cast< float>( 0 );
00063         specular[ 1 ] = static_cast< float>( 0 );
00064         specular[ 2 ] = static_cast< float>( 0 );
00065         specular[ 3 ] = static_cast< float>( 0 );
00066 
00067         emission[ 0 ] = static_cast< float>( 0 );
00068         emission[ 1 ] = static_cast< float>( 0 );
00069         emission[ 2 ] = static_cast< float>( 0 );
00070         emission[ 3 ] = static_cast< float>( 1 );
00071   //## end GL_Material::GL_Material%926619736.body
00072 }
00073 
00074 GL_Material::GL_Material (GL_Material& right)
00075   //## begin GL_Material::GL_Material%926619742.hasinit preserve=no
00076   //## end GL_Material::GL_Material%926619742.hasinit
00077   //## begin GL_Material::GL_Material%926619742.initialization preserve=yes
00078   //## end GL_Material::GL_Material%926619742.initialization
00079 {
00080   //## begin GL_Material::GL_Material%926619742.body preserve=yes
00081         for( int i = 0; i < 4; i ++ )
00082         {
00083                 ambient[ i ] = right.ambient[ i ] ;
00084                 diffuse[ i ] = right.diffuse[ i ] ;
00085                 specular[ i ] = right.specular[ i ] ;
00086                 emission[ i ] = right.emission[ i ] ;
00087                 shininess = right.shininess ;
00088         }
00089   //## end GL_Material::GL_Material%926619742.body
00090 }
00091 
00092 
00093 GL_Material::~GL_Material()
00094 {
00095   //## begin GL_Material::~GL_Material%.body preserve=yes
00096   //## end GL_Material::~GL_Material%.body
00097 }
00098 
00099 
00100 
00101 //## Other Operations (implementation)
00102 void GL_Material::SetAmbient (double r, double g, double b, double a)
00103 {
00104   //## begin GL_Material::SetAmbient%926619734.body preserve=yes
00105         ambient[ 0 ] = static_cast< float >( r ) ;
00106         ambient[ 1 ] = static_cast< float >( g ) ;
00107         ambient[ 2 ] = static_cast< float >( b ) ;
00108         ambient[ 3 ] = static_cast< float >( a ) ;
00109   //## end GL_Material::SetAmbient%926619734.body
00110 }
00111 
00112 void GL_Material::SetDiffuse (double r, double g, double b, double a)
00113 {
00114   //## begin GL_Material::SetDiffuse%926619737.body preserve=yes
00115         diffuse[ 0 ] = static_cast< float >( r ) ;
00116         diffuse[ 1 ] = static_cast< float >( g ) ;
00117         diffuse[ 2 ] = static_cast< float >( b ) ;
00118         diffuse[ 3 ] = static_cast< float >( a ) ;
00119   //## end GL_Material::SetDiffuse%926619737.body
00120 }
00121 
00122 void GL_Material::SetSpecular (double r, double g, double b, double a)
00123 {
00124   //## begin GL_Material::SetSpecular%926619738.body preserve=yes
00125         specular[ 0 ] = static_cast< float >( r );
00126         specular[ 1 ] = static_cast< float >( g );
00127         specular[ 2 ] = static_cast< float >( b );
00128         specular[ 3 ] = static_cast< float >( a );
00129   //## end GL_Material::SetSpecular%926619738.body
00130 }
00131 
00132 void GL_Material::SetShininess (double shininess)
00133 {
00134   //## begin GL_Material::SetShininess%926619739.body preserve=yes
00135         this->shininess = shininess ;
00136   //## end GL_Material::SetShininess%926619739.body
00137 }
00138 
00139 void GL_Material::SetTransparancy (double alpha)
00140 {
00141   //## begin GL_Material::SetTransparancy%926619740.body preserve=yes
00142         //set the alpha values appropriately
00143         ambient[ 3 ] = static_cast< float>( alpha ) ;
00144         diffuse[ 3 ] = static_cast< float>( alpha ) ;
00145         specular[ 3 ] = static_cast< float>( alpha ) ;
00146         emission[ 3 ] = static_cast< float>( alpha ) ;
00147 
00148         //check to see if alpha blending is enabled
00149         if( !glIsEnabled( GL_BLEND ) )
00150         {
00151                 assert( false ) ;  //alpha blending should be enabled, or else this will have no effect
00152                 glEnable(GL_BLEND) ;    
00153         }
00154   //## end GL_Material::SetTransparancy%926619740.body
00155 }
00156 
00157 void GL_Material::SetupGlobalMaterials ()
00158 {
00159   //## begin GL_Material::SetupGlobalMaterials%926619741.body preserve=yes
00160         //this function need only be called once
00161         static bool functionAlreadyCalled = false ;
00162         if( functionAlreadyCalled )
00163         {
00164 //              return ;        //IMPROVE: this should not be called twice.
00165         }
00166         matRedPlastic.SetDiffuse( 0.8, 0, 0 ) ;
00167         matRedPlastic.SetAmbient( 0.2, 0, 0 ) ;
00168         matGreenPlastic.SetDiffuse( 0, 0.8, 0 ) ;
00169         matGreenPlastic.SetAmbient( 0, 0.2, 0 ) ;
00170         matRedPlastic.SetDiffuse( 0.8, 0.8, 0.8 ) ;
00171         matRedPlastic.SetAmbient( 0.2, 0.0, 0.0 ) ;
00172         functionAlreadyCalled = true ;
00173   //## end GL_Material::SetupGlobalMaterials%926619741.body
00174 }
00175 
00176 GL_Material& GL_Material::operator = (const GL_Material& right)
00177 {
00178   //## begin GL_Material::operator=%926619743.body preserve=yes
00179         if( this == &right )
00180         {
00181                 return *this ;
00182         }
00183         for( int i = 0; i < 4; i ++ )
00184         {
00185                 ambient[ i ] = right.ambient[ i ] ;
00186                 diffuse[ i ] = right.diffuse[ i ] ;
00187                 specular[ i ] = right.specular[ i ] ;
00188                 emission[ i ] = right.emission[ i ] ;
00189                 shininess = right.shininess ;
00190         }
00191         return *this ;
00192   //## end GL_Material::operator=%926619743.body
00193 }
00194 
00195 bool GL_Material::DrawExplicit () const
00196 {
00197   //## begin GL_Material::DrawExplicit%950474928.body preserve=yes
00198         glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,ambient);
00199         glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,diffuse);
00200         glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,specular);
00201         glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emission);
00202         glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS, static_cast< float >( shininess ));
00203         return true ;
00204   //## end GL_Material::DrawExplicit%950474928.body
00205 }
00206 
00207 // Additional Declarations
00208   //## begin GL_Material%373B17C102DE.declarations preserve=yes
00209 void GL_Material::GLDraw() const
00210 {
00211         GL_Material::DrawExplicit() ;
00212 }
00213   //## end GL_Material%373B17C102DE.declarations
00214 
00215 //## begin module%373B17C102DE.epilog preserve=yes
00216 //## end module%373B17C102DE.epilog
00217 
00218 
00219 // Detached code regions:
00220 // WARNING: this code will be lost if code is regenerated.
00221 #if 0
00222 //## begin GL_Material::DrawExplicit%926619735.body preserve=no
00223 //## end GL_Material::DrawExplicit%926619735.body
00224 
00225 #endif

Generated on Sat Apr 1 21:30:35 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO