00001 #ifndef OPENTISSUE_UTILITY_UTILITY_MATERIAL_H 00002 #define OPENTISSUE_UTILITY_UTILITY_MATERIAL_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 namespace OpenTissue 00013 { 00014 namespace utility 00015 { 00016 00021 class Material 00022 { 00023 protected: 00024 00025 float m_ambient[ 4 ]; 00026 float m_diffuse[ 4 ]; 00027 float m_specular[ 4 ]; 00028 float m_shininess; 00029 00030 public: 00031 00032 Material() 00033 : m_shininess(128) 00034 { 00035 set_default(); 00036 } 00037 00038 void ambient( float const & red, float const & green, float const & blue, float const & alpha = 1.0f ) 00039 { 00040 m_ambient[ 0 ] = red; 00041 m_ambient[ 1 ] = green; 00042 m_ambient[ 2 ] = blue; 00043 m_ambient[ 3 ] = alpha; 00044 } 00045 00046 void diffuse( float const & red, float const & green, float const & blue, float const & alpha = 1.0f ) 00047 { 00048 m_diffuse[ 0 ] = red; 00049 m_diffuse[ 1 ] = green; 00050 m_diffuse[ 2 ] = blue; 00051 m_diffuse[ 3 ] = alpha; 00052 } 00053 00054 void specular( float const & red, float const & green, float const & blue, float const & alpha = 1.0f ) 00055 { 00056 m_specular[ 0 ] = red; 00057 m_specular[ 1 ] = green; 00058 m_specular[ 2 ] = blue; 00059 m_specular[ 3 ] = alpha; 00060 } 00061 00062 void shininess( float const & value ) 00063 { 00064 m_shininess = value; 00065 } 00066 00067 /* 00068 void use() 00069 { 00070 if ( glIsEnabled( GL_COLOR_MATERIAL ) || !glIsEnabled( GL_LIGHTING ) ) 00071 { 00072 glColor4f( m_diffuse[ 0 ], m_diffuse[ 1 ], m_diffuse[ 2 ], m_diffuse[ 3 ] ); 00073 } 00074 else 00075 { 00076 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, m_ambient ); 00077 glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, m_diffuse ); 00078 glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, m_specular ); 00079 glMaterialfv( GL_FRONT_AND_BACK, GL_SHININESS, &m_shininess ); 00080 } 00081 } 00082 */ 00083 00084 void set_default() 00085 { 00086 m_ambient[ 0 ] = 0.1f; 00087 m_ambient[ 1 ] = 0.1f; 00088 m_ambient[ 2 ] = 0.0f; 00089 m_ambient[ 3 ] = 1.0f; 00090 m_diffuse[ 0 ] = 0.6f; 00091 m_diffuse[ 1 ] = 0.6f; 00092 m_diffuse[ 2 ] = 0.1f; 00093 m_diffuse[ 3 ] = 1.0f; 00094 m_specular[ 0 ] = 1.0f; 00095 m_specular[ 1 ] = 1.0f; 00096 m_specular[ 2 ] = 0.75f; 00097 m_specular[ 3 ] = 1.0f; 00098 m_shininess = 128; 00099 } 00100 00101 }; 00102 00103 } // namespace utility 00104 00105 } // namespace OpenTissue 00106 00107 //OPENTISSUE_UTILITY_UTILITY_MATERIAL_H 00108 #endif