]> git.mxchange.org Git - flightgear.git/blobdiff - Objects/obj.cxx
Converted to new logstream debugging facility. This allows release
[flightgear.git] / Objects / obj.cxx
index ee2652248264362203909d37634f12dd1f822b66..64a79b1ef748a8fec68bbcc3e1ee0c0d0b5982c0 100644 (file)
@@ -48,7 +48,7 @@ extern "C" void *memset(void *, int, size_t);
 using namespace std;
 #endif
 
-#include <Debug/fg_debug.h>
+#include <Debug/logstream.hxx>
 #include <Include/fg_constants.h>
 #include <Include/fg_zlib.h>
 #include <Main/options.hxx>
@@ -85,13 +85,17 @@ static void calc_normal(double p1[3], double p2[3],
 }
 
 
-#define FG_TEX_CONSTANT 8.0
+#define FG_TEX_CONSTANT 69.0
 
 
 // Calculate texture coordinates for a given point.
 static Point3D calc_tex_coords(double *node, const Point3D& ref) {
     Point3D cp;
     Point3D pp;
+    // double tmplon, tmplat;
+
+    // cout << "-> " << node[0] << " " << node[1] << " " << node[2] << endl;
+    // cout << "-> " << ref.x() << " " << ref.y() << " " << ref.z() << endl;
 
     cp = Point3D( node[0] + ref.x(),
                  node[1] + ref.y(),
@@ -99,19 +103,23 @@ static Point3D calc_tex_coords(double *node, const Point3D& ref) {
 
     pp = fgCartToPolar3d(cp);
 
-    // cout << pp << endl;
+    // tmplon = pp.lon() * RAD_TO_DEG;
+    // tmplat = pp.lat() * RAD_TO_DEG;
+    // cout << tmplon << " " << tmplat << endl;
 
-    pp.setx( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.x(), 1.0) );
-    pp.sety( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.y(), 1.0) );
+    pp.setx( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.x(), 11.0) );
+    pp.sety( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.y(), 11.0) );
 
     if ( pp.x() < 0.0 ) {
-       pp.setx( pp.x() + 1.0 );
+       pp.setx( pp.x() + 11.0 );
     }
 
     if ( pp.y() < 0.0 ) {
-       pp.sety( pp.y() + 1.0 );
+       pp.sety( pp.y() + 11.0 );
     }
 
+    // cout << pp << endl;
+
     return(pp);
 }
 
@@ -140,8 +148,7 @@ int fgObjLoad( const string& path, fgTILE *t) {
        in.open( path + ".obj" );
        if ( ! in )
        {
-           fgPrintf( FG_TERRAIN, FG_ALERT, 
-                     "Cannot open file: %s\n", path.c_str() );
+           FG_LOG( FG_TERRAIN, FG_ALERT, "Cannot open file: " << path );
            return 0;
        }
     }
@@ -159,56 +166,54 @@ int fgObjLoad( const string& path, fgTILE *t) {
     stopwatch.start();
 
     // ignore initial comments and blank lines. (priming the pump)
-    in.eat_comments();
+    in >> skipcomment;
 
     while ( ! in.eof() )
     {
 
        string token;
-       in.stream() >> token;
+       in >> token;
 
        // printf("token = %s\n", token.c_str() );
 
        if ( token == "gbs" )
        {
            // reference point (center offset)
-           in.stream() >> t->center >> t->bounding_radius;
+           in >> t->center >> t->bounding_radius;
+           center = t->center;
        }
        else if ( token == "bs" )
        {
            // reference point (center offset)
-           /*
-           in.stream() >> fragment.center.x
-                       >> fragment.center.y
-                       >> fragment.center.z
-           */
-           in.stream() >> fragment.center;
-           in.stream() >> fragment.bounding_radius;
+           in >> fragment.center;
+           in >> fragment.bounding_radius;
        }
        else if ( token == "vn" )
        {
            // vertex normal
            if ( vncount < MAX_NODES ) {
-               in.stream() >> normals[vncount][0]
-                           >> normals[vncount][1]
-                           >> normals[vncount][2];
+               in >> normals[vncount][0]
+                  >> normals[vncount][1]
+                  >> normals[vncount][2];
                vncount++;
            } else {
-               fgPrintf( FG_TERRAIN, FG_EXIT, 
-                         "Read too many vertex normals ... dying :-(\n");
+               FG_LOG( FG_TERRAIN, FG_ALERT, 
+                       "Read too many vertex normals ... dying :-(" );
+               exit(-1);
            }
        }
        else if ( token[0] == 'v' )
        {
            // node (vertex)
            if ( t->ncount < MAX_NODES ) {
-               in.stream() >> t->nodes[t->ncount][0]
-                           >> t->nodes[t->ncount][1]
-                           >> t->nodes[t->ncount][2];
+               in >> t->nodes[t->ncount][0]
+                  >> t->nodes[t->ncount][1]
+                  >> t->nodes[t->ncount][2];
                t->ncount++;
            } else {
-               fgPrintf( FG_TERRAIN, FG_EXIT, 
-                         "Read too many nodes ... dying :-(\n");
+               FG_LOG( FG_TERRAIN, FG_ALERT, 
+                       "Read too many nodes ... dying :-(");
+               exit(-1);
            }
        }
        else if ( token == "usemtl" )
@@ -245,14 +250,14 @@ int fgObjLoad( const string& path, fgTILE *t) {
 
            // scan the material line
            string material;
-           in.stream() >> material;
+           in >> material;
            fragment.tile_ptr = t;
 
            // find this material in the properties list
            if ( ! material_mgr.find( material, fragment.material_ptr )) {
-               fgPrintf( FG_TERRAIN, FG_ALERT, 
-                         "Ack! unknown usemtl name = %s in %s\n",
-                         material.c_str(), path.c_str() );
+               FG_LOG( FG_TERRAIN, FG_ALERT, 
+                       "Ack! unknown usemtl name = " << material 
+                       << " in " << path );
            }
 
            // initialize the fragment transformation matrix
@@ -269,7 +274,7 @@ int fgObjLoad( const string& path, fgTILE *t) {
            n1 = n2 = n3 = n4 = 0;
 
            // fgPrintf( FG_TERRAIN, FG_DEBUG, "    new tri strip = %s", line);
-           in.stream() >> n1 >> n2 >> n3;
+           in >> n1 >> n2 >> n3;
            fragment.add_face(n1, n2, n3);
 
            // fgPrintf( FG_TERRAIN, FG_DEBUG, "(t) = ");
@@ -347,7 +352,7 @@ int fgObjLoad( const string& path, fgTILE *t) {
                if ( isdigit(c) )
                {
                    in.putback(c);
-                   in.stream() >> n4;
+                   in >> n4;
                    break;
                }
            }
@@ -385,7 +390,7 @@ int fgObjLoad( const string& path, fgTILE *t) {
            }
 
            // fgPrintf( FG_TERRAIN, FG_DEBUG, "new triangle = %s", line);*/
-           in.stream() >> n1 >> n2 >> n3;
+           in >> n1 >> n2 >> n3;
            fragment.add_face(n1, n2, n3);
 
             // xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
@@ -415,7 +420,7 @@ int fgObjLoad( const string& path, fgTILE *t) {
 
            // fgPrintf( FG_TERRAIN, FG_DEBUG, "continued tri strip = %s ", 
            //           line);
-           in.stream() >> n1;
+           in >> n1;
 
            // There can be one or two values 
            char c;
@@ -427,7 +432,7 @@ int fgObjLoad( const string& path, fgTILE *t) {
                if ( isdigit(c) )
                {
                    in.putback(c);
-                   in.stream() >> n2;
+                   in >> n2;
                    break;
                }
            }
@@ -501,13 +506,13 @@ int fgObjLoad( const string& path, fgTILE *t) {
                last2 = n2;
            }
        } else {
-           fgPrintf( FG_TERRAIN, FG_WARN, "Unknown token in %s = %s\n", 
-                     path.c_str(), token.c_str() );
+           FG_LOG( FG_TERRAIN, FG_WARN, "Unknown token in " 
+                   << path << " = " << token );
        }
 
        // eat comments and blank lines before start of while loop so
        // if we are done with useful input it is noticed before hand.
-       in.eat_comments();
+       in >> skipcomment;
     }
 
     if ( in_fragment ) {
@@ -539,8 +544,9 @@ int fgObjLoad( const string& path, fgTILE *t) {
     */   
 
     stopwatch.stop();
-    fgPrintf( FG_TERRAIN, FG_INFO, "Loaded %s in %f seconds\n",
-             path.c_str(), stopwatch.elapsedSeconds() );
+    FG_LOG( FG_TERRAIN, FG_INFO, 
+           "Loaded " << path << " in " 
+           << stopwatch.elapsedSeconds() << " seconds" );
 
     // printf("end of tile\n");
 
@@ -549,6 +555,17 @@ int fgObjLoad( const string& path, fgTILE *t) {
 
 
 // $Log$
+// Revision 1.10  1998/11/06 21:18:18  curt
+// Converted to new logstream debugging facility.  This allows release
+// builds with no messages at all (and no performance impact) by using
+// the -DFG_NDEBUG flag.
+//
+// Revision 1.9  1998/11/06 14:47:06  curt
+// Changes to track Bernie's updates to fgstream.
+//
+// Revision 1.8  1998/10/20 18:33:55  curt
+// Tweaked texture coordinates, but we still have some problems. :-(
+//
 // Revision 1.7  1998/10/20 15:48:44  curt
 // Removed an extraneous output message.
 //