![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsOpenGLSpringHalfEdgeModel.cpp 00003 00004 Class OpenGLSpringHalfEdgeModel is for creating an OpenGL Polygonal Model using 00005 half-edge data structure. 00006 00007 SUKITTI PUNAK (02/27/2006) 00008 UPDATE (04/10/2006) 00009 ******************************************************************************/ 00010 #include "TAPsOpenGLSpringHalfEdgeModel.hpp" 00011 // Using Inclusion Model (i.e. definitions are included in declarations) 00012 // (this name.cpp is included in name.hpp) 00013 // Each friend is defined directly inside its declaration. 00014 00015 BEGIN_NAMESPACE_TAPs__OpenGL 00016 //============================================================================= 00017 //----------------------------------------------------------------------------- 00018 // default constructor 00019 template <typename T> 00020 OpenGLSpringHalfEdgeModel<T>::OpenGLSpringHalfEdgeModel() 00021 : SpringHalfEdgeModel<T>(), bIsDisplayVertexNormals( false ) 00022 { 00023 #ifdef TAPs_DEBUG_MODE 00024 std::cout << "OpenGLSpringHalfEdgeModel<" << typeid(T).name() << "> constructor\n"; 00025 #endif//TAPs_DEBUG_MODE 00026 } 00027 //----------------------------------------------------------------------------- 00028 // destructor 00029 template <typename T> 00030 OpenGLSpringHalfEdgeModel<T>::~OpenGLSpringHalfEdgeModel() 00031 { 00032 #ifdef TAPs_DEBUG_MODE 00033 std::cout << "OpenGLSpringHalfEdgeModel<" << typeid(T).name() << "> destructor\n"; 00034 #endif//TAPs_DEBUG_MODE 00035 } 00036 /* 00037 //----------------------------------------------------------------------------- 00038 //void DisplayGL() 00039 template <typename T> 00040 void OpenGLSpringHalfEdgeModel<T>::DisplayGL( OpenGL::Enum::DrawMode DM ) 00041 { 00042 switch (DM) { 00043 case OpenGL::Enum::POLYGON: 00044 DrawGL( GL_POLYGON ); 00045 break; 00046 case OpenGL::Enum::WIRE_FRAME: 00047 DrawGL( GL_LINE_LOOP ); 00048 break; 00049 case OpenGL::Enum::POINT: 00050 DrawGL( GL_POINTS ); 00051 break; 00052 case OpenGL::Enum:: POLYGON_WITH_WIRE_FRAME: 00053 // Draw the object with GL_POLYGON_OFFSET enabled 00054 glEnable( GL_POLYGON_OFFSET_FILL ); 00055 glPolygonOffset( 1.0, 1.0 ); 00056 DrawGL( GL_POLYGON ); 00057 glDisable( GL_POLYGON_OFFSET_FILL ); 00058 // Draw the wire frame of the object 00059 glDisable( GL_LIGHTING ); 00060 //glDisable( GL_DEPTH_TEST ); 00061 glColor3ub( 255, 200, 0 ); 00062 DrawGL( GL_LINE_LOOP ); 00063 glEnable( GL_LIGHTING ); 00064 //glEnable( GL_DEPTH_TEST ); 00065 break; 00066 } 00067 } 00068 //*/ 00069 //----------------------------------------------------------------------------- 00070 // Helper Fn 00071 // void DrawGL() 00072 template <typename T> 00073 void OpenGLSpringHalfEdgeModel<T>::DrawGL ( GLenum drawMode ) 00074 { 00075 #ifdef TAPs_USE_DATA_POOL 00076 glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); 00077 #endif//TAPs_USE_DATA_POOL 00078 //---------------------------------------------------------------- 00079 if ( drawMode == OpenGL::Enum::POINT ) { 00080 00081 #ifdef TAPs_USE_DATA_POOL 00082 glEnableClientState( GL_VERTEX_ARRAY ); 00083 if ( typeid(T) == typeid(float) ) 00084 { 00085 glVertexPointer( 3, GL_FLOAT, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00086 } 00087 else //if ( typeid(T) == typeid(double) ) 00088 { 00089 glVertexPointer( 3, GL_DOUBLE, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00090 } 00091 glPointSize( 2 ); 00092 glDrawArrays( GL_POINTS, 0, GetArrayOfVertexPositions().GetSize() ); 00093 00094 #else //TAPs_USE_DATA_POOL 00095 HEVertex<T> *ptr = m_listVertex->Head(); 00096 glBegin( drawMode ); 00097 while ( ptr != NULL ) { 00098 // Draw the vertex 00099 glVertex3f ( 00100 static_cast<float>( (*ptr)[0] ), 00101 static_cast<float>( (*ptr)[1] ), 00102 static_cast<float>( (*ptr)[2] ) ); 00103 ptr = ptr->Next(); 00104 } 00105 glEnd(); 00106 00107 #endif//TAPs_USE_DATA_POOL 00108 00109 } 00110 else if ( isFacetShading ) { 00111 // Draw the object 00112 //glEnable( GL_TEXTURE_2D ); 00113 HEFace<T> *facePtr = m_listFace->Head(); 00114 HEHalfEdge<T> *halfEdgePtr; 00115 //for ( int f = 0; f < GetNoFaces(); ++f ) { 00116 while ( facePtr != NULL ) { 00117 00118 // Submaterial supported by .ASE 00119 #ifdef TAPs_SUPPORT_ASE_FORMAT 00120 int matID = facePtr->GetMaterialID(); 00121 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00122 this->submaterials[ matID ]->ApplyMaterial(); 00123 } 00124 #endif//TAPs_SUPPORT_ASE_FORMAT 00125 00126 halfEdgePtr = facePtr->IncidentHalfEdge(); 00127 glBegin( drawMode ); 00128 //for ( int i = 0; i < 3; ++i ) { 00129 do { 00131 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00132 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00133 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00134 //} 00135 // Normal of the face 00136 glNormal3f ( 00137 static_cast<float>( facePtr->GetNormal()[0] ), 00138 static_cast<float>( facePtr->GetNormal()[1] ), 00139 static_cast<float>( facePtr->GetNormal()[2] ) 00140 ); 00141 // Draw the vertex 00142 glVertex3f ( 00143 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00144 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00145 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00146 ); 00147 // DEBUG: 00148 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 00149 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 00150 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 00151 //std::cout << "\n"; 00152 halfEdgePtr = halfEdgePtr->Next(); 00153 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00154 //std::cout << "\n"; 00155 //} 00156 glEnd(); 00157 facePtr = facePtr->Next(); 00158 } 00159 00160 // Draw the object 00161 //for ( int i = 0; i < m_iNoFaces; i++ ) 00162 //{ 00163 // glBegin( drawMode ); 00164 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00165 // { 00166 // // Draw texture 00167 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00168 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00169 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00170 // } 00171 // // Normal of the face 00172 // //glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00173 // // static_cast<float>( m_prFace[i].GetNormal()[1] ), 00174 // // static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00175 // // Draw the vertex 00176 // glVertex3f ( 00177 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00178 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00179 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00180 // } 00181 // glEnd(); 00182 //} 00184 } 00185 else { 00186 // Draw the object 00187 00188 #ifdef TAPs_USE_DATA_POOL 00189 glEnableClientState( GL_VERTEX_ARRAY ); 00190 glEnableClientState( GL_NORMAL_ARRAY ); 00191 if ( typeid(T) == typeid(float) ) 00192 { 00193 glVertexPointer( 3, GL_FLOAT, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00194 glNormalPointer( GL_FLOAT, 0, GetArrayOfVertexNormals().GetAddressOfDataNumber(0) ); 00195 } 00196 else //if ( typeid(T) == typeid(double) ) 00197 { 00198 glVertexPointer( 3, GL_DOUBLE, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00199 glNormalPointer( GL_DOUBLE, 0, GetArrayOfVertexNormals().GetAddressOfDataNumber(0) ); 00200 } 00201 00202 #ifdef TAPs_SUPPORT_ASE_FORMAT 00203 int i = 0; 00204 HEFace<T> *facePtr = m_listFace->Head(); 00205 while ( facePtr != NULL ) { 00206 00207 // Submaterial supported by .ASE 00208 int matID = facePtr->GetMaterialID(); 00209 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00210 this->submaterials[ matID ]->ApplyMaterial(); 00211 } 00212 glDrawElements( 00213 GL_TRIANGLES, 00214 3, 00215 GL_UNSIGNED_INT, 00216 GetArrayOfIndexFaces().GetAddressOfDataNumber(i++) 00217 ); 00218 facePtr = facePtr->Next(); 00219 } 00220 #else //TAPs_SUPPORT_ASE_FORMAT 00221 glDrawElements( 00222 GL_TRIANGLES, 00223 GetArrayOfIndexFaces().GetSize()*GetArrayOfIndexFaces().GetStride(), 00224 GL_UNSIGNED_INT, 00225 GetArrayOfIndexFaces().GetAddressOfDataNumber(0) 00226 ); 00227 #endif//TAPs_SUPPORT_ASE_FORMAT 00228 00229 #else //TAPs_USE_DATA_POOL 00230 //glEnable( GL_TEXTURE_2D ); 00231 HEFace<T> *facePtr = m_listFace->Head(); 00232 HEHalfEdge<T> *halfEdgePtr; 00233 //for ( int f = 0; f < GetNoFaces(); ++f ) { 00234 while ( facePtr != NULL ) { 00235 00236 // Submaterial supported by .ASE 00237 #ifdef TAPs_SUPPORT_ASE_FORMAT 00238 int matID = facePtr->GetMaterialID(); 00239 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00240 this->submaterials[ matID ]->ApplyMaterial(); 00241 } 00242 #endif//TAPs_SUPPORT_ASE_FORMAT 00243 00244 halfEdgePtr = facePtr->IncidentHalfEdge(); 00245 glBegin( drawMode ); 00246 //for ( int i = 0; i < 3; ++i ) { 00247 do { 00249 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00250 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00251 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00252 //} 00254 glNormal3f ( 00255 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[0] ), 00256 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[1] ), 00257 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[2] ) 00258 ); 00259 // Draw the vertex 00260 glVertex3f ( 00261 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00262 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00263 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00264 ); 00265 // DEBUG: 00266 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 00267 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 00268 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 00269 //std::cout << "\n"; 00270 halfEdgePtr = halfEdgePtr->Next(); 00271 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00272 //std::cout << "\n"; 00273 //} 00274 glEnd(); 00275 facePtr = facePtr->Next(); 00276 } 00277 00278 #endif//TAPs_USE_DATA_POOL 00279 00282 //for ( int i = 0; i < m_iNoFaces; i++ ) 00283 //{ 00284 // glBegin( drawMode ); 00285 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00286 // { 00287 // // Draw texture 00288 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00289 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00290 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00291 // } 00292 // // Normal of the vertex 00293 // glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 00294 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 00295 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 00296 // // Draw the vertex 00297 // glVertex3f ( 00298 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00299 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00300 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00301 // } 00302 // glEnd(); 00303 //} 00305 } 00306 00307 // Draw Boundary 00308 //if ( drawMode == OpenGL::Enum::POLYGON_WITH_WIRE_FRAME ) { 00309 //if ( true ) { 00310 // glColor3f( 1.0f, 0.0f, 0.0f ); 00311 // glDisable( GL_LIGHTING ); 00312 // glBegin( GL_LINES ); 00313 // HEFace<T> *facePtr = m_listFace->Head(); 00314 // HEHalfEdge<T> *halfEdgePtr; 00315 // while ( facePtr != NULL ) { 00316 // halfEdgePtr = facePtr->IncidentHalfEdge(); 00317 // do { 00318 // if ( !halfEdgePtr->Pair() ) { 00319 // // Draw the vertex 00320 // glVertex3f ( 00321 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00322 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00323 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00324 // ); 00325 // glVertex3f ( 00326 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 00327 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 00328 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 00329 // ); 00330 // } 00331 // halfEdgePtr = halfEdgePtr->Next(); 00332 // } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00333 // facePtr = facePtr->Next(); 00334 // } 00335 // glEnd(); 00336 // glEnable( GL_LIGHTING ); 00337 //} 00338 00339 // Draw Boundary 00340 if ( true ) { 00341 glColor3f( 1.0f, 0.0f, 0.0f ); 00342 glPushAttrib( GL_LIGHTING_BIT ); 00343 glDisable( GL_LIGHTING ); 00344 glBegin( GL_LINES ); 00345 if ( m_listHoleFace != NULL ) { 00346 HEFace<T> *facePtr = m_listHoleFace->Head(); 00347 HEHalfEdge<T> *halfEdgePtr; 00348 while ( facePtr != NULL ) { 00349 halfEdgePtr = facePtr->IncidentHalfEdge(); 00350 do { 00351 //if ( halfEdgePtr && halfEdgePtr->Next() ) { 00352 // Draw the vertex 00353 glVertex3f ( 00354 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00355 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00356 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00357 ); 00358 glVertex3f ( 00359 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 00360 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 00361 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 00362 ); 00363 //} 00364 halfEdgePtr = halfEdgePtr->Next(); 00365 } while ( halfEdgePtr && halfEdgePtr != facePtr->IncidentHalfEdge() ); 00366 facePtr = facePtr->Next(); 00367 } 00368 } 00369 glEnd(); 00370 //glEnable( GL_LIGHTING ); 00371 glPopAttrib(); 00372 } 00373 00374 if ( bIsDisplayVertexNormals ) { 00375 glColor3ub( 75, 200, 100 ); 00376 glPushAttrib( GL_LIGHTING_BIT ); 00377 glDisable( GL_LIGHTING ); 00378 //HEVertex<T> * pVertex = GetVertexList(); 00379 HEVertex<T> * pVertex = m_listVertex->Head(); 00380 while ( pVertex ) { 00381 Fn::Draw3DLine( pVertex->GetPosition(), pVertex->GetPosition() + pVertex->GetNormal() ); 00382 pVertex = pVertex->Next(); 00383 } 00384 //glEnable( GL_LIGHTING ); 00385 glPopAttrib(); 00386 } 00387 00388 00389 //DrawGLParticleRef(); 00390 //DrawGLVertexRing1(); 00391 //DrawGLSpringConnections(); 00392 //DrawGLSprings(); 00393 00394 00395 //DrawGLHalfEdges(); 00396 00397 // Draw AABB Bounding Box 00398 //DrawBoundingAABB(); 00399 //DrawBoundingEllipsoid(); 00400 //DrawBoundingSphere(); 00401 //---------------------------------------------------------------- 00402 #ifdef TAPs_USE_DATA_POOL 00403 glPopClientAttrib(); 00404 #endif//TAPs_USE_DATA_POOL 00405 } 00406 //----------------------------------------------------------------------------- 00407 00408 //============================================================================= 00409 #ifdef TAPs_ENABLE_FACE_VERTEX_COLOR 00410 //----------------------------------------------------------------------------- 00411 template <typename T> 00412 void OpenGLSpringHalfEdgeModel<T>::DrawGLWithFaceVertexColor_RGB ( GLenum drawMode ) 00413 { 00414 #ifdef TAPs_USE_DATA_POOL 00415 glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); 00416 #endif//TAPs_USE_DATA_POOL 00417 00418 glPushAttrib( GL_ENABLE_BIT | GL_ENABLE_BIT ); 00419 glEnable( GL_COLOR_MATERIAL ); 00420 00421 //---------------------------------------------------------------- 00422 if ( drawMode == OpenGL::Enum::POINT ) { 00423 00424 #ifdef TAPs_USE_DATA_POOL 00425 glEnableClientState( GL_VERTEX_ARRAY ); 00426 if ( typeid(T) == typeid(float) ) 00427 { 00428 glVertexPointer( 3, GL_FLOAT, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00429 } 00430 else //if ( typeid(T) == typeid(double) ) 00431 { 00432 glVertexPointer( 3, GL_DOUBLE, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00433 } 00434 glPointSize( 2 ); 00435 glDrawArrays( GL_POINTS, 0, GetArrayOfVertexPositions().GetSize() ); 00436 00437 #else //TAPs_USE_DATA_POOL 00438 HEVertex<T> *ptr = m_listVertex->Head(); 00439 glBegin( drawMode ); 00440 while ( ptr != NULL ) { 00441 // Draw the vertex 00442 glVertex3f ( 00443 static_cast<float>( (*ptr)[0] ), 00444 static_cast<float>( (*ptr)[1] ), 00445 static_cast<float>( (*ptr)[2] ) ); 00446 ptr = ptr->Next(); 00447 } 00448 glEnd(); 00449 00450 #endif//TAPs_USE_DATA_POOL 00451 } 00452 else if ( isFacetShading ) { 00453 // Draw the object 00454 //glEnable( GL_TEXTURE_2D ); 00455 HEFace<T> *facePtr = m_listFace->Head(); 00456 HEHalfEdge<T> *halfEdgePtr; 00457 //for ( int f = 0; f < GetNoFaces(); ++f ) { 00458 while ( facePtr != NULL ) { 00459 00460 /* 00461 // Submaterial supported by .ASE 00462 #ifdef TAPs_SUPPORT_ASE_FORMAT 00463 int matID = facePtr->GetMaterialID(); 00464 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00465 this->submaterials[ matID ]->ApplyMaterial(); 00466 } 00467 #endif//TAPs_SUPPORT_ASE_FORMAT 00468 //*/ 00469 00470 halfEdgePtr = facePtr->IncidentHalfEdge(); 00471 int j = 0; 00472 glBegin( drawMode ); 00473 //for ( int i = 0; i < 3; ++i ) { 00474 do { 00476 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00477 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00478 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00479 //} 00480 // Normal of the face 00481 glNormal3f ( 00482 static_cast<float>( facePtr->GetNormal()[0] ), 00483 static_cast<float>( facePtr->GetNormal()[1] ), 00484 static_cast<float>( facePtr->GetNormal()[2] ) 00485 ); 00486 00487 // Vertex color of the face 00488 float VC[3]; 00489 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2] ); 00490 glColor3f ( VC[0], VC[1], VC[2] ); 00491 00492 // Draw the vertex 00493 glVertex3f ( 00494 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00495 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00496 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00497 ); 00498 // DEBUG: 00499 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 00500 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 00501 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 00502 //std::cout << "\n"; 00503 halfEdgePtr = halfEdgePtr->Next(); 00504 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00505 //std::cout << "\n"; 00506 //} 00507 glEnd(); 00508 facePtr = facePtr->Next(); 00509 } 00510 00511 // Draw the object 00512 //for ( int i = 0; i < m_iNoFaces; i++ ) 00513 //{ 00514 // glBegin( drawMode ); 00515 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00516 // { 00517 // // Draw texture 00518 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00519 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00520 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00521 // } 00522 // // Normal of the face 00523 // //glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00524 // // static_cast<float>( m_prFace[i].GetNormal()[1] ), 00525 // // static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00526 // // Draw the vertex 00527 // glVertex3f ( 00528 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00529 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00530 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00531 // } 00532 // glEnd(); 00533 //} 00535 } 00536 else { 00537 // Draw the object 00538 00539 #ifdef TAPs_USE_DATA_POOL__ 00540 #else //TAPs_USE_DATA_POOL__ 00541 00542 //glEnable( GL_TEXTURE_2D ); 00543 HEFace<T> *facePtr = m_listFace->Head(); 00544 HEHalfEdge<T> *halfEdgePtr; 00545 //for ( int f = 0; f < GetNoFaces(); ++f ) { 00546 while ( facePtr != NULL ) { 00547 00548 /* 00549 // Submaterial supported by .ASE 00550 #ifdef TAPs_SUPPORT_ASE_FORMAT 00551 int matID = facePtr->GetMaterialID(); 00552 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00553 this->submaterials[ matID ]->ApplyMaterial(); 00554 } 00555 #endif//TAPs_SUPPORT_ASE_FORMAT 00556 //*/ 00557 00558 halfEdgePtr = facePtr->IncidentHalfEdge(); 00559 int j = 0; 00560 glBegin( drawMode ); 00561 //for ( int i = 0; i < 3; ++i ) { 00562 do { 00564 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00565 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00566 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00567 //} 00569 glNormal3f ( 00570 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[0] ), 00571 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[1] ), 00572 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[2] ) 00573 ); 00574 00575 // Vertex color of the face 00576 float VC[3]; 00577 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2] ); 00578 glColor3f ( VC[0], VC[1], VC[2] ); 00579 00580 // Draw the vertex 00581 glVertex3f ( 00582 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00583 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00584 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00585 ); 00586 // DEBUG: 00587 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 00588 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 00589 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 00590 //std::cout << "\n"; 00591 halfEdgePtr = halfEdgePtr->Next(); 00592 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00593 //std::cout << "\n"; 00594 //} 00595 glEnd(); 00596 facePtr = facePtr->Next(); 00597 } 00598 00599 #endif//TAPs_USE_DATA_POOL__ 00600 00603 //for ( int i = 0; i < m_iNoFaces; i++ ) 00604 //{ 00605 // glBegin( drawMode ); 00606 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00607 // { 00608 // // Draw texture 00609 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00610 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00611 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00612 // } 00613 // // Normal of the vertex 00614 // glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 00615 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 00616 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 00617 // // Draw the vertex 00618 // glVertex3f ( 00619 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00620 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00621 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00622 // } 00623 // glEnd(); 00624 //} 00626 } 00627 00628 glPopAttrib(); 00629 00630 // Draw Boundary 00631 //if ( drawMode == OpenGL::Enum::POLYGON_WITH_WIRE_FRAME ) { 00632 //if ( true ) { 00633 // glColor3f( 1.0f, 0.0f, 0.0f ); 00634 // glDisable( GL_LIGHTING ); 00635 // glBegin( GL_LINES ); 00636 // HEFace<T> *facePtr = m_listFace->Head(); 00637 // HEHalfEdge<T> *halfEdgePtr; 00638 // while ( facePtr != NULL ) { 00639 // halfEdgePtr = facePtr->IncidentHalfEdge(); 00640 // do { 00641 // if ( !halfEdgePtr->Pair() ) { 00642 // // Draw the vertex 00643 // glVertex3f ( 00644 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00645 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00646 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00647 // ); 00648 // glVertex3f ( 00649 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 00650 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 00651 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 00652 // ); 00653 // } 00654 // halfEdgePtr = halfEdgePtr->Next(); 00655 // } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00656 // facePtr = facePtr->Next(); 00657 // } 00658 // glEnd(); 00659 // glEnable( GL_LIGHTING ); 00660 //} 00661 00662 // Draw Boundary 00663 if ( true ) { 00664 glColor3f( 1.0f, 0.0f, 0.0f ); 00665 glPushAttrib( GL_LIGHTING_BIT ); 00666 glDisable( GL_LIGHTING ); 00667 glBegin( GL_LINES ); 00668 if ( m_listHoleFace != NULL ) { 00669 HEFace<T> *facePtr = m_listHoleFace->Head(); 00670 HEHalfEdge<T> *halfEdgePtr; 00671 while ( facePtr != NULL ) { 00672 halfEdgePtr = facePtr->IncidentHalfEdge(); 00673 do { 00674 //if ( halfEdgePtr && halfEdgePtr->Next() ) { 00675 // Draw the vertex 00676 glVertex3f ( 00677 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00678 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00679 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00680 ); 00681 glVertex3f ( 00682 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 00683 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 00684 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 00685 ); 00686 //} 00687 halfEdgePtr = halfEdgePtr->Next(); 00688 } while ( halfEdgePtr && halfEdgePtr != facePtr->IncidentHalfEdge() ); 00689 facePtr = facePtr->Next(); 00690 } 00691 } 00692 glEnd(); 00693 //glEnable( GL_LIGHTING ); 00694 glPopAttrib(); 00695 } 00696 00697 if ( bIsDisplayVertexNormals ) { 00698 glColor3ub( 75, 200, 100 ); 00699 glPushAttrib( GL_LIGHTING_BIT ); 00700 glDisable( GL_LIGHTING ); 00701 //HEVertex<T> * pVertex = GetVertexList(); 00702 HEVertex<T> * pVertex = m_listVertex->Head(); 00703 while ( pVertex ) { 00704 Fn::Draw3DLine( pVertex->GetPosition(), pVertex->GetPosition() + pVertex->GetNormal() ); 00705 pVertex = pVertex->Next(); 00706 } 00707 //glEnable( GL_LIGHTING ); 00708 glPopAttrib(); 00709 } 00710 00711 00712 //DrawGLParticleRef(); 00713 //DrawGLVertexRing1(); 00714 //DrawGLSpringConnections(); 00715 //DrawGLSprings(); 00716 00717 00718 //DrawGLHalfEdges(); 00719 00720 // Draw AABB Bounding Box 00721 //DrawBoundingAABB(); 00722 //DrawBoundingEllipsoid(); 00723 //DrawBoundingSphere(); 00724 //---------------------------------------------------------------- 00725 #ifdef TAPs_USE_DATA_POOL 00726 glPopClientAttrib(); 00727 #endif//TAPs_USE_DATA_POOL 00728 } 00729 //----------------------------------------------------------------------------- 00730 template <typename T> 00731 void OpenGLSpringHalfEdgeModel<T>::DrawGLWithFaceVertexColor_RGBA ( GLenum drawMode ) 00732 { 00733 #ifdef TAPs_USE_DATA_POOL 00734 glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); 00735 #endif//TAPs_USE_DATA_POOL 00736 00737 glPushAttrib( GL_ENABLE_BIT | GL_ENABLE_BIT ); 00738 glEnable( GL_COLOR_MATERIAL ); 00739 00740 //---------------------------------------------------------------- 00741 if ( drawMode == OpenGL::Enum::POINT ) { 00742 00743 #ifdef TAPs_USE_DATA_POOL 00744 glEnableClientState( GL_VERTEX_ARRAY ); 00745 if ( typeid(T) == typeid(float) ) 00746 { 00747 glVertexPointer( 3, GL_FLOAT, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00748 } 00749 else //if ( typeid(T) == typeid(double) ) 00750 { 00751 glVertexPointer( 3, GL_DOUBLE, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00752 } 00753 glPointSize( 2 ); 00754 glDrawArrays( GL_POINTS, 0, GetArrayOfVertexPositions().GetSize() ); 00755 00756 #else //TAPs_USE_DATA_POOL 00757 HEVertex<T> *ptr = m_listVertex->Head(); 00758 glBegin( drawMode ); 00759 while ( ptr != NULL ) { 00760 // Draw the vertex 00761 glVertex3f ( 00762 static_cast<float>( (*ptr)[0] ), 00763 static_cast<float>( (*ptr)[1] ), 00764 static_cast<float>( (*ptr)[2] ) ); 00765 ptr = ptr->Next(); 00766 } 00767 glEnd(); 00768 00769 #endif//TAPs_USE_DATA_POOL 00770 } 00771 else if ( isFacetShading ) { 00772 // Draw the object 00773 //glEnable( GL_TEXTURE_2D ); 00774 HEFace<T> *facePtr = m_listFace->Head(); 00775 HEHalfEdge<T> *halfEdgePtr; 00776 //for ( int f = 0; f < GetNoFaces(); ++f ) { 00777 while ( facePtr != NULL ) { 00778 00779 /* 00780 // Submaterial supported by .ASE 00781 #ifdef TAPs_SUPPORT_ASE_FORMAT 00782 int matID = facePtr->GetMaterialID(); 00783 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00784 this->submaterials[ matID ]->ApplyMaterial(); 00785 } 00786 #endif//TAPs_SUPPORT_ASE_FORMAT 00787 //*/ 00788 00789 halfEdgePtr = facePtr->IncidentHalfEdge(); 00790 int j = 0; 00791 glBegin( drawMode ); 00792 //for ( int i = 0; i < 3; ++i ) { 00793 do { 00795 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00796 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00797 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00798 //} 00799 // Normal of the face 00800 glNormal3f ( 00801 static_cast<float>( facePtr->GetNormal()[0] ), 00802 static_cast<float>( facePtr->GetNormal()[1] ), 00803 static_cast<float>( facePtr->GetNormal()[2] ) 00804 ); 00805 00806 // Vertex color of the face 00807 float VC[4]; 00808 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2], &VC[3] ); 00809 glColor4f ( VC[0], VC[1], VC[2], VC[3] ); 00810 00811 // Draw the vertex 00812 glVertex3f ( 00813 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00814 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00815 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00816 ); 00817 // DEBUG: 00818 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 00819 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 00820 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 00821 //std::cout << "\n"; 00822 halfEdgePtr = halfEdgePtr->Next(); 00823 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00824 //std::cout << "\n"; 00825 //} 00826 glEnd(); 00827 facePtr = facePtr->Next(); 00828 } 00829 00830 // Draw the object 00831 //for ( int i = 0; i < m_iNoFaces; i++ ) 00832 //{ 00833 // glBegin( drawMode ); 00834 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00835 // { 00836 // // Draw texture 00837 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00838 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00839 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00840 // } 00841 // // Normal of the face 00842 // //glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00843 // // static_cast<float>( m_prFace[i].GetNormal()[1] ), 00844 // // static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00845 // // Draw the vertex 00846 // glVertex3f ( 00847 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00848 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00849 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00850 // } 00851 // glEnd(); 00852 //} 00854 } 00855 else { 00856 // Draw the object 00857 00858 #ifdef TAPs_USE_DATA_POOL__ 00859 #else //TAPs_USE_DATA_POOL__ 00860 00861 //glEnable( GL_TEXTURE_2D ); 00862 HEFace<T> *facePtr = m_listFace->Head(); 00863 HEHalfEdge<T> *halfEdgePtr; 00864 //for ( int f = 0; f < GetNoFaces(); ++f ) { 00865 while ( facePtr != NULL ) { 00866 00867 /* 00868 // Submaterial supported by .ASE 00869 #ifdef TAPs_SUPPORT_ASE_FORMAT 00870 int matID = facePtr->GetMaterialID(); 00871 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00872 this->submaterials[ matID ]->ApplyMaterial(); 00873 } 00874 #endif//TAPs_SUPPORT_ASE_FORMAT 00875 //*/ 00876 00877 halfEdgePtr = facePtr->IncidentHalfEdge(); 00878 int j = 0; 00879 glBegin( drawMode ); 00880 //for ( int i = 0; i < 3; ++i ) { 00881 do { 00883 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00884 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00885 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00886 //} 00888 glNormal3f ( 00889 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[0] ), 00890 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[1] ), 00891 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[2] ) 00892 ); 00893 00894 // Vertex color of the face 00895 float VC[4]; 00896 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2], &VC[3] ); 00897 glColor4f ( VC[0], VC[1], VC[2], VC[3] ); 00898 00899 // Draw the vertex 00900 glVertex3f ( 00901 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00902 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00903 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00904 ); 00905 // DEBUG: 00906 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 00907 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 00908 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 00909 //std::cout << "\n"; 00910 halfEdgePtr = halfEdgePtr->Next(); 00911 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00912 //std::cout << "\n"; 00913 //} 00914 glEnd(); 00915 facePtr = facePtr->Next(); 00916 } 00917 00918 #endif//TAPs_USE_DATA_POOL__ 00919 00922 //for ( int i = 0; i < m_iNoFaces; i++ ) 00923 //{ 00924 // glBegin( drawMode ); 00925 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00926 // { 00927 // // Draw texture 00928 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00929 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00930 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00931 // } 00932 // // Normal of the vertex 00933 // glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 00934 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 00935 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 00936 // // Draw the vertex 00937 // glVertex3f ( 00938 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00939 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00940 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00941 // } 00942 // glEnd(); 00943 //} 00945 } 00946 00947 glPopAttrib(); 00948 00949 // Draw Boundary 00950 //if ( drawMode == OpenGL::Enum::POLYGON_WITH_WIRE_FRAME ) { 00951 //if ( true ) { 00952 // glColor3f( 1.0f, 0.0f, 0.0f ); 00953 // glDisable( GL_LIGHTING ); 00954 // glBegin( GL_LINES ); 00955 // HEFace<T> *facePtr = m_listFace->Head(); 00956 // HEHalfEdge<T> *halfEdgePtr; 00957 // while ( facePtr != NULL ) { 00958 // halfEdgePtr = facePtr->IncidentHalfEdge(); 00959 // do { 00960 // if ( !halfEdgePtr->Pair() ) { 00961 // // Draw the vertex 00962 // glVertex3f ( 00963 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00964 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00965 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00966 // ); 00967 // glVertex3f ( 00968 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 00969 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 00970 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 00971 // ); 00972 // } 00973 // halfEdgePtr = halfEdgePtr->Next(); 00974 // } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00975 // facePtr = facePtr->Next(); 00976 // } 00977 // glEnd(); 00978 // glEnable( GL_LIGHTING ); 00979 //} 00980 00981 // Draw Boundary 00982 if ( true ) { 00983 glColor3f( 1.0f, 0.0f, 0.0f ); 00984 glPushAttrib( GL_LIGHTING_BIT ); 00985 glDisable( GL_LIGHTING ); 00986 glBegin( GL_LINES ); 00987 if ( m_listHoleFace != NULL ) { 00988 HEFace<T> *facePtr = m_listHoleFace->Head(); 00989 HEHalfEdge<T> *halfEdgePtr; 00990 while ( facePtr != NULL ) { 00991 halfEdgePtr = facePtr->IncidentHalfEdge(); 00992 do { 00993 //if ( halfEdgePtr && halfEdgePtr->Next() ) { 00994 // Draw the vertex 00995 glVertex3f ( 00996 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00997 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00998 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00999 ); 01000 glVertex3f ( 01001 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 01002 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 01003 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 01004 ); 01005 //} 01006 halfEdgePtr = halfEdgePtr->Next(); 01007 } while ( halfEdgePtr && halfEdgePtr != facePtr->IncidentHalfEdge() ); 01008 facePtr = facePtr->Next(); 01009 } 01010 } 01011 glEnd(); 01012 //glEnable( GL_LIGHTING ); 01013 glPopAttrib(); 01014 } 01015 01016 if ( bIsDisplayVertexNormals ) { 01017 glColor3ub( 75, 200, 100 ); 01018 glPushAttrib( GL_LIGHTING_BIT ); 01019 glDisable( GL_LIGHTING ); 01020 //HEVertex<T> * pVertex = GetVertexList(); 01021 HEVertex<T> * pVertex = m_listVertex->Head(); 01022 while ( pVertex ) { 01023 Fn::Draw3DLine( pVertex->GetPosition(), pVertex->GetPosition() + pVertex->GetNormal() ); 01024 pVertex = pVertex->Next(); 01025 } 01026 //glEnable( GL_LIGHTING ); 01027 glPopAttrib(); 01028 } 01029 01030 01031 //DrawGLParticleRef(); 01032 //DrawGLVertexRing1(); 01033 //DrawGLSpringConnections(); 01034 //DrawGLSprings(); 01035 01036 01037 //DrawGLHalfEdges(); 01038 01039 // Draw AABB Bounding Box 01040 //DrawBoundingAABB(); 01041 //DrawBoundingEllipsoid(); 01042 //DrawBoundingSphere(); 01043 //---------------------------------------------------------------- 01044 #ifdef TAPs_USE_DATA_POOL 01045 glPopClientAttrib(); 01046 #endif//TAPs_USE_DATA_POOL 01047 } 01048 //----------------------------------------------------------------------------- 01049 template <typename T> 01050 bool OpenGLSpringHalfEdgeModel<T>::EnableVertexColors ( bool b ) 01051 { 01052 if ( m_svVertexColors.size() == 0 ) m_bEnableVertexColor = false; 01053 else m_bEnableVertexColor = b; 01054 return m_bEnableVertexColor; 01055 } 01056 //----------------------------------------------------------------------------- 01057 #endif//TAPs_ENABLE_FACE_VERTEX_COLOR 01058 //============================================================================= 01059 01060 01061 01062 01063 01064 01065 01066 01067 01068 01069 01070 01071 01072 //============================================================================= 01073 #ifdef TAPs_RENDER_BY_GLSL_DS_FACE_VERTEX 01074 //----------------------------------------------------------------------------- 01075 template <typename T> 01076 void OpenGLSpringHalfEdgeModel<T>::DrawGLSLWithDSFaceVertex_RGB ( GLenum drawMode ) 01077 { 01078 //assert( ShaderProgram ); 01079 GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->BeginGLSL(); 01080 GlobalGLSLShaderPool::SetShaderParameters( ShaderName ); 01081 01082 #ifdef TAPs_USE_DATA_POOL 01083 glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); 01084 #endif//TAPs_USE_DATA_POOL 01085 01086 glPushAttrib( GL_ENABLE_BIT | GL_ENABLE_BIT ); 01087 glEnable( GL_COLOR_MATERIAL ); 01088 01089 //---------------------------------------------------------------- 01090 if ( drawMode == OpenGL::Enum::POINT ) { 01091 01092 #ifdef TAPs_USE_DATA_POOL 01093 glEnableClientState( GL_VERTEX_ARRAY ); 01094 if ( typeid(T) == typeid(float) ) 01095 { 01096 glVertexPointer( 3, GL_FLOAT, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 01097 } 01098 else //if ( typeid(T) == typeid(double) ) 01099 { 01100 glVertexPointer( 3, GL_DOUBLE, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 01101 } 01102 glPointSize( 2 ); 01103 glDrawArrays( GL_POINTS, 0, GetArrayOfVertexPositions().GetSize() ); 01104 01105 #else //TAPs_USE_DATA_POOL 01106 HEVertex<T> *ptr = m_listVertex->Head(); 01107 glBegin( drawMode ); 01108 while ( ptr != NULL ) { 01109 // Draw the vertex 01110 glVertex3f ( 01111 static_cast<float>( (*ptr)[0] ), 01112 static_cast<float>( (*ptr)[1] ), 01113 static_cast<float>( (*ptr)[2] ) ); 01114 ptr = ptr->Next(); 01115 } 01116 glEnd(); 01117 01118 #endif//TAPs_USE_DATA_POOL 01119 } 01120 else if ( isFacetShading ) { 01121 // Draw the object 01122 //glEnable( GL_TEXTURE_2D ); 01123 HEFace<T> *facePtr = m_listFace->Head(); 01124 HEHalfEdge<T> *halfEdgePtr; 01125 //for ( int f = 0; f < GetNoFaces(); ++f ) { 01126 while ( facePtr != NULL ) { 01127 01128 /* 01129 // Submaterial supported by .ASE 01130 #ifdef TAPs_SUPPORT_ASE_FORMAT 01131 int matID = facePtr->GetMaterialID(); 01132 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 01133 this->submaterials[ matID ]->ApplyMaterial(); 01134 } 01135 #endif//TAPs_SUPPORT_ASE_FORMAT 01136 //*/ 01137 01138 halfEdgePtr = facePtr->IncidentHalfEdge(); 01139 int j = 0; 01140 glBegin( drawMode ); 01141 //for ( int i = 0; i < 3; ++i ) { 01142 do { 01144 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01145 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01146 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01147 //} 01148 // Normal of the face 01149 glNormal3f ( 01150 static_cast<float>( facePtr->GetNormal()[0] ), 01151 static_cast<float>( facePtr->GetNormal()[1] ), 01152 static_cast<float>( facePtr->GetNormal()[2] ) 01153 ); 01154 01155 /* 01156 // Vertex color of the face 01157 float VC[3]; 01158 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2] ); 01159 glColor3f ( VC[0], VC[1], VC[2] ); 01160 //*/ 01161 01162 // Draw the vertex 01163 glVertex3f ( 01164 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01165 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01166 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01167 ); 01168 // DEBUG: 01169 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 01170 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 01171 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 01172 //std::cout << "\n"; 01173 halfEdgePtr = halfEdgePtr->Next(); 01174 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01175 //std::cout << "\n"; 01176 //} 01177 glEnd(); 01178 facePtr = facePtr->Next(); 01179 } 01180 01181 // Draw the object 01182 //for ( int i = 0; i < m_iNoFaces; i++ ) 01183 //{ 01184 // glBegin( drawMode ); 01185 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 01186 // { 01187 // // Draw texture 01188 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01189 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01190 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01191 // } 01192 // // Normal of the face 01193 // //glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 01194 // // static_cast<float>( m_prFace[i].GetNormal()[1] ), 01195 // // static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 01196 // // Draw the vertex 01197 // glVertex3f ( 01198 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 01199 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 01200 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 01201 // } 01202 // glEnd(); 01203 //} 01205 } 01206 else { 01207 // Draw the object 01208 01209 #ifdef TAPs_USE_DATA_POOL__ 01210 #else //TAPs_USE_DATA_POOL__ 01211 01212 //glEnable( GL_TEXTURE_2D ); 01213 HEFace<T> *facePtr = m_listFace->Head(); 01214 HEHalfEdge<T> *halfEdgePtr; 01215 //for ( int f = 0; f < GetNoFaces(); ++f ) { 01216 while ( facePtr != NULL ) { 01217 01218 /* 01219 // Submaterial supported by .ASE 01220 #ifdef TAPs_SUPPORT_ASE_FORMAT 01221 int matID = facePtr->GetMaterialID(); 01222 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 01223 this->submaterials[ matID ]->ApplyMaterial(); 01224 } 01225 #endif//TAPs_SUPPORT_ASE_FORMAT 01226 //*/ 01227 01228 halfEdgePtr = facePtr->IncidentHalfEdge(); 01229 int j = 0; 01230 glBegin( drawMode ); 01231 //for ( int i = 0; i < 3; ++i ) { 01232 do { 01234 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01235 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01236 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01237 //} 01239 glNormal3f ( 01240 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[0] ), 01241 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[1] ), 01242 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[2] ) 01243 ); 01244 01245 /* 01246 // Vertex color of the face 01247 float VC[3]; 01248 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2] ); 01249 glColor3f ( VC[0], VC[1], VC[2] ); 01250 //*/ 01251 01252 // Draw the vertex 01253 glVertex3f ( 01254 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01255 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01256 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01257 ); 01258 // DEBUG: 01259 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 01260 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 01261 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 01262 //std::cout << "\n"; 01263 halfEdgePtr = halfEdgePtr->Next(); 01264 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01265 //std::cout << "\n"; 01266 //} 01267 glEnd(); 01268 facePtr = facePtr->Next(); 01269 } 01270 01271 #endif//TAPs_USE_DATA_POOL__ 01272 01275 //for ( int i = 0; i < m_iNoFaces; i++ ) 01276 //{ 01277 // glBegin( drawMode ); 01278 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 01279 // { 01280 // // Draw texture 01281 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01282 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01283 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01284 // } 01285 // // Normal of the vertex 01286 // glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 01287 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 01288 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 01289 // // Draw the vertex 01290 // glVertex3f ( 01291 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 01292 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 01293 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 01294 // } 01295 // glEnd(); 01296 //} 01298 } 01299 01300 glPopAttrib(); 01301 01302 // Draw Boundary 01303 //if ( drawMode == OpenGL::Enum::POLYGON_WITH_WIRE_FRAME ) { 01304 //if ( true ) { 01305 // glColor3f( 1.0f, 0.0f, 0.0f ); 01306 // glDisable( GL_LIGHTING ); 01307 // glBegin( GL_LINES ); 01308 // HEFace<T> *facePtr = m_listFace->Head(); 01309 // HEHalfEdge<T> *halfEdgePtr; 01310 // while ( facePtr != NULL ) { 01311 // halfEdgePtr = facePtr->IncidentHalfEdge(); 01312 // do { 01313 // if ( !halfEdgePtr->Pair() ) { 01314 // // Draw the vertex 01315 // glVertex3f ( 01316 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01317 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01318 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01319 // ); 01320 // glVertex3f ( 01321 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 01322 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 01323 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 01324 // ); 01325 // } 01326 // halfEdgePtr = halfEdgePtr->Next(); 01327 // } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01328 // facePtr = facePtr->Next(); 01329 // } 01330 // glEnd(); 01331 // glEnable( GL_LIGHTING ); 01332 //} 01333 01334 // Draw Boundary 01335 if ( true ) { 01336 glColor3f( 1.0f, 0.0f, 0.0f ); 01337 glPushAttrib( GL_LIGHTING_BIT ); 01338 glDisable( GL_LIGHTING ); 01339 glBegin( GL_LINES ); 01340 if ( m_listHoleFace != NULL ) { 01341 HEFace<T> *facePtr = m_listHoleFace->Head(); 01342 HEHalfEdge<T> *halfEdgePtr; 01343 while ( facePtr != NULL ) { 01344 halfEdgePtr = facePtr->IncidentHalfEdge(); 01345 do { 01346 //if ( halfEdgePtr && halfEdgePtr->Next() ) { 01347 // Draw the vertex 01348 glVertex3f ( 01349 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01350 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01351 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01352 ); 01353 glVertex3f ( 01354 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 01355 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 01356 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 01357 ); 01358 //} 01359 halfEdgePtr = halfEdgePtr->Next(); 01360 } while ( halfEdgePtr && halfEdgePtr != facePtr->IncidentHalfEdge() ); 01361 facePtr = facePtr->Next(); 01362 } 01363 } 01364 glEnd(); 01365 //glEnable( GL_LIGHTING ); 01366 glPopAttrib(); 01367 } 01368 01369 if ( bIsDisplayVertexNormals ) { 01370 glColor3ub( 75, 200, 100 ); 01371 glPushAttrib( GL_LIGHTING_BIT ); 01372 glDisable( GL_LIGHTING ); 01373 //HEVertex<T> * pVertex = GetVertexList(); 01374 HEVertex<T> * pVertex = m_listVertex->Head(); 01375 while ( pVertex ) { 01376 Fn::Draw3DLine( pVertex->GetPosition(), pVertex->GetPosition() + pVertex->GetNormal() ); 01377 pVertex = pVertex->Next(); 01378 } 01379 //glEnable( GL_LIGHTING ); 01380 glPopAttrib(); 01381 } 01382 01383 01384 //DrawGLParticleRef(); 01385 //DrawGLVertexRing1(); 01386 //DrawGLSpringConnections(); 01387 //DrawGLSprings(); 01388 01389 01390 //DrawGLHalfEdges(); 01391 01392 // Draw AABB Bounding Box 01393 //DrawBoundingAABB(); 01394 //DrawBoundingEllipsoid(); 01395 //DrawBoundingSphere(); 01396 //---------------------------------------------------------------- 01397 #ifdef TAPs_USE_DATA_POOL 01398 glPopClientAttrib(); 01399 #endif//TAPs_USE_DATA_POOL 01400 01401 GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->EndGLSL(); 01402 } 01403 //----------------------------------------------------------------------------- 01404 template <typename T> 01405 void OpenGLSpringHalfEdgeModel<T>::DrawGLSLWithDSFaceVertex_RGBA ( GLenum drawMode ) 01406 { 01407 //assert( ShaderProgram ); 01408 GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->BeginGLSL(); 01409 GlobalGLSLShaderPool::SetShaderParameters( ShaderName ); 01410 01411 #ifdef TAPs_USE_DATA_POOL 01412 glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); 01413 #endif//TAPs_USE_DATA_POOL 01414 01415 glPushAttrib( GL_ENABLE_BIT | GL_ENABLE_BIT ); 01416 glEnable( GL_COLOR_MATERIAL ); 01417 01418 //---------------------------------------------------------------- 01419 if ( drawMode == OpenGL::Enum::POINT ) { 01420 01421 #ifdef TAPs_USE_DATA_POOL 01422 glEnableClientState( GL_VERTEX_ARRAY ); 01423 if ( typeid(T) == typeid(float) ) 01424 { 01425 glVertexPointer( 3, GL_FLOAT, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 01426 } 01427 else //if ( typeid(T) == typeid(double) ) 01428 { 01429 glVertexPointer( 3, GL_DOUBLE, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 01430 } 01431 glPointSize( 2 ); 01432 glDrawArrays( GL_POINTS, 0, GetArrayOfVertexPositions().GetSize() ); 01433 01434 #else //TAPs_USE_DATA_POOL 01435 HEVertex<T> *ptr = m_listVertex->Head(); 01436 glBegin( drawMode ); 01437 while ( ptr != NULL ) { 01438 // Draw the vertex 01439 glVertex3f ( 01440 static_cast<float>( (*ptr)[0] ), 01441 static_cast<float>( (*ptr)[1] ), 01442 static_cast<float>( (*ptr)[2] ) ); 01443 ptr = ptr->Next(); 01444 } 01445 glEnd(); 01446 01447 #endif//TAPs_USE_DATA_POOL 01448 } 01449 else if ( isFacetShading ) { 01450 // Draw the object 01451 //glEnable( GL_TEXTURE_2D ); 01452 HEFace<T> *facePtr = m_listFace->Head(); 01453 HEHalfEdge<T> *halfEdgePtr; 01454 //for ( int f = 0; f < GetNoFaces(); ++f ) { 01455 while ( facePtr != NULL ) { 01456 01457 /* 01458 // Submaterial supported by .ASE 01459 #ifdef TAPs_SUPPORT_ASE_FORMAT 01460 int matID = facePtr->GetMaterialID(); 01461 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 01462 this->submaterials[ matID ]->ApplyMaterial(); 01463 } 01464 #endif//TAPs_SUPPORT_ASE_FORMAT 01465 //*/ 01466 01467 halfEdgePtr = facePtr->IncidentHalfEdge(); 01468 int j = 0; 01469 glBegin( drawMode ); 01470 //for ( int i = 0; i < 3; ++i ) { 01471 do { 01473 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01474 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01475 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01476 //} 01477 // Normal of the face 01478 glNormal3f ( 01479 static_cast<float>( facePtr->GetNormal()[0] ), 01480 static_cast<float>( facePtr->GetNormal()[1] ), 01481 static_cast<float>( facePtr->GetNormal()[2] ) 01482 ); 01483 01484 /* 01485 // Vertex color of the face 01486 float VC[4]; 01487 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2], &VC[3] ); 01488 glColor4f ( VC[0], VC[1], VC[2], VC[3] ); 01489 //*/ 01490 01491 // Draw the vertex 01492 glVertex3f ( 01493 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01494 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01495 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01496 ); 01497 // DEBUG: 01498 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 01499 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 01500 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 01501 //std::cout << "\n"; 01502 halfEdgePtr = halfEdgePtr->Next(); 01503 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01504 //std::cout << "\n"; 01505 //} 01506 glEnd(); 01507 facePtr = facePtr->Next(); 01508 } 01509 01510 // Draw the object 01511 //for ( int i = 0; i < m_iNoFaces; i++ ) 01512 //{ 01513 // glBegin( drawMode ); 01514 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 01515 // { 01516 // // Draw texture 01517 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01518 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01519 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01520 // } 01521 // // Normal of the face 01522 // //glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 01523 // // static_cast<float>( m_prFace[i].GetNormal()[1] ), 01524 // // static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 01525 // // Draw the vertex 01526 // glVertex3f ( 01527 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 01528 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 01529 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 01530 // } 01531 // glEnd(); 01532 //} 01534 } 01535 else { 01536 // Draw the object 01537 01538 #ifdef TAPs_USE_DATA_POOL__ 01539 #else //TAPs_USE_DATA_POOL__ 01540 01541 //glEnable( GL_TEXTURE_2D ); 01542 HEFace<T> *facePtr = m_listFace->Head(); 01543 HEHalfEdge<T> *halfEdgePtr; 01544 //for ( int f = 0; f < GetNoFaces(); ++f ) { 01545 while ( facePtr != NULL ) { 01546 01547 /* 01548 // Submaterial supported by .ASE 01549 #ifdef TAPs_SUPPORT_ASE_FORMAT 01550 int matID = facePtr->GetMaterialID(); 01551 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 01552 this->submaterials[ matID ]->ApplyMaterial(); 01553 } 01554 #endif//TAPs_SUPPORT_ASE_FORMAT 01555 //*/ 01556 01557 halfEdgePtr = facePtr->IncidentHalfEdge(); 01558 int j = 0; 01559 glBegin( drawMode ); 01560 //for ( int i = 0; i < 3; ++i ) { 01561 do { 01563 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01564 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01565 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01566 //} 01568 glNormal3f ( 01569 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[0] ), 01570 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[1] ), 01571 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[2] ) 01572 ); 01573 01574 /* 01575 // Vertex color of the face 01576 float VC[4]; 01577 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2], &VC[3] ); 01578 glColor4f ( VC[0], VC[1], VC[2], VC[3] ); 01579 //*/ 01580 01581 // Draw the vertex 01582 glVertex3f ( 01583 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01584 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01585 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01586 ); 01587 // DEBUG: 01588 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 01589 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 01590 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 01591 //std::cout << "\n"; 01592 halfEdgePtr = halfEdgePtr->Next(); 01593 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01594 //std::cout << "\n"; 01595 //} 01596 glEnd(); 01597 facePtr = facePtr->Next(); 01598 } 01599 01600 #endif//TAPs_USE_DATA_POOL__ 01601 01604 //for ( int i = 0; i < m_iNoFaces; i++ ) 01605 //{ 01606 // glBegin( drawMode ); 01607 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 01608 // { 01609 // // Draw texture 01610 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01611 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01612 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01613 // } 01614 // // Normal of the vertex 01615 // glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 01616 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 01617 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 01618 // // Draw the vertex 01619 // glVertex3f ( 01620 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 01621 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 01622 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 01623 // } 01624 // glEnd(); 01625 //} 01627 } 01628 01629 glPopAttrib(); 01630 01631 // Draw Boundary 01632 //if ( drawMode == OpenGL::Enum::POLYGON_WITH_WIRE_FRAME ) { 01633 //if ( true ) { 01634 // glColor3f( 1.0f, 0.0f, 0.0f ); 01635 // glDisable( GL_LIGHTING ); 01636 // glBegin( GL_LINES ); 01637 // HEFace<T> *facePtr = m_listFace->Head(); 01638 // HEHalfEdge<T> *halfEdgePtr; 01639 // while ( facePtr != NULL ) { 01640 // halfEdgePtr = facePtr->IncidentHalfEdge(); 01641 // do { 01642 // if ( !halfEdgePtr->Pair() ) { 01643 // // Draw the vertex 01644 // glVertex3f ( 01645 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01646 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01647 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01648 // ); 01649 // glVertex3f ( 01650 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 01651 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 01652 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 01653 // ); 01654 // } 01655 // halfEdgePtr = halfEdgePtr->Next(); 01656 // } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01657 // facePtr = facePtr->Next(); 01658 // } 01659 // glEnd(); 01660 // glEnable( GL_LIGHTING ); 01661 //} 01662 01663 // Draw Boundary 01664 if ( true ) { 01665 glColor3f( 1.0f, 0.0f, 0.0f ); 01666 glPushAttrib( GL_LIGHTING_BIT ); 01667 glDisable( GL_LIGHTING ); 01668 glBegin( GL_LINES ); 01669 if ( m_listHoleFace != NULL ) { 01670 HEFace<T> *facePtr = m_listHoleFace->Head(); 01671 HEHalfEdge<T> *halfEdgePtr; 01672 while ( facePtr != NULL ) { 01673 halfEdgePtr = facePtr->IncidentHalfEdge(); 01674 do { 01675 //if ( halfEdgePtr && halfEdgePtr->Next() ) { 01676 // Draw the vertex 01677 glVertex3f ( 01678 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01679 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01680 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01681 ); 01682 glVertex3f ( 01683 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 01684 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 01685 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 01686 ); 01687 //} 01688 halfEdgePtr = halfEdgePtr->Next(); 01689 } while ( halfEdgePtr && halfEdgePtr != facePtr->IncidentHalfEdge() ); 01690 facePtr = facePtr->Next(); 01691 } 01692 } 01693 glEnd(); 01694 //glEnable( GL_LIGHTING ); 01695 glPopAttrib(); 01696 } 01697 01698 if ( bIsDisplayVertexNormals ) { 01699 glColor3ub( 75, 200, 100 ); 01700 glPushAttrib( GL_LIGHTING_BIT ); 01701 glDisable( GL_LIGHTING ); 01702 //HEVertex<T> * pVertex = GetVertexList(); 01703 HEVertex<T> * pVertex = m_listVertex->Head(); 01704 while ( pVertex ) { 01705 Fn::Draw3DLine( pVertex->GetPosition(), pVertex->GetPosition() + pVertex->GetNormal() ); 01706 pVertex = pVertex->Next(); 01707 } 01708 //glEnable( GL_LIGHTING ); 01709 glPopAttrib(); 01710 } 01711 01712 01713 //DrawGLParticleRef(); 01714 //DrawGLVertexRing1(); 01715 //DrawGLSpringConnections(); 01716 //DrawGLSprings(); 01717 01718 01719 //DrawGLHalfEdges(); 01720 01721 // Draw AABB Bounding Box 01722 //DrawBoundingAABB(); 01723 //DrawBoundingEllipsoid(); 01724 //DrawBoundingSphere(); 01725 //---------------------------------------------------------------- 01726 #ifdef TAPs_USE_DATA_POOL 01727 glPopClientAttrib(); 01728 #endif//TAPs_USE_DATA_POOL 01729 01730 GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->EndGLSL(); 01731 } 01732 //----------------------------------------------------------------------------- 01733 #endif//TAPs_ENABLE_FACE_VERTEX_COLOR 01734 //============================================================================= 01735 01736 01737 01738 01739 01740 01741 01742 01743 01744 01745 01746 01747 01748 01749 01750 01751 01752 01753 01754 01755 01756 01757 01758 //----------------------------------------------------------------------------- 01759 // DEBUG 01760 template <typename T> 01761 void OpenGLSpringHalfEdgeModel<T>::DrawGLParticleRef () 01762 { 01763 /* 01764 if ( !m_listParticleRef.empty() ) { 01765 std::list< ParticleRef<T> >::iterator pos = m_listParticleRef.begin(); 01766 glPushAttrib( GL_CURRENT_BIT | GL_LIGHTING_BIT ); 01767 glDisable( GL_LIGHTING ); 01768 glColor3f( 0, 1, 0 ); 01769 glPointSize( 2 ); 01770 glPushMatrix(); 01771 glBegin( GL_POINTS ); 01772 while ( pos != m_listParticleRef.end() ) { 01773 glVertex3f( pos->GetPosition()[0], 01774 pos->GetPosition()[1], 01775 pos->GetPosition()[2] ); 01776 ++pos; 01777 } 01778 glEnd(); 01779 glPopMatrix(); 01780 glPopAttrib(); 01781 } 01782 //*/ 01783 if ( !m_vpParticleRef.empty() ) { 01784 glPushAttrib( GL_CURRENT_BIT | GL_LIGHTING_BIT ); 01785 glDisable( GL_LIGHTING ); 01786 glColor3f( 0, 1, 0 ); 01787 glPointSize( 2 ); 01788 glPushMatrix(); 01789 glBegin( GL_POINTS ); 01790 for ( int i = 0; i < static_cast<int>( m_vpParticleRef.size() ); ++i ) { 01791 glVertex3f( m_vpParticleRef[i]->GetPosition()[0], 01792 m_vpParticleRef[i]->GetPosition()[1], 01793 m_vpParticleRef[i]->GetPosition()[2] ); 01794 } 01795 glEnd(); 01796 glPopMatrix(); 01797 glPopAttrib(); 01798 } 01799 } 01800 //----------------------------------------------------------------------------- 01801 // DEBUG 01802 template <typename T> 01803 void OpenGLSpringHalfEdgeModel<T>::DrawGLVertexRing1 () 01804 { 01805 glPushAttrib( GL_CURRENT_BIT | GL_LIGHTING_BIT ); 01806 glDisable( GL_LIGHTING ); 01807 glColor3f( 0, 0.5, 1 ); 01808 glLineWidth( 1 ); 01809 glPushMatrix(); 01810 glBegin( GL_LINES ); 01811 for ( int i = 0; i < static_cast<int>( m_vpHEVertex.size() ); ++i ) { 01812 int k; 01813 for ( int j = 0; j < static_cast<int>( m_pviListVertexRing1[i].size() ); ++j ) { 01814 glVertex3f( m_vpHEVertex[i]->GetPosition()[0], 01815 m_vpHEVertex[i]->GetPosition()[1], 01816 m_vpHEVertex[i]->GetPosition()[2] ); 01817 k = m_pviListVertexRing1[i][j]; 01818 glVertex3f( m_vpHEVertex[k]->GetPosition()[0], 01819 m_vpHEVertex[k]->GetPosition()[1], 01820 m_vpHEVertex[k]->GetPosition()[2] ); 01821 } 01822 } 01823 glEnd(); 01824 glPopMatrix(); 01825 glPopAttrib(); 01826 } 01827 //----------------------------------------------------------------------------- 01828 // DEBUG 01829 template <typename T> 01830 void OpenGLSpringHalfEdgeModel<T>::DrawGLSpringConnections () 01831 { 01832 for ( int i = 0; i < static_cast<int>( m_vpSpringRef.size() ); ++i ) { 01833 glPushAttrib( GL_CURRENT_BIT | GL_LIGHTING_BIT ); 01834 glDisable( GL_LIGHTING ); 01835 glColor3f( 0, 0.5, 1 ); 01836 glLineWidth( 1 ); 01837 glPushMatrix(); 01838 glBegin( GL_LINES ); 01839 glVertex3f( m_vpSpringRef[i]->GetParticleOne().GetPosition()[0], 01840 m_vpSpringRef[i]->GetParticleOne().GetPosition()[1], 01841 m_vpSpringRef[i]->GetParticleOne().GetPosition()[2] ); 01842 glVertex3f( m_vpSpringRef[i]->GetParticleTwo().GetPosition()[0], 01843 m_vpSpringRef[i]->GetParticleTwo().GetPosition()[1], 01844 m_vpSpringRef[i]->GetParticleTwo().GetPosition()[2] ); 01845 glEnd(); 01846 glPopMatrix(); 01847 glPopAttrib(); 01848 } 01849 } 01850 //----------------------------------------------------------------------------- 01851 // DEBUG 01852 template <typename T> 01853 void OpenGLSpringHalfEdgeModel<T>::DrawGLSprings () 01854 { 01855 for ( int i = 0; i < static_cast<int>( m_vpSpringRef.size() ); ++i ) { 01856 m_vpSpringRef[i]->DrawByOpenGL( ); 01857 } 01858 } 01859 //----------------------------------------------------------------------------- 01860 //============================================================================= 01861 END_NAMESPACE_TAPs__OpenGL 01862 //----------------------------------------------------------------------------- 01863 //345678901234567890123456789012345678901234567890123456789012345678901234567890 01864 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8