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