basic/geometry/vrml_reader/VrmlMaterial.cpp

Go to the documentation of this file.
00001 #pragma warning ( disable : 4786 )
00002 
00003 #include <assert.h>
00004 #include <math/vector4.h>
00005 #include "../IGS/IGS_Material.h"
00006 #ifndef NOGL
00007 #include "opengl/glos.h"
00008 #include <gl/gl.h>
00009 #endif
00010 #include <stdio.h>
00011 #include "utility.h"
00012 #include "VrmlMaterial.h"
00013 #include "VrmlStack.h"
00014 
00015 //=============================================================================
00016 // Constructor
00017 //
00018 // Description: Constructor
00019 //=============================================================================
00020 VrmlMaterial::VrmlMaterial()
00021 {
00022 }
00023 
00024 //=============================================================================
00025 // Parse
00026 //
00027 // Description: Parses the node from the file
00028 //=============================================================================
00029 void VrmlMaterial::Parse( char*& buffer )
00030 {
00031         EatWhite( buffer );
00032         while( buffer[ 0 ] != '}' )
00033         {
00034                 Keyword keyword = VrmlNode::GetKeyword( buffer );
00035                 EatWhite( buffer );
00036                 if( buffer[ 0 ] == '[' )
00037                 {
00038                         buffer++;
00039                         EatWhite( buffer );
00040                 }
00041 
00042                 switch( keyword )
00043                 {
00044                 case VRML_AmbientColor:
00045                         {
00046                                 //read in 3 floating point numbers
00047                                 int result;
00048                                 result = sscanf( buffer, "%f%f%f", &m_Ambient[ 0 ], &m_Ambient[ 1 ], &m_Ambient[ 2 ] );
00049                                 assert( result == 3 );
00050                                 m_Ambient[ 3 ] = 1.0f;
00051 
00052                                 //advance to the end of the line
00053                                 while( buffer[ 0 ] != '\n' )
00054                                 {
00055                                         buffer++;
00056                                 }
00057                                 break;
00058                         }
00059                 case VRML_AmbientIntensity:
00060                         {
00061                                 //advance to the end of the line
00062                                 while( buffer[ 0 ] != '\n' )
00063                                 {
00064                                         buffer++;
00065                                 }
00066                                 break;
00067                         }
00068                 case VRML_DiffuseColor:
00069                         {
00070                                 //read in 3 floating point numbers
00071                                 int result;
00072                                 result = sscanf( buffer, "%f%f%f", &m_Diffuse[ 0 ], &m_Diffuse[ 1 ], &m_Diffuse[ 2 ] );
00073                                 assert( result == 3 );
00074                                 m_Diffuse[ 3 ] = 1.0f;
00075 
00076                                 //advance to the end of the line
00077                                 while( buffer[ 0 ] != '\n' )
00078                                 {
00079                                         buffer++;
00080                                 }
00081                                 break;
00082                         }
00083                 case VRML_EmissiveColor:
00084                         {
00085                                 //read in 3 floating point numbers
00086                                 int result;
00087                                 result = sscanf( buffer, "%f%f%f", &m_Emissive[ 0 ], &m_Emissive[ 1 ], &m_Emissive[ 2 ] );
00088                                 assert( result == 3 );
00089                                 m_Emissive[ 3 ] = 1.0f;
00090 
00091                                 //advance over 3 fields
00092                                 EatWhite( buffer );
00093                 EatNotWhite( buffer );
00094                                 EatWhite( buffer );
00095                 EatNotWhite( buffer );
00096                                 EatWhite( buffer );
00097                 EatNotWhite( buffer );
00098                                 break;
00099                         }
00100                 case VRML_SpecularColor:
00101                         {
00102                                 //read in 3 floating point numbers
00103                                 int result;
00104                                 result = sscanf( buffer, "%f%f%f", &m_Specular[ 0 ], &m_Specular[ 1 ], &m_Specular[ 2 ] );
00105                                 assert( result == 3 );
00106                                 m_Specular[ 3 ] = 1.0f;
00107 
00108                                 //advance to the end of the line
00109                                 while( buffer[ 0 ] != '\n' )
00110                                 {
00111                                         buffer++;
00112                                 }
00113                                 break;
00114                         }
00115                 case VRML_Shininess:
00116                         {
00117                                 //read in 1 floating point numbers
00118                                 int result;
00119                                 result = sscanf( buffer, "%f", &m_Shininess );
00120                                 assert( result == 1 );
00121 
00122                                 //advance to the end of the line
00123                                 while( buffer[ 0 ] != '\n' )
00124                                 {
00125                                         buffer++;
00126                                 }
00127                                 break;
00128                         }
00129                 case VRML_Transparency:
00130                         {
00131                                 //advance to the end of the line
00132                                 while( buffer[ 0 ] != '\n' )
00133                                 {
00134                                         buffer++;
00135                                 }
00136                                 break;
00137                         }
00138                 default:
00139                         {
00140                                 //advance to the end of the line
00141                                 while( buffer[ 0 ] != '\n' )
00142                                 {
00143                                         buffer++;
00144                                 }
00145                                 assert( false );
00146                                 break;
00147                         }
00148                 }
00149                 EatWhite( buffer );
00150                 if( buffer[ 0 ] == ',' )
00151                 {
00152                         buffer++;
00153                 }
00154                 EatWhite( buffer );
00155                 if( buffer[ 0 ] == ']' )
00156                 {
00157                         buffer++;
00158                 }
00159                 EatWhite( buffer );
00160         }
00161         buffer++;
00162 }
00163 
00164 //=============================================================================
00165 // Render
00166 //
00167 // Description: renders the object to the stack
00168 //=============================================================================
00169 void VrmlMaterial::Render( VrmlStack& stack ) const
00170 {
00171         stack.m_Ambient = IGS_Color( m_Ambient[ 0 ], m_Ambient[ 1 ], m_Ambient[ 2 ] );
00172         stack.m_Diffuse = IGS_Color( m_Diffuse[ 0 ], m_Diffuse[ 1 ], m_Diffuse[ 2 ] );
00173         stack.m_Specular = IGS_Color( m_Specular[ 0 ], m_Specular[ 1 ], m_Specular[ 2 ] );
00174         stack.m_Emissive = IGS_Color( m_Emissive[ 0 ], m_Emissive[ 1 ], m_Emissive[ 2 ] );
00175         stack.m_Shininess = m_Shininess;
00176 }
00177 
00178 //=============================================================================
00179 // RenderOpenGl
00180 //
00181 // Description: Renders the object to OpenGl
00182 //=============================================================================
00183 void VrmlMaterial::RenderOpenGl( VrmlStack& stack ) const
00184 {
00185 #ifndef NOGL
00186         ::glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, this->m_Ambient );
00187         ::glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, this->m_Diffuse );
00188         ::glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, this->m_Specular );
00189         ::glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, this->m_Emissive );
00190 #endif
00191         //assert( false );
00192 }
00193 
00194 //=============================================================================
00195 // RenderToIGS
00196 //
00197 // Description: Renders the object to the IGS subsystem
00198 //=============================================================================
00199 IGS_Object* VrmlMaterial::RenderToIGS( VrmlStack& stack ) const
00200 {
00201         IGS_Material* returnMe = new IGS_Material;
00202         return returnMe;
00203 }
00204 

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