![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsOpenGLBox.cpp 00003 00004 An OpenGL Box 00005 00006 SUKITTI PUNAK (10/07/2004) 00007 UPDATE (10/07/2004) 00008 ******************************************************************************/ 00009 #include "TAPsOpenGLBox.hpp" 00010 // Using Inclusion Model (i.e. definitions are included in declarations) 00011 // (this name.cpp is included in name.hpp) 00012 // Each friend is defined directly inside its declaration. 00013 00014 BEGIN_NAMESPACE_TAPs__OpenGL 00015 //============================================================================= 00016 //----------------------------------------------------------------------------- 00017 OpenGLBox::OpenGLBox 00018 ( Real xMin, Real xMax, Real yMin, Real yMax, Real zMin, Real zMax ) 00019 { 00020 // Set the eight points of this box 00021 // xMin is the left side from the center of the box 00022 // xMax is the right side from the center of the box 00023 // yMin is the bottom side from the center of the box 00024 // yMax is the top side from the center of the box 00025 // zMin is the far side from the center of the box 00026 // zMax is the near side from the center of the box 00027 // 4-------5 00028 // /| /| 00029 // / | / | 00030 // 3--+----2 | 00031 // | 7----+--6 00032 // | / | / 00033 // |/ |/ 00034 // 0-------1 00035 m_rPt[0][0] = xMin; m_rPt[0][1] = yMin; m_rPt[0][2] = zMax; 00036 m_rPt[1][0] = xMax; m_rPt[1][1] = yMin; m_rPt[1][2] = zMax; 00037 m_rPt[2][0] = xMax; m_rPt[2][1] = yMax; m_rPt[2][2] = zMax; 00038 m_rPt[3][0] = xMin; m_rPt[3][1] = yMax; m_rPt[3][2] = zMax; 00039 m_rPt[4][0] = xMin; m_rPt[4][1] = yMax; m_rPt[4][2] = zMin; 00040 m_rPt[5][0] = xMax; m_rPt[5][1] = yMax; m_rPt[5][2] = zMin; 00041 m_rPt[6][0] = xMax; m_rPt[6][1] = yMin; m_rPt[6][2] = zMin; 00042 m_rPt[7][0] = xMin; m_rPt[7][1] = yMin; m_rPt[7][2] = zMin; 00043 } 00044 //----------------------------------------------------------------------------- 00045 OpenGLBox::~OpenGLBox() 00046 {} 00047 //----------------------------------------------------------------------------- 00048 void OpenGLBox::DisplayGL( Enum::DrawMode DM ) 00049 { 00050 //int ptSize[1]; 00051 glColor3f( 1.0f, 1.0f, 1.0f ); 00052 00053 ApplyMaterial(); 00054 00055 // GL_QUAD_STRIP 00056 // V0-------V2-------V4-------V6 00057 // | | | | 00058 // | | | | 00059 // | | | | 00060 // V1-------V3-------V5-------V7 00061 glBegin( GL_QUAD_STRIP ); 00062 glVertex3f( m_rPt[0][0], m_rPt[0][1], m_rPt[0][2] ); // V0 00063 glVertex3f( m_rPt[1][0], m_rPt[1][1], m_rPt[1][2] ); // V1 00064 glVertex3f( m_rPt[3][0], m_rPt[3][1], m_rPt[3][2] ); // V2 00065 glVertex3f( m_rPt[2][0], m_rPt[2][1], m_rPt[2][2] ); // V3 00066 glVertex3f( m_rPt[4][0], m_rPt[4][1], m_rPt[4][2] ); // V4 00067 glVertex3f( m_rPt[5][0], m_rPt[5][1], m_rPt[5][2] ); // V5 00068 glVertex3f( m_rPt[7][0], m_rPt[7][1], m_rPt[7][2] ); // V6 00069 glVertex3f( m_rPt[6][0], m_rPt[6][1], m_rPt[6][2] ); // V7 00070 glEnd(); 00071 glBegin( GL_QUAD_STRIP ); 00072 glVertex3f( m_rPt[3][0], m_rPt[3][1], m_rPt[3][2] ); // V0 00073 glVertex3f( m_rPt[4][0], m_rPt[4][1], m_rPt[4][2] ); // V1 00074 glVertex3f( m_rPt[0][0], m_rPt[0][1], m_rPt[0][2] ); // V2 00075 glVertex3f( m_rPt[7][0], m_rPt[7][1], m_rPt[7][2] ); // V3 00076 glVertex3f( m_rPt[1][0], m_rPt[1][1], m_rPt[1][2] ); // V4 00077 glVertex3f( m_rPt[6][0], m_rPt[6][1], m_rPt[6][2] ); // V5 00078 glVertex3f( m_rPt[2][0], m_rPt[2][1], m_rPt[2][2] ); // V6 00079 glVertex3f( m_rPt[5][0], m_rPt[5][1], m_rPt[5][2] ); // V7 00080 glEnd(); 00081 00082 /* 00083 switch (DM) { 00084 // Draw Points 00085 case OpenGL::POINT: 00086 // Set Point Size 00087 //glGetIntegerv( GL_POINT_SIZE, ptSize ); 00088 //glPointSize( 2 ); 00089 glBegin( GL_POINTS ); 00090 for ( m = 0; m < m_iNoRows; m++ ) { 00091 for ( n = 0; n < m_iNoCols; n++ ) { 00092 glVertex3f( m_pcParticle[m][n]->m_vtPosit[0], 00093 m_pcParticle[m][n]->m_vtPosit[1], 00094 m_pcParticle[m][n]->m_vtPosit[2] ); 00095 } 00096 } 00097 glEnd(); 00098 // Restore Point Size 00099 //glPointSize( ptSize[0] ); 00100 break; 00101 00102 // Draw Wire Frame 00103 case OpenGL::WIRE_FRAME: 00104 // Draw Row Lines 00105 for ( m = 0; m < m_iNoRows; m++ ) { 00106 glBegin( GL_LINE_STRIP ); 00107 for ( n = 0; n < m_iNoCols; n++ ) { 00108 glVertex3f( m_pcParticle[m][n]->m_vtPosit[0], 00109 m_pcParticle[m][n]->m_vtPosit[1], 00110 m_pcParticle[m][n]->m_vtPosit[2] ); 00111 } 00112 glEnd(); 00113 } 00114 // Draw Column Lines 00115 for ( n = 0; n < m_iNoCols; n++ ) { 00116 glBegin( GL_LINE_STRIP ); 00117 for ( m = 0; m < m_iNoRows; m++ ) { 00118 glVertex3f( m_pcParticle[m][n]->m_vtPosit[0], 00119 m_pcParticle[m][n]->m_vtPosit[1], 00120 m_pcParticle[m][n]->m_vtPosit[2] ); 00121 } 00122 glEnd(); 00123 } 00124 // Draw Diagonal Lines 00125 glBegin( GL_LINES ); 00126 for ( m = 0; m < m_iNoRows-1; m++ ) { 00127 for ( n = 0; n < m_iNoCols-1; n++ ) { 00128 // Draw a line from [m][n] --- [m+1][n+1] 00129 glVertex3f( m_pcParticle[m][n]->m_vtPosit[0], 00130 m_pcParticle[m][n]->m_vtPosit[1], 00131 m_pcParticle[m][n]->m_vtPosit[2] ); 00132 glVertex3f( m_pcParticle[m+1][n+1]->m_vtPosit[0], 00133 m_pcParticle[m+1][n+1]->m_vtPosit[1], 00134 m_pcParticle[m+1][n+1]->m_vtPosit[2] ); 00135 // Draw a line from [m+1][n] to [m][n+1] 00136 glVertex3f( m_pcParticle[m+1][n]->m_vtPosit[0], 00137 m_pcParticle[m+1][n]->m_vtPosit[1], 00138 m_pcParticle[m+1][n]->m_vtPosit[2] ); 00139 glVertex3f( m_pcParticle[m][n+1]->m_vtPosit[0], 00140 m_pcParticle[m][n+1]->m_vtPosit[1], 00141 m_pcParticle[m][n+1]->m_vtPosit[2] ); 00142 } 00143 } 00144 glEnd(); 00145 break; 00146 00147 // Draw Polygons 00148 case OpenGL::POLYGON: 00149 // With Texture 00150 if ( m_pcImg != NULL ) { 00151 00152 DrawTexture(); 00153 00154 float tr, tc; 00155 float trStep = 1.0 / (m_iNoRows-1); 00156 float tcStep = 1.0 / (m_iNoCols-1); 00157 for ( m = 0, tr = 1.0; m < m_iNoRows-1; m++, tr -= trStep ) { 00158 glBegin( GL_QUAD_STRIP ); 00159 for ( n = 0, tc = 0.0; n < m_iNoCols; n++, tc += tcStep ) { 00160 glTexCoord2f(tc, tr); 00161 glVertex3f( m_pcParticle[m][n]->m_vtPosit[0], 00162 m_pcParticle[m][n]->m_vtPosit[1], 00163 m_pcParticle[m][n]->m_vtPosit[2] ); 00164 glTexCoord2f(tc, tr-trStep); 00165 glVertex3f( m_pcParticle[m+1][n]->m_vtPosit[0], 00166 m_pcParticle[m+1][n]->m_vtPosit[1], 00167 m_pcParticle[m+1][n]->m_vtPosit[2] ); 00168 } 00169 glEnd(); 00170 } 00171 } 00172 // Without Texture 00173 else { 00174 for ( m = 0; m < m_iNoRows-1; m++ ) { 00175 glBegin( GL_QUAD_STRIP ); 00176 for ( n = 0; n < m_iNoCols; n++ ) { 00177 glVertex3f( m_pcParticle[m][n]->m_vtPosit[0], 00178 m_pcParticle[m][n]->m_vtPosit[1], 00179 m_pcParticle[m][n]->m_vtPosit[2] ); 00180 glVertex3f( m_pcParticle[m+1][n]->m_vtPosit[0], 00181 m_pcParticle[m+1][n]->m_vtPosit[1], 00182 m_pcParticle[m+1][n]->m_vtPosit[2] ); 00183 } 00184 glEnd(); 00185 } 00186 } 00187 break; 00188 } 00189 00190 // TEST 00191 //DisplayGL_ParticleNormals(); 00192 glDisable( GL_LIGHTING ); 00193 glColor3f( 0.0f, 1.0f, 0.0f ); 00194 glPointSize( 7 ); 00195 m = 0; n = 0; 00196 glBegin( GL_POINTS ); 00197 glVertex3f( m_pcParticle[m][n]->m_vtPosit[0], 00198 m_pcParticle[m][n]->m_vtPosit[1], 00199 m_pcParticle[m][n]->m_vtPosit[2] ); 00200 glEnd(); 00201 glColor3f( 0.0f, 1.0f, 1.0f ); 00202 glPointSize( 5 ); 00203 m = 0; n = 1; 00204 glBegin( GL_POINTS ); 00205 glVertex3f( m_pcParticle[m][n]->m_vtPosit[0], 00206 m_pcParticle[m][n]->m_vtPosit[1], 00207 m_pcParticle[m][n]->m_vtPosit[2] ); 00208 glEnd(); 00209 glPointSize( 1 ); 00210 glEnable( GL_LIGHTING ); 00211 */ 00212 } 00213 //----------------------------------------------------------------------------- 00214 //============================================================================= 00215 END_NAMESPACE_TAPs__OpenGL 00216 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00217 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8