#include <TAPsOpenGLPNTriangleModel.hpp>


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