]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/sg_binobj.cxx
Tweaks.
[simgear.git] / simgear / io / sg_binobj.cxx
index 359ee4cf111516e3aebd42ecbc5d9b5c4015fd57..237f24d9da98140386510900b62fb48089bc8e1a 100644 (file)
 #include "sg_binobj.hxx"
 
 
-FG_USING_STD( string );
-FG_USING_STD( vector );
-FG_USING_STD( cout );
-FG_USING_STD( endl );
+SG_USING_STD( string );
+SG_USING_STD( vector );
+
+#if !defined (SG_HAVE_NATIVE_SGI_COMPILERS)
+SG_USING_STD( cout );
+SG_USING_STD( endl );
+#endif
 
 
 enum {
@@ -189,7 +192,6 @@ bool SGBinObject::read_bin( const string& file ) {
 
     // read headers
     unsigned int header;
-    unsigned short version;
     sgReadUInt( fp, &header );
     if ( ((header & 0xFF000000) >> 24) == 'S' &&
         ((header & 0x00FF0000) >> 16) == 'G' ) {
@@ -252,11 +254,19 @@ bool SGBinObject::read_bin( const string& file ) {
                sgReadBytes( fp, nbytes, ptr );
 
                double *dptr = (double *)ptr;
+               if ( sgIsBigEndian() ) {
+                   sgEndianSwap( (unsigned long long *)&(dptr[0]) );
+                   sgEndianSwap( (unsigned long long *)&(dptr[1]) );
+                   sgEndianSwap( (unsigned long long *)&(dptr[2]) );
+               }
                gbs_center = Point3D( dptr[0], dptr[1], dptr[2] );
                // cout << "Center = " << gbs_center << endl;
                ptr += sizeof(double) * 3;
                
                float *fptr = (float *)ptr;
+               if ( sgIsBigEndian() ) {
+                   sgEndianSwap( (unsigned int *)fptr );
+               }
                gbs_radius = fptr[0];
                // cout << "Bounding radius = " << gbs_radius << endl;
            }
@@ -283,6 +293,11 @@ bool SGBinObject::read_bin( const string& file ) {
                int count = nbytes / (sizeof(float) * 3);
                float *fptr = (float *)ptr;
                for ( k = 0; k < count; ++k ) {
+                   if ( sgIsBigEndian() ) {
+                       sgEndianSwap( (unsigned int *)&(fptr[0]) );
+                       sgEndianSwap( (unsigned int *)&(fptr[1]) );
+                       sgEndianSwap( (unsigned int *)&(fptr[2]) );
+                   }
                    p = Point3D( fptr[0], fptr[1], fptr[2] );
                    // cout << "node = " << p << endl;
                    wgs84_nodes.push_back( p );
@@ -311,9 +326,14 @@ bool SGBinObject::read_bin( const string& file ) {
                sgReadBytes( fp, nbytes, ptr );
                int count = nbytes / 3;
                for ( k = 0; k < count; ++k ) {
-                   p = Point3D( ptr[0] / 128.0 - 1.0,
-                                ptr[1] / 128.0 - 1.0,
-                                ptr[2] / 128.0 - 1.0 );
+                    sgdVec3 normal;
+                    sgdSetVec3( normal,
+                               (ptr[0]) / 127.5 - 1.0,
+                               (ptr[1]) / 127.5 - 1.0,
+                               (ptr[2]) / 127.5 - 1.0 );
+                    sgdNormalizeVec3( normal );
+
+                   p = Point3D( normal[0], normal[1], normal[2] );
                    // cout << "normal = " << p << endl;
                    normals.push_back( p );
                    ptr += 3;
@@ -342,6 +362,10 @@ bool SGBinObject::read_bin( const string& file ) {
                int count = nbytes / (sizeof(float) * 2);
                float *fptr = (float *)ptr;
                for ( k = 0; k < count; ++k ) {
+                   if ( sgIsBigEndian() ) {
+                       sgEndianSwap( (unsigned int *)&(fptr[0]) );
+                       sgEndianSwap( (unsigned int *)&(fptr[1]) );
+                   }
                    p = Point3D( fptr[0], fptr[1], 0 );
                    // cout << "texcoord = " << p << endl;
                    texcoords.push_back( p );
@@ -378,6 +402,10 @@ bool SGBinObject::read_bin( const string& file ) {
                int_list vs, tcs;
                vs.clear(); tcs.clear();
                for ( k = 0; k < count; ++k ) {
+                   if ( sgIsBigEndian() ) {
+                       sgEndianSwap( (unsigned short *)&(sptr[0]) );
+                       sgEndianSwap( (unsigned short *)&(sptr[1]) );
+                   }
                    vs.push_back( sptr[0] );
                    tcs.push_back( sptr[1] );
                    // cout << sptr[0] << "/" << sptr[1] << " ";
@@ -418,6 +446,10 @@ bool SGBinObject::read_bin( const string& file ) {
                int_list vs, tcs;
                vs.clear(); tcs.clear();
                for ( k = 0; k < count; ++k ) {
+                   if ( sgIsBigEndian() ) {
+                       sgEndianSwap( (unsigned short *)&(sptr[0]) );
+                       sgEndianSwap( (unsigned short *)&(sptr[1]) );
+                   }
                    vs.push_back( sptr[0] );
                    tcs.push_back( sptr[1] );
                    // cout << sptr[0] << "/" << sptr[1] << " ";
@@ -458,6 +490,10 @@ bool SGBinObject::read_bin( const string& file ) {
                int_list vs, tcs;
                vs.clear(); tcs.clear();
                for ( k = 0; k < count; ++k ) {
+                   if ( sgIsBigEndian() ) {
+                       sgEndianSwap( (unsigned short *)&(sptr[0]) );
+                       sgEndianSwap( (unsigned short *)&(sptr[1]) );
+                   }
                    vs.push_back( sptr[0] );
                    tcs.push_back( sptr[1] );
                    // cout << sptr[0] << "/" << sptr[1] << " ";
@@ -636,9 +672,9 @@ bool SGBinObject::write_bin( const string& base, const string& name,
     char normal[3];
     for ( i = 0; i < (int)normals.size(); ++i ) {
        p = normals[i];
-       normal[0] = (unsigned char)((p.x() + 1.0) * 128);
-       normal[1] = (unsigned char)((p.y() + 1.0) * 128);
-       normal[2] = (unsigned char)((p.z() + 1.0) * 128);
+       normal[0] = (unsigned char)((p.x() + 1.0) * 127.5);
+       normal[1] = (unsigned char)((p.y() + 1.0) * 127.5);
+       normal[2] = (unsigned char)((p.z() + 1.0) * 127.5);
        sgWriteBytes( fp, 3, normal );
     }