TAPs 0.7.7.3
TAPsOpenGLPNTriangleModel.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsOpenGLPNTriangleModel.cpp
00003 
00004 (X <==> Extra)
00005 Class TAPsOpenGLPNTriangleModel is for creating an OpenGL PN-Triangle Model.
00006 
00007 See class XTrigonalModel (in "../Model/TAPsXTrigonalModel.hpp") and
00008 class OpenGLSupport ("../OpenGL/TAPsOpenGLSupport.hpp") for detail.
00009 
00010 SUKITTI PUNAK   (03/25/2005)
00011 UPDATE          (05/29/2005)
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 OpenGLPNTriangleModel<T>::OpenGLPNTriangleModel()
00024     : XTrigonalModel<T>()
00025 {
00026     #ifdef  TAPs_DEBUG_MODE
00027     std::cout << "OpenGLPNTriangleModel<" << typeid(T).name() << "> constructor\n";
00028     #endif//TAPs_DEBUG_MODE
00029 }
00030 //-----------------------------------------------------------------------------
00031 // destructor
00032 template <typename T>
00033 OpenGLPNTriangleModel<T>::~OpenGLPNTriangleModel()
00034 {
00035     if ( m_prPNTriCoef != NULL ) delete [] m_prPNTriCoef;
00036     if ( m_prPNTriNormal != NULL ) delete [] m_prPNTriNormal;
00037 
00038     #ifdef  TAPs_DEBUG_MODE
00039     std::cout << "OpenGLPNTriangleModel<" << typeid(T).name() << "> destructor\n";
00040     #endif//TAPs_DEBUG_MODE
00041 }
00042 //-----------------------------------------------------------------------------
00043 // Initialize
00044 template <typename T>
00045 void OpenGLPNTriangleModel<T>::Initialize ()
00046 {
00047     XPolygonalModel<T>::Initialize();
00048     CreateAndCalPNTriangles();
00049 }
00050 //-----------------------------------------------------------------------------
00051 // (Helper Fn) CreateAndCalPNTriangles
00052 template <typename T>
00053 void OpenGLPNTriangleModel<T>::CreateAndCalPNTriangles () {
00054     if ( !AllocatePNTriangleCoefficients() ) exit(1);
00055     if ( !AllocatePNTriangleNormals() )  exit(1);
00056     InitializePNTriangleCoefficients();
00057     InitializePNTriangleNormals();
00058     CalculatePNTriangleCoefficients();
00059     CalculatePNTriangleNormals();
00060 }
00061 //-----------------------------------------------------------------------------
00062 // (Helper Fn) AllocatePNTriangleCoefficients
00063 template <typename T>
00064 bool OpenGLPNTriangleModel<T>::AllocatePNTriangleCoefficients () {
00065     m_prPNTriCoef = new float[GetNoFaces()*10*3];
00066     if ( m_prPNTriCoef ) return true;
00067     return false;
00068 }
00069 //-----------------------------------------------------------------------------
00070 // (Helper Fn) AllocatePNTriangleNormals
00071 template <typename T>
00072 bool OpenGLPNTriangleModel<T>::AllocatePNTriangleNormals () {
00073     m_prPNTriNormal = new float[GetNoFaces()*6*3];
00074     if ( m_prPNTriNormal ) return true;
00075     return false;
00076 }
00077 //-----------------------------------------------------------------------------
00078 // (Helper Fn) InitializePNTriangleCoefficients
00079 template <typename T>
00080 void OpenGLPNTriangleModel<T>::InitializePNTriangleCoefficients () {
00081     // Coefficients or Control Points
00082     //                    b003                              9
00083     //                    /  \
00084     //                  /      \
00085     //               b102      b012                       7   8
00086     //              /              \           <===>    
00087     //            /                  \
00088     //         b201       b111       b021               4   5  6
00089     //        /                          \
00090     //      /                              \
00091     //     b300 ---- b210 ---- b120 ---- b030          0  1  2  3
00092     int b = 0;
00093     Vector3<T> *P1, *P2, *P3;
00094     for ( int f = 0; f < GetNoFaces(); ++f, b+=30 ) {
00095         // Initialize b300, b030, and b003
00096         P1 = &m_prXVertex[ m_prFace[f].GetVertexNo(0) ].GetPosition();
00097         P2 = &m_prXVertex[ m_prFace[f].GetVertexNo(1) ].GetPosition();
00098         P3 = &m_prXVertex[ m_prFace[f].GetVertexNo(2) ].GetPosition();
00099         for ( int i = 0; i < 3; ++i ) {
00100             *(m_prPNTriCoef+b+i)    = (*P1)[i];     // b300
00101             *(m_prPNTriCoef+b+9+i)  = (*P2)[i];     // b030
00102             *(m_prPNTriCoef+b+27+i) = (*P3)[i];     // b003
00103         }
00104     }
00105 }
00106 //-----------------------------------------------------------------------------
00107 // (Helper Fn) InitializePNTriangleNormals
00108 template <typename T>
00109 void OpenGLPNTriangleModel<T>::InitializePNTriangleNormals () {
00110     // Normals
00111     //              n002                        5
00112     //              /  \
00113     //            /      \
00114     //         n101      n011        <===>    3  4
00115     //        /              \
00116     //      /                  \
00117     //    n200 ---- n110 ---- n020          0  1  2
00118     int n = 0;
00119     Vector3<T> *N1, *N2, *N3;
00120     for ( int f = 0; f < GetNoFaces(); ++f, n+=18 ) {
00121         // Initialize n200, n020, and n002
00122         N1 = &m_prXVertex[ m_prFace[f].GetVertexNo(0) ].GetNormal();
00123         N2 = &m_prXVertex[ m_prFace[f].GetVertexNo(1) ].GetNormal();
00124         N3 = &m_prXVertex[ m_prFace[f].GetVertexNo(2) ].GetNormal();
00125         for ( int i = 0; i < 3; ++i ) {
00126             *(m_prPNTriNormal+n+i)    = (*N1)[i];   // n200
00127             *(m_prPNTriNormal+n+6+i)  = (*N2)[i];   // n020
00128             *(m_prPNTriNormal+n+15+i) = (*N3)[i];   // n002
00129         }
00130     }
00131 }
00132 //-----------------------------------------------------------------------------
00133 // (Helper Fn) CalculatePNTriangleVertices
00134 template <typename T>
00135 void OpenGLPNTriangleModel<T>::CalculatePNTriangleCoefficients () {
00136     // Coefficients or Control Points
00137     //                    b003                              9
00138     //                    /  \
00139     //                  /      \
00140     //               b102      b012                       7   8
00141     //              /              \           <===>    
00142     //            /                  \
00143     //         b201       b111       b021               4   5  6
00144     //        /                          \
00145     //      /                              \
00146     //     b300 ---- b210 ---- b120 ---- b030          0  1  2  3
00147     int b = 0;
00148     Vector3<T> *P1, *P2, *P3;
00149     Vector3<T> *N1, *N2, *N3;
00150     Vector3<T> temp, sum;
00151     T w12, w21, w23, w32, w31, w13;
00152     for ( int f = 0; f < GetNoFaces(); ++f ) {
00153         P1 = &m_prXVertex[ m_prFace[f].GetVertexNo(0) ].GetPosition();
00154         P2 = &m_prXVertex[ m_prFace[f].GetVertexNo(1) ].GetPosition();
00155         P3 = &m_prXVertex[ m_prFace[f].GetVertexNo(2) ].GetPosition();
00156         N1 = &m_prXVertex[ m_prFace[f].GetVertexNo(0) ].GetNormal();
00157         N2 = &m_prXVertex[ m_prFace[f].GetVertexNo(1) ].GetNormal();
00158         N3 = &m_prXVertex[ m_prFace[f].GetVertexNo(2) ].GetNormal();
00159         // Calculate w12, w23, and w31
00160         w12 = ( (*P2) - (*P1) ) * (*N1);
00161         w21 = ( (*P1) - (*P2) ) * (*N2);
00162         w23 = ( (*P3) - (*P2) ) * (*N2);
00163         w32 = ( (*P2) - (*P3) ) * (*N3);
00164         w31 = ( (*P1) - (*P3) ) * (*N3);
00165         w13 = ( (*P3) - (*P1) ) * (*N1);
00166         // b210
00167         b += 3;
00168         sum = temp = (2*(*P1) + (*P2) - w12*(*N1)) / 3.0;
00169         *(m_prPNTriCoef+b)   = temp[0];
00170         *(m_prPNTriCoef+b+1) = temp[1];
00171         *(m_prPNTriCoef+b+2) = temp[2];
00172         // b120
00173         b += 3;
00174         sum += temp = (2*(*P2) + (*P1) - w21*(*N2)) / 3.0;
00175         *(m_prPNTriCoef+b)   = temp[0];
00176         *(m_prPNTriCoef+b+1) = temp[1];
00177         *(m_prPNTriCoef+b+2) = temp[2];
00178         // b021
00179         b += 12;
00180         sum += temp = (2*(*P2) + (*P3) - w23*(*N2)) / 3.0;
00181         *(m_prPNTriCoef+b)   = temp[0];
00182         *(m_prPNTriCoef+b+1) = temp[1];
00183         *(m_prPNTriCoef+b+2) = temp[2];
00184         // b012
00185         b += 6;
00186         sum += temp = (2*(*P3) + (*P2) - w32*(*N3)) / 3.0;
00187         *(m_prPNTriCoef+b)   = temp[0];
00188         *(m_prPNTriCoef+b+1) = temp[1];
00189         *(m_prPNTriCoef+b+2) = temp[2];
00190         // b102
00191         b -= 3;
00192         sum += temp = (2*(*P3) + (*P1) - w31*(*N3)) / 3.0;
00193         *(m_prPNTriCoef+b)   = temp[0];
00194         *(m_prPNTriCoef+b+1) = temp[1];
00195         *(m_prPNTriCoef+b+2) = temp[2];
00196         // b201
00197         b -= 9;
00198         sum += temp = (2*(*P1) + (*P3) - w13*(*N1)) / 3.0;
00199         *(m_prPNTriCoef+b)   = temp[0];
00200         *(m_prPNTriCoef+b+1) = temp[1];
00201         *(m_prPNTriCoef+b+2) = temp[2];
00202         // b111
00203         b += 3;
00204         sum /= 6.0;
00205         temp = (*P1 + *P2 + *P3) / 3.0;
00206         temp = sum + (sum - temp) / 2.0;
00207         *(m_prPNTriCoef+b)   = temp[0];
00208         *(m_prPNTriCoef+b+1) = temp[1];
00209         *(m_prPNTriCoef+b+2) = temp[2];
00210 
00211         b += 15;    // update b index
00212     }
00213 }
00214 //-----------------------------------------------------------------------------
00215 // (Helper Fn) CalculatePNTriangleNormals
00216 template <typename T>
00217 void OpenGLPNTriangleModel<T>::CalculatePNTriangleNormals () {
00218     // Normals
00219     //              n002                        5
00220     //              /  \
00221     //            /      \
00222     //         n101      n011        <===>    3  4
00223     //        /              \
00224     //      /                  \
00225     //    n200 ---- n110 ---- n020          0  1  2
00226     int n = 0;
00227     Vector3<T> *P1, *P2, *P3;
00228     Vector3<T> *N1, *N2, *N3;
00229     Vector3<T> temp;
00230     T v12, v23, v31;
00231     for ( int f = 0; f < GetNoFaces(); ++f ) {
00232         P1 = &m_prXVertex[ m_prFace[f].GetVertexNo(0) ].GetPosition();
00233         P2 = &m_prXVertex[ m_prFace[f].GetVertexNo(1) ].GetPosition();
00234         P3 = &m_prXVertex[ m_prFace[f].GetVertexNo(2) ].GetPosition();
00235         N1 = &m_prXVertex[ m_prFace[f].GetVertexNo(0) ].GetNormal();
00236         N2 = &m_prXVertex[ m_prFace[f].GetVertexNo(1) ].GetNormal();
00237         N3 = &m_prXVertex[ m_prFace[f].GetVertexNo(2) ].GetNormal();
00238         //cout << *N1 << " " << *N2 << " " << *N3 << endl;
00239         Vector3<T> p12(*P2 - *P1);
00240         Vector3<T> p23(*P3 - *P2);
00241         Vector3<T> p31(*P1 - *P3);
00242         Vector3<T> n12(*N2 + *N1);
00243         Vector3<T> n23(*N3 + *N2);
00244         Vector3<T> n31(*N1 + *N3);
00245         v12 = 2.0 * (p12 * n12) / (p12 * p12);
00246         v23 = 2.0 * (p23 * n23) / (p23 * p23);
00247         v31 = 2.0 * (p31 * n31) / (p31 * p31);
00248         // n110
00249         temp = (n12 - v12*p12).Normalized();
00250         n += 3;
00251         *(m_prPNTriNormal+n)   = temp[0];
00252         *(m_prPNTriNormal+n+1) = temp[1];
00253         *(m_prPNTriNormal+n+2) = temp[2];
00254         // n101
00255         temp = (n23 - v23*p23).Normalized();
00256         n += 6;
00257         *(m_prPNTriNormal+n)   = temp[0];
00258         *(m_prPNTriNormal+n+1) = temp[1];
00259         *(m_prPNTriNormal+n+2) = temp[2];
00260         // n011
00261         temp = (n31 - v31*p31).Normalized();
00262         n += 3;
00263         *(m_prPNTriNormal+n)   = temp[0];
00264         *(m_prPNTriNormal+n+1) = temp[1];
00265         *(m_prPNTriNormal+n+2) = temp[2];
00266         n += 6; // update n index
00267     }
00268 }
00269 //-----------------------------------------------------------------------------
00270 // (Helper Fn) DrawTriBezierPatchNo
00271 template <typename T>
00272 void OpenGLPNTriangleModel<T>::DrawTriBezierPatchNo(int noOfFaces, int smoothness) {
00273     int noOfVertices = smoothness*(smoothness+1)/2;
00274     float *vertex = new float[noOfVertices*3];
00275     float *normal = new float[noOfVertices*3];
00276     float uInc = 1.0 / (smoothness-1);
00277     float vInc = 1.0 / (smoothness-1);
00278     float uu, vv, ww;
00279     for ( int faceNo = 0; faceNo < noOfFaces; ++faceNo ) {
00280         int index = 0;
00281         float u = 0.0f, v = 0.0f, w;
00282         int bCount = faceNo * 30;
00283         int nCount = faceNo * 18;
00284         float *b = m_prPNTriCoef;
00285         float *n = m_prPNTriNormal;
00286         for ( int i = 0; i < smoothness; ++i, u += uInc ) {
00287             v = 0.0f;
00288             for ( int j = 0; j < smoothness; ++j, v += vInc ) {
00289                 w = 1.0f - u - v;
00290                 if ( w < -0.0000001f ) break;
00291                 ww = w*w;
00292                 uu = u*u;
00293                 vv = v*v;
00294                 T magnitude = 0.0;
00295                 for ( int d = 0; d < 3; ++d, ++index ) {
00296                     vertex[index] =     b[bCount+d]*ww*w + b[bCount+9+d]*uu*u + b[bCount+27+d]*vv*v
00297                                         + 3.0f*(   b[bCount+3+d]*ww*u  + b[bCount+6+d]*w*uu 
00298                                                 + b[bCount+12+d]*ww*v + b[bCount+18+d]*uu*v
00299                                                 + b[bCount+21+d]*w*vv + b[bCount+24+d]*u*vv )
00300                                         + b[bCount+15+d]*6.0f*w*u*v;
00301                     normal[index] =   n[nCount+d]*ww + n[nCount+6+d]*uu + n[nCount+15+d]*vv
00302                                     + n[nCount+3+d]*w*u + n[nCount+9+d]*u*v + n[nCount+12+d]*w*v;
00303                     magnitude += normal[index]*normal[index];
00304                 }
00305                 magnitude = sqrt(magnitude);
00306                 normal[index-3] /= magnitude;
00307                 normal[index-2] /= magnitude;
00308                 normal[index-1] /= magnitude;
00309             }
00310         }
00311         /*
00312         glPointSize(11);
00313         int pos = 0;
00314         glBegin( GL_POINTS );
00315             for ( int i = 0; i < noOfVertices; ++i, pos+=3 ) {
00316                 glVertex3f( vertex[pos], vertex[pos+1], vertex[pos+2] );
00317             }
00318         glEnd();
00319         */
00320 
00321         int row1 = 0, row2 = smoothness*3;
00322         for ( int r = 1; r < smoothness; ++r, row1+=3 ) {
00323             glBegin( GL_TRIANGLE_STRIP );
00324                 for ( int i = 0; i < smoothness-r; ++i, row1+=3, row2+=3 ) {
00325                     glNormal3f( normal[row1], normal[row1+1], normal[row1+2] );
00326                     glVertex3f( vertex[row1], vertex[row1+1], vertex[row1+2] );
00327                     glNormal3f( normal[row2], normal[row2+1], normal[row2+2] );
00328                     glVertex3f( vertex[row2], vertex[row2+1], vertex[row2+2] );
00329                 }
00330                 glNormal3f( normal[row1], normal[row1+1], normal[row1+2] );
00331                 glVertex3f( vertex[row1], vertex[row1+1], vertex[row1+2] );
00332             glEnd();
00333         }
00334         /*
00335         row1 = 0;
00336         for ( int r = 0; r < noOfVertices; ++r, row1+=3 ) {
00337             glBegin( GL_LINES );
00338                 GLfloat ppp[3];
00339                 ppp[0]= normal[row1]+vertex[row1];
00340                 ppp[1]= normal[row1+1]+vertex[row1+1];
00341                 ppp[2]= normal[row1+2]+vertex[row1+2];
00342                     glVertex3f( vertex[row1], vertex[row1+1], vertex[row1+2] );
00343                     glVertex3fv( ppp );
00344             glEnd();
00345         }*/
00346         /*
00347         int idx = 0;
00348         DrawText( "b300", 
00349             static_cast<float>( vertex[idx] ),
00350             static_cast<float>( vertex[idx+1] ),
00351             static_cast<float>( vertex[idx+2] ) );
00352         idx = (smoothness-1)*3;
00353         DrawText( "b030", 
00354             static_cast<float>( vertex[idx] ),
00355             static_cast<float>( vertex[idx+1] ),
00356             static_cast<float>( vertex[idx+2] ) );
00357         idx = (noOfVertices-1)*3;
00358         DrawText( "b003", 
00359             static_cast<float>( vertex[idx] ),
00360             static_cast<float>( vertex[idx+1] ),
00361             static_cast<float>( vertex[idx+2] ) );
00362         */
00363     }
00364     delete [] vertex;
00365     delete [] normal;
00366 }
00367 /*
00368 //-----------------------------------------------------------------------------
00369 //void DisplayGL()
00370 template <typename T>
00371 void OpenGLPNTriangleModel<T>::DisplayGL( OpenGL::Enum::DrawMode DM )
00372 {
00373     switch (DM) {
00374     case OpenGL::Enum::POLYGON:
00375         DrawGL( GL_POLYGON );
00376         break;
00377     case OpenGL::Enum::WIRE_FRAME:
00378         DrawGL( GL_LINE_LOOP );
00379         break;
00380     case OpenGL::Enum::POINT:
00381         DrawGL( GL_POINTS );
00382         break;
00383     case OpenGL::Enum:: POLYGON_WITH_WIRE_FRAME:
00384         // Draw the object with GL_POLYGON_OFFSET enabled
00385         glEnable( GL_POLYGON_OFFSET_FILL );
00386         glPolygonOffset( 1.0, 1.0 );
00387         DrawGL( GL_POLYGON );
00388         glDisable( GL_POLYGON_OFFSET_FILL );
00389         // Draw the wire frame of the object
00390         glDisable( GL_LIGHTING );
00391         //glDisable( GL_DEPTH_TEST );
00392         glColor3ub( 255, 200, 0 );
00393         DrawGL( GL_LINE_LOOP );
00394         glEnable( GL_LIGHTING );
00395         //glEnable( GL_DEPTH_TEST );
00396         break;
00397     }
00398 }
00399 //*/
00400 //-----------------------------------------------------------------------------
00401 // Helper Fn
00402 // void DrawGL()
00403 template <typename T>
00404 void OpenGLPNTriangleModel<T>::DrawGL( GLenum drawMode )
00405 {
00406     //if ( isFacetShading ) {
00407     if ( false ) {
00408         // Draw the object
00409         //glEnable( GL_TEXTURE_2D );
00410         for ( int i = 0; i < m_iNoFaces; i++ )
00411         {
00412             glBegin( drawMode );
00413             for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j )
00414             {
00415                 // Draw texture
00416                 if ( m_prFace[i].GetNoTexCoords() != 0 ) {
00417                     glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 
00418                                 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) );
00419                 }
00420                 // Normal of the face
00421                 glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 
00422                              static_cast<float>( m_prFace[i].GetNormal()[1] ), 
00423                              static_cast<float>( m_prFace[i].GetNormal()[2] ) );
00424                 // Draw the vertex
00425                 glVertex3f ( 
00426                     static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 
00427                     static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 
00428                     static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) );
00429             }
00430             glEnd();
00431         }
00432         //glDisable( GL_TEXTURE_2D );
00433     }
00434     else if ( isFacetShading ) {
00435         // Draw the object
00436         //glEnable( GL_TEXTURE_2D );
00437         for ( int i = 0; i < m_iNoFaces; i++ )
00438         {
00439             glBegin( drawMode );
00440             for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j )
00441             {
00442                 // Draw texture
00443                 if ( m_prFace[i].GetNoTexCoords() != 0 ) {
00444                     glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 
00445                                 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) );
00446                 }
00447                 // Normal of the vertex
00448                 glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 
00449                             static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 
00450                             static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 
00451                 // Draw the vertex
00452                 glVertex3f ( 
00453                     static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 
00454                     static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 
00455                     static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) );
00456             }
00457             glEnd();
00458         }
00459         //glDisable( GL_TEXTURE_2D );
00460     }
00461     else {
00462         // Draw the object
00463         //glEnable( GL_TEXTURE_2D );
00464 
00465         int b[3] = { 0, 9, 27 }, n[3] = { 0, 6, 15 };
00466 
00467         /*
00468         // For FPS
00469         clock_t start, finish;
00470         start = clock();
00471         */
00472         //for ( int i = 0; i < m_iNoFaces; ++i )
00473         {
00474             #ifdef TAPs_USE_GLSL
00475             if ( gbUseGPU ) {   // draw by GLSL hardware
00476                 //setUniformVariables();
00477                 //DrawPNTrianglePatch(i, 10, m_prPNTriCoef, m_prPNTriNormal);
00478                 #ifdef TAPs_SHADER_FNS_HPP
00479                 DrawTriangleUsingHardware(m_iNoFaces, 10, m_prPNTriCoef, m_prPNTriNormal);
00480                 #endif
00481             }
00482             else {  // draw by CPU software
00483                 // Draw Bezier Patch
00484                 //DrawTriBezierPatchNo(i, 10);
00485                 DrawTriBezierPatchNo(m_iNoFaces, 10);
00486             }
00487             #else   // draw by CPU software
00488             DrawTriBezierPatchNo(m_iNoFaces, 10);
00489             #endif
00490 
00491             /*
00492             glBegin( GL_LINE_LOOP );
00493             for ( int j = 0; j < 3; ++j )
00494             {
00495                 // Draw texture
00496                 if ( m_prFace[i].GetNoTexCoords() != 0 ) {
00497                     glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 
00498                                   static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) );
00499                 }
00500                 // Normal of the vertex
00501                 glNormal3f ( static_cast<float>( m_prPNTriNormal[n[j]  ] ),
00502                              static_cast<float>( m_prPNTriNormal[n[j]+1] ),
00503                              static_cast<float>( m_prPNTriNormal[n[j]+2] ) );
00504                 // Draw the vertex
00505                 glVertex3f ( 
00506                     static_cast<float>( m_prPNTriCoef[ b[j]  ] ),
00507                     static_cast<float>( m_prPNTriCoef[ b[j]+1] ),
00508                     static_cast<float>( m_prPNTriCoef[ b[j]+2] ) );
00509             }
00510             glEnd();
00511             */
00512 
00513             /*
00514             DrawText( "b300", 
00515                     static_cast<float>( m_prPNTriCoef[ b[0]  ] ),
00516                     static_cast<float>( m_prPNTriCoef[ b[0]+1] ),
00517                     static_cast<float>( m_prPNTriCoef[ b[0]+2] ) );
00518             DrawText( "b030", 
00519                     static_cast<float>( m_prPNTriCoef[ b[1]  ] ),
00520                     static_cast<float>( m_prPNTriCoef[ b[1]+1] ),
00521                     static_cast<float>( m_prPNTriCoef[ b[1]+2] ) );
00522             DrawText( "b003", 
00523                     static_cast<float>( m_prPNTriCoef[ b[2]  ] ),
00524                     static_cast<float>( m_prPNTriCoef[ b[2]+1] ),
00525                     static_cast<float>( m_prPNTriCoef[ b[2]+2] ) );
00526             */
00527 
00528             /*
00529             // Draw Bezier control points
00530             glPointSize(5);
00531             glDisable(GL_LIGHTING);
00532             int s;
00533             glBegin( GL_POINTS );
00534             for ( s = 0; s < 30; s+=3 ) {
00535                 // Draw the vertex
00536                 glColor3ub( s*25, 0, 0 );
00537                 glVertex3f (
00538                     static_cast<float>( m_prPNTriCoef[ b[0]+s   ] ),
00539                     static_cast<float>( m_prPNTriCoef[ b[0]+s+1 ] ),
00540                     static_cast<float>( m_prPNTriCoef[ b[0]+s+2 ] ) );
00541             }
00542             glEnd();
00543             */
00544 
00545             /*
00546             DrawText( "b300", 
00547                 static_cast<float>( m_prPNTriCoef[ b[0]  ] ),
00548                 static_cast<float>( m_prPNTriCoef[ b[0]+1] ),
00549                 static_cast<float>( m_prPNTriCoef[ b[0]+2] ) );
00550             DrawText( "b210", 
00551                 static_cast<float>( m_prPNTriCoef[ b[0]+3] ),
00552                 static_cast<float>( m_prPNTriCoef[ b[0]+4] ),
00553                 static_cast<float>( m_prPNTriCoef[ b[0]+5] ) );
00554             DrawText( "b120", 
00555                 static_cast<float>( m_prPNTriCoef[ b[0]+6] ),
00556                 static_cast<float>( m_prPNTriCoef[ b[0]+7] ),
00557                 static_cast<float>( m_prPNTriCoef[ b[0]+8] ) );
00558             DrawText( "b030", 
00559                 static_cast<float>( m_prPNTriCoef[ b[0]+9 ] ),
00560                 static_cast<float>( m_prPNTriCoef[ b[0]+10] ),
00561                 static_cast<float>( m_prPNTriCoef[ b[0]+11] ) );
00562             DrawText( "b201", 
00563                 static_cast<float>( m_prPNTriCoef[ b[0]+12] ),
00564                 static_cast<float>( m_prPNTriCoef[ b[0]+13] ),
00565                 static_cast<float>( m_prPNTriCoef[ b[0]+14] ) );
00566             DrawText( "b111", 
00567                 static_cast<float>( m_prPNTriCoef[ b[0]+15] ),
00568                 static_cast<float>( m_prPNTriCoef[ b[0]+16] ),
00569                 static_cast<float>( m_prPNTriCoef[ b[0]+17] ) );
00570             DrawText( "b021", 
00571                 static_cast<float>( m_prPNTriCoef[ b[0]+18] ),
00572                 static_cast<float>( m_prPNTriCoef[ b[0]+19] ),
00573                 static_cast<float>( m_prPNTriCoef[ b[0]+20] ) );
00574             DrawText( "b102", 
00575                 static_cast<float>( m_prPNTriCoef[ b[0]+21] ),
00576                 static_cast<float>( m_prPNTriCoef[ b[0]+22] ),
00577                 static_cast<float>( m_prPNTriCoef[ b[0]+23] ) );
00578             DrawText( "b012", 
00579                 static_cast<float>( m_prPNTriCoef[ b[0]+24] ),
00580                 static_cast<float>( m_prPNTriCoef[ b[0]+25] ),
00581                 static_cast<float>( m_prPNTriCoef[ b[0]+26] ) );
00582             DrawText( "b003", 
00583                 static_cast<float>( m_prPNTriCoef[ b[0]+27] ),
00584                 static_cast<float>( m_prPNTriCoef[ b[0]+28] ),
00585                 static_cast<float>( m_prPNTriCoef[ b[0]+29] ) );
00586             */
00587 
00588             /*
00589             // Draw lines connecting Bezier control points
00590             glColor3ub( 0, 220, 0 );
00591             glBegin( GL_LINE_LOOP );
00592             s = 0;
00593             glVertex3f ( 
00594                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00595                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00596                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00597             s = 3;
00598             glVertex3f ( 
00599                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00600                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00601                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00602             s = 6;
00603             glVertex3f ( 
00604                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00605                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00606                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00607             s = 9;
00608             glVertex3f ( 
00609                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00610                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00611                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00612             s = 18;
00613             glVertex3f ( 
00614                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00615                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00616                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00617             s = 24;
00618             glVertex3f ( 
00619                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00620                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00621                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00622             s = 27;
00623             glVertex3f ( 
00624                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00625                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00626                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00627             s = 21;
00628             glVertex3f ( 
00629                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00630                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00631                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00632             s = 12;
00633             glVertex3f ( 
00634                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00635                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00636                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00637             glEnd();
00638             glBegin( GL_LINE_LOOP );
00639             s = 3;
00640             glVertex3f ( 
00641                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00642                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00643                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00644             s = 12;
00645             glVertex3f ( 
00646                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00647                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00648                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00649             s = 15;
00650             glVertex3f ( 
00651                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00652                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00653                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00654             glEnd();
00655             glBegin( GL_LINE_LOOP );
00656             s = 6;
00657             glVertex3f ( 
00658                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00659                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00660                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00661             s = 15;
00662             glVertex3f ( 
00663                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00664                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00665                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00666             s = 18;
00667             glVertex3f ( 
00668                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00669                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00670                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00671             glEnd();
00672             glBegin( GL_LINE_LOOP );
00673             s = 15;
00674             glVertex3f ( 
00675                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00676                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00677                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00678             s = 21;
00679             glVertex3f ( 
00680                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00681                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00682                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00683             s = 24;
00684             glVertex3f ( 
00685                 static_cast<float>( m_prPNTriCoef[ b[0]+s  ] ),
00686                 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ),
00687                 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) );
00688             glEnd();
00689             */
00690 
00691             //glEnable(GL_LIGHTING);
00692             /*
00693             b[0] += 30;
00694             b[1] += 30;
00695             b[2] += 30;
00696             n[0] += 18;
00697             n[1] += 18;
00698             n[2] += 18;
00699             */
00700         }
00701         /*
00702         // For FPS
00703         finish = clock();
00704         double duration = static_cast<double>(finish - start);
00705         int dFPS;
00706         if ( duration > 0.0 ) {
00707             dFPS = CLOCKS_PER_SEC / duration;
00708         }
00709         else {
00710             dFPS = 1000;
00711         }
00712         std::cout << "FPs: " << dFPS << "\n";
00713         */
00714 
00715         //glDisable( GL_TEXTURE_2D );
00716     }
00717 }
00718 //-----------------------------------------------------------------------------
00719 //=============================================================================
00720 END_NAMESPACE_TAPs__OpenGL
00721 //-----------------------------------------------------------------------------
00722 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00723 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines