TAPs 0.7.7.3
TAPsOpenGLTrigonalModel.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsOpenGLTrigonalModel.cpp
00003 
00004 Class OpenGLTrigonalModel is for creating an OpenGL Triangulated Model.
00005 
00006 See class TrigonalModel (in "../Model/TAPsTrigonalModel.hpp") and
00007 class OpenGLSupport ("../OpenGL/TAPsOpenGLSupport.hpp") for detail.
00008 
00009 SUKITTI PUNAK   (24/03/2005)
00010 UPDATE          (24/03/2005)
00011 ******************************************************************************/
00012 #include "TAPsOpenGLTrigonalModel.hpp"
00013 // Using Inclusion Model (i.e. definitions are included in declarations)
00014 //                       (this name.cpp is included in name.hpp)
00015 // Each friend is defined directly inside its declaration.
00016 
00017 BEGIN_NAMESPACE_TAPs__OpenGL
00018 //=============================================================================
00019 //-----------------------------------------------------------------------------
00020 // default constructor
00021 template <typename T>
00022 OpenGLTrigonalModel<T>::OpenGLTrigonalModel()
00023     : TrigonalModel<T>()
00024 {
00025     #ifdef  TAPs_DEBUG_MODE
00026     std::cout << "OpenGLTrigonalModel<" << typeid(T).name() << "> constructor\n";
00027     #endif//TAPs_DEBUG_MODE
00028 }
00029 //-----------------------------------------------------------------------------
00030 // destructor
00031 template <typename T>
00032 OpenGLTrigonalModel<T>::~OpenGLTrigonalModel()
00033 {
00034     #ifdef  TAPs_DEBUG_MODE
00035     std::cout << "OpenGLTrigonalModel<" << typeid(T).name() << "> destructor\n";
00036     #endif//TAPs_DEBUG_MODE
00037 }
00038 /*
00039 //-----------------------------------------------------------------------------
00040 //void DisplayGL()
00041 template <typename T>
00042 void OpenGLTrigonalModel<T>::DisplayGL( OpenGL::Enum::DrawMode DM )
00043 {
00044     switch (DM) {
00045     case OpenGL::Enum::POLYGON:
00046         DrawGL( GL_POLYGON );
00047         break;
00048     case OpenGL::Enum::WIRE_FRAME:
00049         DrawGL( GL_LINE_LOOP );
00050         break;
00051     case OpenGL::Enum::POINT:
00052         DrawGL( GL_POINTS );
00053         break;
00054     case OpenGL::Enum:: POLYGON_WITH_WIRE_FRAME:
00055         // Draw the object with GL_POLYGON_OFFSET enabled
00056         glEnable( GL_POLYGON_OFFSET_FILL );
00057         glPolygonOffset( 1.0, 1.0 );
00058         DrawGL( GL_POLYGON );
00059         glDisable( GL_POLYGON_OFFSET_FILL );
00060         // Draw the wire frame of the object
00061         glDisable( GL_LIGHTING );
00062         //glDisable( GL_DEPTH_TEST );
00063         glColor3ub( 255, 200, 0 );
00064         DrawGL( GL_LINE_LOOP );
00065         glEnable( GL_LIGHTING );
00066         //glEnable( GL_DEPTH_TEST );
00067         break;
00068     }
00069 }
00070 //*/
00071 //-----------------------------------------------------------------------------
00072 // Helper Fn
00073 // void DrawGL()
00074 template <typename T>
00075 void OpenGLTrigonalModel<T>::DrawGL( GLenum drawMode )
00076 {
00077     if ( isFacetShading ) {
00078         // Draw the object
00079         //glEnable( GL_TEXTURE_2D );
00080         for ( int i = 0; i < m_iNoFaces; ++i )
00081         {
00082             glBegin( drawMode );
00083             for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j )
00084             {
00085                 // Draw texture
00086                 if ( m_prFace[i].GetNoTexCoords() != 0 ) {
00087                     glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 
00088                                 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) );
00089                 }
00090                 // Normal of the face
00091                 glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 
00092                              static_cast<float>( m_prFace[i].GetNormal()[1] ), 
00093                              static_cast<float>( m_prFace[i].GetNormal()[2] ) );
00094                 // Draw the vertex
00095                 glVertex3f ( 
00096                     static_cast<float>( m_prVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 
00097                     static_cast<float>( m_prVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 
00098                     static_cast<float>( m_prVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) );
00099             }
00100             glEnd();
00101         }
00102         //glDisable( GL_TEXTURE_2D );
00103     }
00104     else {
00105         // Draw the object
00106         //glEnable( GL_TEXTURE_2D );
00107         for ( int i = 0; i < m_iNoFaces; i++ )
00108         {
00109             glBegin( drawMode );
00110 
00111             // Normal of the face
00112             glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 
00113                          static_cast<float>( m_prFace[i].GetNormal()[1] ), 
00114                          static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 
00115 
00116             for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j )
00117             {
00118                 // Draw texture
00119                 if ( m_prFace[i].GetNoTexCoords() != 0 ) {
00120                     glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 
00121                                 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) );
00122                 }
00123 
00124                 // FIX THIS
00125                 // Normal of the vertex
00126                 //glNormal3f ( static_cast<float>( m_prVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 
00127                 //           static_cast<float>( m_prVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 
00128                 //           static_cast<float>( m_prVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 
00129                 
00130                 // Draw the vertex
00131                 glVertex3f ( 
00132                     static_cast<float>( m_prVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 
00133                     static_cast<float>( m_prVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 
00134                     static_cast<float>( m_prVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) );
00135             }
00136             glEnd();
00137         }
00138         //glDisable( GL_TEXTURE_2D );
00139     }
00140 }
00141 //-----------------------------------------------------------------------------
00142 //=============================================================================
00143 END_NAMESPACE_TAPs__OpenGL
00144 //-----------------------------------------------------------------------------
00145 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00146 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines