]> git.mxchange.org Git - flightgear.git/blobdiff - src/Objects/obj.cxx
Work on better texture coordinate handling with the ability to scale textures
[flightgear.git] / src / Objects / obj.cxx
index e4b1b0670c37e731d50ab2372b66544938ddb919..06e5d1de750174d7cc68ba917923749b23c054dd 100644 (file)
@@ -176,14 +176,15 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
     geod[3] = Point3D( clon - width/2.0, clat + height/2.0, 0.0 );
 
     Point3D rad[4];
-    for ( int i = 0; i < 4; ++i ) {
+    int i;
+    for ( i = 0; i < 4; ++i ) {
        rad[i] = Point3D( geod[i].x() * DEG_TO_RAD, geod[i].y() * DEG_TO_RAD,
                          geod[i].z() );
     }
 
     Point3D cart[4], rel[4];
     t->nodes.clear();
-    for ( int i = 0; i < 4; ++i ) {
+    for ( i = 0; i < 4; ++i ) {
        cart[i] = fgGeodToCart(rad[i]);
        rel[i] = cart[i] - center;
        t->nodes.push_back( rel[i] );
@@ -199,7 +200,7 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
 
     // Calculate normals
     Point3D normals[4];
-    for ( int i = 0; i < 4; ++i ) {
+    for ( i = 0; i < 4; ++i ) {
        normals[i] = cart[i];
        double length = normals[i].distance3D( Point3D(0.0) );
        normals[i] /= length;
@@ -208,7 +209,7 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
 
     // Calculate texture coordinates
     Point3D texs[4];
-    for ( int i = 0; i < 4; ++i ) {
+    for ( i = 0; i < 4; ++i ) {
        texs[i] = calc_tex_coords( rel[i], center );
        // cout << "texture coordinate = " << texs[i] << endl;
     }
@@ -223,7 +224,7 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
     t->vnlist = new sgVec3 [ 4 ];
     t->tclist = new sgVec2 [ 4 ];
 
-    for ( int i = 0; i < 4; ++i ) {
+    for ( i = 0; i < 4; ++i ) {
        sgSetVec3( t->vtlist[i], 
                   rel[i].x(), rel[i].y(), rel[i].z() );
        sgSetVec3( t->vnlist[i], 
@@ -233,7 +234,7 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
     
     unsigned short *vindex = new unsigned short [ 4 ];
     unsigned short *tindex = new unsigned short [ 4 ];
-    for ( int i = 0; i < 4; ++i ) {
+    for ( i = 0; i < 4; ++i ) {
        vindex[i] = i;
        tindex[i] = i;
     }
@@ -269,6 +270,7 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
     point_list nodes;
     Point3D node;
     Point3D center;
+    double scenery_version = 0.0;
     double tex_width = 1000.0, tex_height = 1000.0;
     bool shared_done = false;
     int_list fan_vertices;
@@ -328,7 +330,11 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
 
            in >> token;
 
-           if ( token == "gbs" ) {
+           if ( token == "version" ) {
+               // read scenery versions number
+               in >> scenery_version;
+               // cout << "scenery_version = " << scenery_version << endl;
+           } else if ( token == "gbs" ) {
                // reference point (center offset)
                in >> t->center >> t->bounding_radius;
                center = t->center;
@@ -372,7 +378,8 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                    }
                    for ( i = 0; i < vtcount; ++i ) {
                        sgSetVec2( t->tclist[i],
-                                  tex_coords[i][0], tex_coords[i][1] );
+                                  tex_coords[i][0],
+                                  tex_coords[i][1] );
                    }
                }
 
@@ -575,7 +582,7 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
 
                if ( n4 > 0 ) {
                    fragment.add_face(n3, n2, n4);
-
+                   
                    if ( shading ) {
                        // Shading model is "GL_SMOOTH"
                        // MAT3_SCALE_VEC(normal, normals[n4], scale);
@@ -610,6 +617,10 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                if ( in.get( c ) && c == '/' ) {
                    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);
+                   }
                    pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
                    pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
                } else {
@@ -625,6 +636,10 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                if ( in.get( c ) && c == '/' ) {
                    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);
+                   }
                    pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
                    pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
                } else {
@@ -658,6 +673,10 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                    if ( in.get( c ) && c == '/' ) {
                        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);
+                       }
                        pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
                        pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
                    } else {
@@ -857,7 +876,7 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
     t->nodes = nodes;
 
     stopwatch.stop();
-    FG_LOG( FG_TERRAIN, FG_INFO
+    FG_LOG( FG_TERRAIN, FG_DEBUG
            "Loaded " << path << " in " 
            << stopwatch.elapsedSeconds() << " seconds" );