Ignore:
Timestamp:
02/19/07 09:16:59 (17 years ago)
Author:
gumbau
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp

    r2090 r2127  
    55using   namespace       std; 
    66 
    7 //--------------------------------------------------------------------------- 
     7//------------------------------------------------------------------------- 
    88//      Handle events. 
    9 //--------------------------------------------------------------------------- 
     9//------------------------------------------------------------------------- 
    1010int     GeoMeshView::handle(int event) 
    1111{ 
     
    3333                case    fltk::DRAG: 
    3434                         
    35                         button  =       fltk::event_state(); 
     35                        button  =       fltk::event_key(); 
    3636                        x                               =       fltk::event_x(); 
    3737                        y                               =       fltk::event_y(); 
    3838                         
     39 
    3940                        switch (button) 
    4041                        { 
    4142                                //      Button 1 Pushed. 
    42                                 case    0x01100000: 
     43                                case    1: 
    4344                         
    4445                                        if (x > mMouseX) 
     
    104105                                        return  1; 
    105106                                 
    106                                 case    0x04100000: 
     107                                //      Button 3 pushed. 
     108                                case    2: 
     109                                case    3: 
    107110 
    108111                                        if (y   > mSizeY) 
     
    124127                                        return 1; 
    125128 
    126                         }                        
     129                        } 
    127130                         
    128131                case    fltk::MOUSEWHEEL: 
     
    172175} 
    173176 
    174 //--------------------------------------------------------------------------- 
     177//------------------------------------------------------------------------- 
    175178//      Enable color strips. 
    176 //--------------------------------------------------------------------------- 
     179//------------------------------------------------------------------------- 
    177180void    GeoMeshView::enableColorStrips() 
    178181{ 
     
    180183} 
    181184 
    182 //--------------------------------------------------------------------------- 
     185//------------------------------------------------------------------------- 
    183186//      Disable color strips. 
    184 //--------------------------------------------------------------------------- 
     187//------------------------------------------------------------------------- 
    185188void    GeoMeshView::disableColorStrips() 
    186189{ 
     
    188191} 
    189192 
    190 //--------------------------------------------------------------------------- 
     193//------------------------------------------------------------------------- 
    191194//      Gets the color strips state. 
    192 //--------------------------------------------------------------------------- 
     195//------------------------------------------------------------------------- 
    193196bool    GeoMeshView::getColorStrips() 
    194197{ 
     
    196199} 
    197200 
    198 //--------------------------------------------------------------------------- 
     201//------------------------------------------------------------------------- 
    199202//      Set the color to the submesh sumbmeshIndex 
    200 //--------------------------------------------------------------------------- 
     203//------------------------------------------------------------------------- 
    201204void    GeoMeshView::setSubMeshSelected(int submeshIndex) 
    202205{ 
     
    204207} 
    205208 
    206 //--------------------------------------------------------------------------- 
     209//------------------------------------------------------------------------- 
    207210//      Sets the leaves submesh index. 
    208 //--------------------------------------------------------------------------- 
     211//------------------------------------------------------------------------- 
    209212void    GeoMeshView::setLeavesSubMesh(int submeshIndex) 
    210213{ 
     
    212215} 
    213216 
    214 //--------------------------------------------------------------------------- 
     217//------------------------------------------------------------------------- 
    215218//      Gets the leaves submesh index. 
    216 //--------------------------------------------------------------------------- 
     219//------------------------------------------------------------------------- 
    217220int     GeoMeshView::getLeavesSubMesh() 
    218221{ 
     
    220223} 
    221224 
    222 //--------------------------------------------------------------------------- 
     225//------------------------------------------------------------------------- 
    223226//      Set the list of strip colors. 
    224 //--------------------------------------------------------------------------- 
     227//------------------------------------------------------------------------- 
    225228void    GeoMeshView::setStripColors() 
    226229{ 
     
    253256                } 
    254257        } 
    255  
    256258         
    257259        //      Sets random colors to each strip. 
    258260        for (int submesh        = 0; submesh < geoMesh->mSubMeshCount; submesh++) 
    259         { 
     261        {        
    260262                //      Gets the actual submesh. 
    261263                geosubmesh      =       &geoMesh->mSubMesh[submesh]; 
     
    265267                        for     (int strip = 0; strip   <       geosubmesh->mStripCount; strip++) 
    266268                        { 
    267                                 mStripColors[submesh][strip].r  =       rand()/((float)RAND_MAX); 
    268                                 mStripColors[submesh][strip].g  =       rand()/((float)RAND_MAX); 
    269                                 mStripColors[submesh][strip].b  =       rand()/((float)RAND_MAX); 
     269                                mStripColors[submesh][strip].r  =       (0.6 * rand() + 0.4 * (float)RAND_MAX)/((float)RAND_MAX); 
     270                                mStripColors[submesh][strip].g  =       (0.6 * rand() + 0.4 * (float)RAND_MAX)/((float)RAND_MAX); 
     271                                mStripColors[submesh][strip].b  =       (0.6 * rand() + 0.4 * (float)RAND_MAX)/((float)RAND_MAX); 
    270272                        } 
    271273                } 
     
    276278} 
    277279 
    278 /* 
    279 //--------------------------------------------------------------------------- 
     280//------------------------------------------------------------------------- 
    280281//      Get the bounding box of the object. 
    281 //--------------------------------------------------------------------------- 
    282 GeometryBounds  GeoMeshView::getBoundingBox() 
    283 { 
    284         SubMesh                                 *geosubmesh; 
    285         Index                                           position; 
    286         Vector3                                 vector3; 
    287         GeometryBounds  bounds; 
    288         float                                           x,y,z; 
    289         float                                           xMin,yMin,zMin; 
    290         float                                           xMax,yMax,zMax; 
    291                  
    292         //      For each submesh. 
    293         for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 
    294         { 
    295                 //      Gets the actual submesh. 
    296                 geosubmesh      =       &geoMesh->mSubMesh[submesh]; 
    297  
    298                 //      For each index of the strip. 
    299                 for (int index = 0; index < geosubmesh->mIndexCount; index++) 
    300                 { 
    301                         position        =       geosubmesh->mIndex[index]; 
    302  
    303                         //      Gets the vertex coordinates. 
    304                         vector3 =       geosubmesh->mVertexBuffer->mPosition[position]; 
    305                                  
    306                         x                                       =       vector3[0]; 
    307                         y                                       =       vector3[1]; 
    308                         z                                       =       vector3[2]; 
    309                                  
    310                         //      If is the first iteation. 
    311                         if ((submesh    == 0)   &&      (index  ==      0)) 
    312                         { 
    313                                 xMin    =       xMax    =       x; 
    314                                 yMin    =       yMax    =       y; 
    315                                 zMin    =       zMax    =       z; 
    316                         } 
    317                         else 
    318                         { 
    319                                 if (x < xMin) 
    320                                 { 
    321                                         xMin    =       x; 
    322                                 } 
    323                                 else if (x > xMax) 
    324                                 { 
    325                                         xMax    =       x; 
    326                                 } 
    327  
    328                                 if (y < yMin) 
    329                                 { 
    330                                         yMin    =       y; 
    331                                 } 
    332                                 else if (y > yMax) 
    333                                 { 
    334                                         yMax    =       y; 
    335                                 } 
    336  
    337                                 if (z < zMin) 
    338                                 { 
    339                                         zMin    =       z; 
    340                                 } 
    341                                 else if (z > zMax) 
    342                                 { 
    343                                         zMax    =       z; 
    344                                 } 
    345                         } 
    346                 } 
    347         } 
    348  
    349         xMed    =       (xMax + xMin)   /       2; 
    350         yMed    =       (yMax + yMin)   /       2; 
    351         zMed    =       (zMax + zMin)   /       2; 
    352  
    353  
    354         if ((xMax - xMin) > (yMax - yMin)) 
    355         { 
    356                 if ((xMax - xMin) > (zMax - zMin)) 
    357                 { 
    358                         mScaleFactor    =       xMax - xMin; 
    359                 } 
    360                 else 
    361                 { 
    362                         mScaleFactor    =       zMax - zMin; 
    363                 } 
    364         } 
    365         else 
    366         { 
    367                 if ((yMax - yMin) > (zMax - zMin)) 
    368                 { 
    369                         mScaleFactor    =       yMax - yMin; 
    370                 } 
    371                 else 
    372                 { 
    373                         mScaleFactor    =       zMax - zMin; 
    374                 } 
    375         } 
    376  
    377         //      Set the bounds. 
    378         bounds.minx             =       xMin; 
    379         bounds.miny             =       yMin; 
    380         bounds.minz             =       zMin; 
    381         bounds.maxx             =       xMax; 
    382         bounds.maxy             =       yMax; 
    383         bounds.maxz             =       zMax; 
    384         bounds.radius   =       mScaleFactor; 
    385  
    386         return  bounds; 
    387 } 
    388 */ 
    389  
    390 //--------------------------------------------------------------------------- 
     282//------------------------------------------------------------------------- 
     283void    GeoMeshView::getBoundingBox() 
     284{ 
     285        float   cx; 
     286        float   cy; 
     287        float   cz; 
     288        float   scale; 
     289 
     290        xMax    =       geoMesh->mMeshBounds.maxX; 
     291        yMax    =       geoMesh->mMeshBounds.maxY; 
     292        zMax    =       geoMesh->mMeshBounds.maxZ; 
     293        xMin    =       geoMesh->mMeshBounds.minX; 
     294        yMin    =       geoMesh->mMeshBounds.minY; 
     295        zMin    =       geoMesh->mMeshBounds.minZ; 
     296        scale   =       geoMesh->mMeshBounds.scaleFactor; 
     297         
     298        //      Calculate center of the model. 
     299        cx = (xMax + xMin) / 2.0f; 
     300        cy = (yMax + yMin) / 2.0f; 
     301        cz = (zMax + zMin) / 2.0f; 
     302 
     303        xMax    -=      cx; 
     304        yMax    -=      cy; 
     305        zMax    -=      cz; 
     306        xMin    -=      cx; 
     307        yMin    -=      cy; 
     308        zMin    -=      cz; 
     309 
     310        xMax    *=      scale; 
     311        yMax    *=      scale; 
     312        zMax    *=      scale; 
     313        xMin    *=      scale; 
     314        yMin    *=      scale; 
     315        zMin    *=      scale; 
     316} 
     317 
     318//------------------------------------------------------------------------- 
    391319//      Constructor. 
    392 //--------------------------------------------------------------------------- 
     320//------------------------------------------------------------------------- 
    393321GeoMeshView::GeoMeshView(       int                                             x, 
    394322                                                                                                        int                                             y, 
     
    446374#define ALPHA 0.5 
    447375 
    448 //--------------------------------------------------------------------------- 
     376//------------------------------------------------------------------------- 
    449377//      Sets the Mesh to display. 
    450 //--------------------------------------------------------------------------- 
     378//------------------------------------------------------------------------- 
    451379void GeoMeshView::setMesh(Mesh  *geomesh) 
    452380{ 
     
    458386        mScaleFactor                    =       geomesh->mMeshBounds.scaleFactor; 
    459387         
     388        //      Gets boundings of mesh. 
     389        getBoundingBox(); 
     390 
    460391        //      Refresh vertices to the vertex array. 
    461392        refreshVertices(geomesh); 
     
    478409} 
    479410 
    480 //--------------------------------------------------------------------------- 
     411//------------------------------------------------------------------------- 
    481412//       Refresh vertices to the vertex array. 
    482 //--------------------------------------------------------------------------- 
     413//------------------------------------------------------------------------- 
    483414void    GeoMeshView::refreshVertices(Mesh       *geomesh) 
    484415{ 
     
    603534} 
    604535 
    605 //--------------------------------------------------------------------------- 
     536//------------------------------------------------------------------------- 
    606537//      Gets the triangle count of the current lod. 
    607 //--------------------------------------------------------------------------- 
     538//------------------------------------------------------------------------- 
    608539size_t  GeoMeshView::getLodStripsTriangleCount() 
    609540{ 
     
    618549} 
    619550 
    620 //--------------------------------------------------------------------------- 
     551//------------------------------------------------------------------------- 
    621552//      Repaint the Mesh. 
    622 //--------------------------------------------------------------------------- 
     553//------------------------------------------------------------------------- 
    623554void GeoMeshView::drawGeoMesh(bool      paintWire) 
    624555{ 
     
    667598}//     End drawGeoMesh. 
    668599 
    669 //--------------------------------------------------------------------------- 
     600//------------------------------------------------------------------------- 
    670601//      Paint eah strip separately. 
    671 //--------------------------------------------------------------------------- 
     602//------------------------------------------------------------------------- 
    672603void GeoMeshView::drawTriangleStrip(int submesh) 
    673604{ 
     
    745676                } 
    746677 
    747  
    748678                //VERTEX ARRAYS 
    749679                glEnableClientState(GL_VERTEX_ARRAY); 
     
    780710}//End drawTriangleStrip. 
    781711 
    782 //--------------------------------------------------------------------------- 
    783 //      Paint the array of idices. 
    784 //--------------------------------------------------------------------------- 
     712//------------------------------------------------------------------------- 
     713//      Paint the array of indices. 
     714//------------------------------------------------------------------------- 
    785715void GeoMeshView::drawTriangleList(     int                     submesh, 
    786716                                                                                                                                                bool            selectedSubMesh, 
     
    895825}//End drawTriangleList 
    896826 
    897 //--------------------------------------------------------------------------- 
     827//------------------------------------------------------------------------- 
    898828//      Paint lodstrip object. 
    899 //--------------------------------------------------------------------------- 
     829//------------------------------------------------------------------------- 
    900830void GeoMeshView::drawLodStrip() 
    901831{ 
     
    970900}//End drawTriangleStrip. 
    971901 
    972 //--------------------------------------------------------------------------- 
     902//------------------------------------------------------------------------- 
    973903//      Paint lodtree object. 
    974 //--------------------------------------------------------------------------- 
     904//------------------------------------------------------------------------- 
    975905void GeoMeshView::drawLodTree() 
    976906{ 
     
    10901020} 
    10911021 
    1092 //--------------------------------------------------------------------------- 
     1022//------------------------------------------------------------------------- 
    10931023//      Sets the lodstripslibrary object. 
    1094 //--------------------------------------------------------------------------- 
     1024//------------------------------------------------------------------------- 
    10951025void    GeoMeshView::setLodStripsLibrary(LodStripsLibrary *lodstrips) 
    10961026{ 
     
    10991029} 
    11001030 
    1101 //--------------------------------------------------------------------------- 
     1031//------------------------------------------------------------------------- 
    11021032//      Sets the lodtreeslibrary object. 
    1103 //--------------------------------------------------------------------------- 
     1033//------------------------------------------------------------------------- 
    11041034void    GeoMeshView::setLodTreesLibrary(LodTreeLibrary *lodtrees) 
    11051035{ 
     
    11081038} 
    11091039 
    1110 //--------------------------------------------------------------------------- 
     1040//------------------------------------------------------------------------- 
    11111041//      Change de Level of detail of the object. 
    1112 //--------------------------------------------------------------------------- 
     1042//------------------------------------------------------------------------- 
    11131043void    GeoMeshView::GoToLod_LodStrip(float     lod) 
    11141044{ 
     
    11261056} 
    11271057 
    1128 //--------------------------------------------------------------------------- 
     1058//------------------------------------------------------------------------- 
    11291059//      Change de Level of detail of the object. 
    1130 //--------------------------------------------------------------------------- 
     1060//------------------------------------------------------------------------- 
    11311061void    GeoMeshView::GoToLod_LodTree(float      lod) 
    11321062{ 
     
    11391069} 
    11401070 
    1141 //--------------------------------------------------------------------------- 
     1071//------------------------------------------------------------------------- 
     1072//      Draw axes. 
     1073//------------------------------------------------------------------------- 
     1074void    GeoMeshView::drawAxes() 
     1075{ 
     1076        float   max; 
     1077 
     1078        max     =       xMax; 
     1079 
     1080        if (yMax > max) 
     1081        { 
     1082                max = yMax; 
     1083        } 
     1084 
     1085        if (zMax > max) 
     1086        { 
     1087                max = zMax; 
     1088        } 
     1089 
     1090        glDisable(GL_LIGHTING); 
     1091        glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 
     1092        glDisable(GL_CULL_FACE); 
     1093 
     1094        //      Set white color to the object. 
     1095        glColor3d(1.0, 0.0, 0.0); 
     1096 
     1097        //      X axis. 
     1098        glBegin(GL_LINES); 
     1099        glVertex3f(0.0f,0.0f,0.0f); 
     1100        glVertex3f(max,0.0f,0.0f); 
     1101        glEnd(); 
     1102 
     1103        //      Set white color to the object. 
     1104        glColor3d(0.0, 1.0, 0.0); 
     1105 
     1106        //      Y axis. 
     1107        glBegin(GL_LINES); 
     1108        glVertex3f(0.0f,0.0f,0.0f); 
     1109        glVertex3f(0.0f,max,0.0f); 
     1110        glEnd(); 
     1111 
     1112        //      Set white color to the object. 
     1113        glColor3d(0.0, 0.0, 1.0); 
     1114 
     1115        //      Z axis. 
     1116        glBegin(GL_LINES); 
     1117        glVertex3f(0.0f,0.0f,0.0f); 
     1118        glVertex3f(0.0f,0.0f,max); 
     1119        glEnd(); 
     1120} 
     1121 
     1122//------------------------------------------------------------------------- 
     1123//      Draw bounding box. 
     1124//------------------------------------------------------------------------- 
     1125void    GeoMeshView::drawBoundingBox() 
     1126{ 
     1127        glDisable(GL_LIGHTING); 
     1128        glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 
     1129        glDisable(GL_CULL_FACE); 
     1130 
     1131        //      Set white color to the object. 
     1132        glColor3d(0.0, 0.0, 0.0); 
     1133 
     1134        glBegin(GL_QUADS); 
     1135        glVertex3f(xMin,yMin,zMin); 
     1136        glVertex3f(xMin,yMax,zMin); 
     1137        glVertex3f(xMax,yMax,zMin); 
     1138        glVertex3f(xMax,yMin,zMin); 
     1139 
     1140        glVertex3f(xMin,yMin,zMin); 
     1141        glVertex3f(xMin,yMax,zMin); 
     1142        glVertex3f(xMin,yMax,zMax); 
     1143        glVertex3f(xMin,yMin,zMax); 
     1144 
     1145        glVertex3f(xMax,yMin,zMin); 
     1146        glVertex3f(xMax,yMax,zMin); 
     1147        glVertex3f(xMax,yMax,zMax); 
     1148        glVertex3f(xMax,yMin,zMax); 
     1149 
     1150        glVertex3f(xMax,yMin,zMax); 
     1151        glVertex3f(xMax,yMax,zMax); 
     1152        glVertex3f(xMin,yMax,zMax); 
     1153        glVertex3f(xMin,yMin,zMax); 
     1154 
     1155        glVertex3f(xMin,yMin,zMax); 
     1156        glVertex3f(xMax,yMin,zMax); 
     1157        glVertex3f(xMax,yMin,zMin); 
     1158        glVertex3f(xMin,yMin,zMin); 
     1159 
     1160        glVertex3f(xMin,yMax,zMax); 
     1161        glVertex3f(xMax,yMax,zMax); 
     1162        glVertex3f(xMax,yMax,zMin); 
     1163        glVertex3f(xMin,yMax,zMin); 
     1164 
     1165        glEnd(); 
     1166} 
     1167 
     1168//------------------------------------------------------------------------- 
    11421169//      Draw the object in the window. 
    1143 //--------------------------------------------------------------------------- 
     1170//------------------------------------------------------------------------- 
    11441171void GeoMeshView::draw() 
    11451172{ 
     
    11821209        //glTranslatef(-xMed,-yMed,-zMed); 
    11831210 
     1211        GLfloat color_blanco[]  =       {1.0f,1.0f,1.0f,1.0f}; 
     1212 
     1213        glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color_blanco); 
     1214 
     1215        glClearColor(0.3,0.3,0.3,0); 
     1216         
     1217        if ((geoMesh != NULL) && mAxes) 
     1218        { 
     1219                //      Draw coordinates axes. 
     1220                drawAxes(); 
     1221        } 
     1222 
     1223        if ((geoMesh != NULL) && mBBox) 
     1224        { 
     1225                //      Draw bounding box. 
     1226                drawBoundingBox(); 
     1227        } 
     1228 
    11841229        //      Set white color to the object. 
    11851230        glColor3d(1.0, 1.0, 1.0); 
    11861231 
    1187         GLfloat color_blanco[]  =       {1.0f,1.0f,1.0f,1.0f}; 
    1188  
    1189         glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color_blanco); 
    1190  
    1191         glClearColor(0.3,0.3,0.3,0); 
    1192          
     1232        if (mLighting) 
     1233        { 
     1234                glEnable(GL_LIGHTING); 
     1235        } 
     1236        else 
     1237        { 
     1238                glDisable(GL_LIGHTING); 
     1239        } 
     1240 
    11931241        if (mCW) 
    11941242        { 
     
    12141262                glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 
    12151263                drawGeoMesh(false); 
    1216         } 
    1217  
    1218         if (mLighting) 
    1219         { 
    1220                 glEnable(GL_LIGHTING); 
    1221         } 
    1222         else 
    1223         { 
    1224                 glDisable(GL_LIGHTING); 
    12251264        } 
    12261265 
     
    12641303 
    12651304        swap_buffers(); 
    1266  
    1267         //      Calculate the FPS. 
    1268         //calcFPS(); 
    12691305} 
    12701306 
Note: See TracChangeset for help on using the changeset viewer.