]> git.mxchange.org Git - flightgear.git/blobdiff - src/Objects/obj.cxx
Add a key mapping (F3) for taking a screen snap shot.
[flightgear.git] / src / Objects / obj.cxx
index 393ed870c60e40fbe6b276d8c1d5182c239363f4..6c91c59ee7a2941785f4c4abd18b51aeb0c1cf82 100644 (file)
@@ -55,6 +55,7 @@
 #include <Math/polar3d.hxx>
 #include <Misc/stopwatch.hxx>
 #include <Scenery/tileentry.hxx>
+#include <Clouds/cloudobj.hxx>
 
 #include "materialmgr.hxx"
 #include "obj.hxx"
@@ -233,7 +234,9 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
     }
     
     unsigned short *vindex = new unsigned short [ 4 ];
+    t->free_ptrs.push_back( vindex );
     unsigned short *tindex = new unsigned short [ 4 ];
+    t->free_ptrs.push_back( tindex );
     for ( i = 0; i < 4; ++i ) {
        vindex[i] = i;
        tindex[i] = i;
@@ -248,6 +251,9 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
     leaf->setState( state );
 
     tile->addKid( leaf );
+    if ( current_options.get_clouds() ) {
+       fgGenCloudTile(path, t, tile);
+    }
 
     return tile;
 }
@@ -266,7 +272,8 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
     int vncount, vtcount;
     int n1 = 0, n2 = 0, n3 = 0, n4 = 0;
     int tex;
-    int last1 = 0, last2 = 0, odd = 0;
+    int last1 = 0, last2 = 0;
+    bool odd = false;
     point_list nodes;
     Point3D node;
     Point3D center;
@@ -279,6 +286,7 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
     ssgSimpleState *state = NULL;
 
     ssgBranch *tile = new ssgBranch () ;
+
     tile -> setName ( (char *)path.c_str() ) ;
 
     // Attempt to open "path.gz" or "path"
@@ -513,7 +521,7 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                // xglBegin(GL_TRIANGLE_STRIP);
                // printf("xglBegin(tristrip) %d %d %d\n", n1, n2, n3);
 
-               odd = 1
+               odd = true
                // scale = 1.0;
 
                if ( shading ) {
@@ -563,7 +571,7 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                }
                // printf("some normals, texcoords, and vertices\n");
 
-               odd = 1 - odd;
+               odd = !odd;
                last1 = n2;
                last2 = n3;
 
@@ -597,17 +605,18 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                    // xglTexCoord2f(pp.lon(), pp.lat());
                    // xglVertex3dv(nodes[n4].get_n());         
                    
-                   odd = 1 - odd;
+                   odd = !odd;
                    last1 = n3;
                    last2 = n4;
                    // printf("a normal, texcoord, and vertex (4th)\n");
                }
-           } else if ( token == "tf" ) {
+           } else if ( (token == "tf") || (token == "ts") ) {
                // triangle fan
                // fgPrintf( FG_TERRAIN, FG_DEBUG, "new fan");
 
                fan_vertices.clear();
                fan_tex_coords.clear();
+               odd = true;
 
                // xglBegin(GL_TRIANGLE_FAN);
 
@@ -618,8 +627,12 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                    in >> tex;
                    fan_tex_coords.push_back( tex );
                    if ( scenery_version >= 0.4 ) {
-                       t->tclist[tex][0] *= (1000.0 / tex_width);
-                       t->tclist[tex][1] *= (1000.0 / tex_height);
+                       if ( tex_width > 0 ) {
+                           t->tclist[tex][0] *= (1000.0 / tex_width);
+                       }
+                       if ( tex_height > 0 ) {
+                           t->tclist[tex][1] *= (1000.0 / tex_height);
+                       }
                    }
                    pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
                    pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
@@ -637,8 +650,12 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                    in >> tex;
                    fan_tex_coords.push_back( tex );
                    if ( scenery_version >= 0.4 ) {
-                       t->tclist[tex][0] *= (1000.0 / tex_width);
-                       t->tclist[tex][1] *= (1000.0 / tex_height);
+                       if ( tex_width > 0 ) {
+                           t->tclist[tex][0] *= (1000.0 / tex_width);
+                       }
+                       if ( tex_height > 0 ) {
+                           t->tclist[tex][1] *= (1000.0 / tex_height);
+                       }
                    }
                    pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
                    pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
@@ -674,8 +691,12 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                        in >> tex;
                        fan_tex_coords.push_back( tex );
                        if ( scenery_version >= 0.4 ) {
-                           t->tclist[tex][0] *= (1000.0 / tex_width);
-                           t->tclist[tex][1] *= (1000.0 / tex_height);
+                           if ( tex_width > 0 ) {
+                               t->tclist[tex][0] *= (1000.0 / tex_width);
+                           }
+                           if ( tex_height > 0 ) {
+                               t->tclist[tex][1] *= (1000.0 / tex_height);
+                           }
                        }
                        pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
                        pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
@@ -686,8 +707,21 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                    // xglTexCoord2f(pp.x(), pp.y());
                    // xglVertex3dv(nodes[n3].get_n());
 
-                   fragment.add_face(n1, n2, n3);
-                   n2 = n3;
+                   if ( token == "tf" ) {
+                       // triangle fan
+                       fragment.add_face(n1, n2, n3);
+                       n2 = n3;
+                   } else {
+                       // triangle strip
+                       if ( odd ) {
+                           fragment.add_face(n1, n2, n3);
+                       } else {
+                           fragment.add_face(n2, n1, n3);
+                       }
+                       odd = !odd;
+                       n1 = n2;
+                       n2 = n3;
+                   }
                }
 
                // xglEnd();
@@ -695,20 +729,36 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                // build the ssg entity
                unsigned short *vindex = 
                    new unsigned short [ fan_vertices.size() ];
+               t->free_ptrs.push_back( vindex );
+
                unsigned short *tindex = 
                    new unsigned short [ fan_tex_coords.size() ];
+               t->free_ptrs.push_back( tindex );
+
                for ( i = 0; i < (int)fan_vertices.size(); ++i ) {
                    vindex[i] = fan_vertices[i];
                }
                for ( i = 0; i < (int)fan_tex_coords.size(); ++i ) {
                    tindex[i] = fan_tex_coords[i];
                }
-               ssgLeaf *leaf = 
-                   new ssgVTable ( GL_TRIANGLE_FAN,
-                                   fan_vertices.size(), vindex, t->vtlist,
-                                   fan_vertices.size(), vindex, t->vnlist,
-                                   fan_tex_coords.size(), tindex, t->tclist,
-                                   0, NULL, NULL ) ;
+               ssgLeaf *leaf;
+               if ( token == "tf" ) {
+                   // triangle fan
+                   leaf = 
+                       new ssgVTable ( GL_TRIANGLE_FAN,
+                                       fan_vertices.size(), vindex, t->vtlist,
+                                       fan_vertices.size(), vindex, t->vnlist,
+                                       fan_tex_coords.size(), tindex,t->tclist,
+                                       0, NULL, NULL ) ;
+               } else {
+                   // triangle strip
+                   leaf = 
+                       new ssgVTable ( GL_TRIANGLE_STRIP,
+                                       fan_vertices.size(), vindex, t->vtlist,
+                                       fan_vertices.size(), vindex, t->vnlist,
+                                       fan_tex_coords.size(), tindex,t->tclist,
+                                       0, NULL, NULL ) ;
+               }
                leaf->setState( state );
 
                tile->addKid( leaf );
@@ -792,7 +842,7 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                // xglVertex3dv(nodes[n1].get_n());
                // printf("a normal, texcoord, and vertex (4th)\n");
    
-               odd = 1 - odd;
+               odd = !odd;
                last1 = last2;
                last2 = n1;
 
@@ -826,7 +876,7 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                    // xglVertex3dv(nodes[n2].get_n());         
                    // printf("a normal, texcoord, and vertex (4th)\n");
 
-                   odd = 1 -odd;
+                   odd = !odd;
                    last1 = last2;
                    last2 = n2;
                }
@@ -879,7 +929,11 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
     FG_LOG( FG_TERRAIN, FG_DEBUG, 
            "Loaded " << path << " in " 
            << stopwatch.elapsedSeconds() << " seconds" );
-    
+
+    // Generate a cloud layer above the tiles
+    if ( current_options.get_clouds() ) {
+       fgGenCloudTile(path, t, tile);
+    }
     return tile;
 }