]> git.mxchange.org Git - flightgear.git/commitdiff
Updates to the scenery loading infrastructure to make it more flexible,
authorcurt <curt>
Sun, 3 Mar 2002 20:29:31 +0000 (20:29 +0000)
committercurt <curt>
Sun, 3 Mar 2002 20:29:31 +0000 (20:29 +0000)
clean up some messiness, and lay more groundwork for runway lighting.

src/Objects/obj.cxx
src/Objects/obj.hxx
src/Scenery/tileentry.cxx
src/Scenery/tileentry.hxx

index a33178ae44783b18b51ce93a0cafa334d5e00983..3b2b61f93ad2a741d52ccb96bdef3a42f277fcd8 100644 (file)
@@ -108,19 +108,17 @@ static Point3D local_calc_tex_coords(const Point3D& node, const Point3D& ref) {
 }
 
 
-// Generate a generic ocean tile on the fly
-ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
+// Generate an ocean tile
+bool fgGenTile( const string& path, SGBucket b,
+                     Point3D *center,
+                     double *bounding_radius,
+                     ssgBranch* geometry )
+{
     FGNewMat *newmat;
 
     ssgSimpleState *state = NULL;
 
-    ssgBranch *tile = new ssgBranch () ;
-    if ( !tile ) {
-        SG_LOG( SG_TERRAIN, SG_ALERT, "fgGenTile(): NO MEMORY" );
-        return NULL;
-    }
-
-    tile -> setName ( (char *)path.c_str() ) ;
+    geometry -> setName ( (char *)path.c_str() ) ;
 
     double tex_width = 1000.0;
     // double tex_height;
@@ -142,14 +140,14 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
     }
 
     // Calculate center point
-    SGBucket b = t->tile_bucket;
     double clon = b.get_center_lon();
     double clat = b.get_center_lat();
     double height = b.get_height();
     double width = b.get_width();
 
-    Point3D center = sgGeodToCart(Point3D(clon*SGD_DEGREES_TO_RADIANS,clat*SGD_DEGREES_TO_RADIANS,0.0));
-    t->center = center;
+    *center = sgGeodToCart( Point3D(clon*SGD_DEGREES_TO_RADIANS,
+                                   clat*SGD_DEGREES_TO_RADIANS,
+                                   0.0) );
     // cout << "center = " << center << endl;;
     
     // Caculate corner vertices
@@ -168,18 +166,14 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
     }
 
     Point3D cart[4], rel[4];
-    t->nodes.clear();
     for ( i = 0; i < 4; ++i ) {
        cart[i] = sgGeodToCart(rad[i]);
-       rel[i] = cart[i] - center;
-       t->nodes.push_back( rel[i] );
+       rel[i] = cart[i] - *center;
        // cout << "corner " << i << " = " << cart[i] << endl;
     }
 
-    t->ncount = 4;
-
     // Calculate bounding radius
-    t->bounding_radius = center.distance3D( cart[0] );
+    *bounding_radius = center->distance3D( cart[0] );
     // cout << "bounding radius = " << t->bounding_radius << endl;
 
     // Calculate normals
@@ -239,9 +233,9 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
 
     leaf->setState( state );
 
-    tile->addKid( leaf );
+    geometry->addKid( leaf );
 
-    return tile;
+    return true;
 }
 
 
@@ -311,7 +305,7 @@ static void gen_random_surface_points( ssgLeaf *leaf, ssgVertexArray *lights,
 
 // Load an Ascii obj file
 ssgBranch *fgAsciiObjLoad( const string& path, FGTileEntry *t,
-                                 ssgVertexArray *lights, const bool is_base)
+                          ssgVertexArray *lights, const bool is_base)
 {
     FGNewMat *newmat = NULL;
     string material;
@@ -906,28 +900,29 @@ ssgLeaf *gen_leaf( const string& path,
 
 
 // Load an Binary obj file
-ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
-                         ssgVertexArray *lights, const bool is_base)
+bool fgBinObjLoad( const string& path, const bool is_base,
+                  Point3D *center,
+                  double *bounding_radius,
+                  ssgBranch* geometry,
+                  ssgBranch* rwy_lights,
+                  ssgVertexArray *ground_lights )
 {
-    int i;
-
     SGBinObject obj;
     bool result = obj.read_bin( path );
 
     if ( !result ) {
-       return NULL;
+       return false;
     }
 
     // cout << "fans size = " << obj.get_fans_v().size()
     //      << " fan_mats size = " << obj.get_fan_materials().size() << endl;
 
-    ssgBranch *object = new ssgBranch();
-    object->setName( (char *)path.c_str() );
+    geometry->setName( (char *)path.c_str() );
    
-    if ( is_base && t != NULL ) {
+    if ( is_base ) {
        // reference point (center offset/bounding sphere)
-       t->center = obj.get_gbs_center();
-       t->bounding_radius = obj.get_gbs_radius();
+       *center = obj.get_gbs_center();
+       *bounding_radius = obj.get_gbs_radius();
     }
 
     point_list nodes = obj.get_wgs84_nodes();
@@ -939,6 +934,8 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
     int_list vertex_index;
     int_list tex_index;
 
+    int i;
+
     // generate points
     string_list pt_materials = obj.get_pt_materials();
     group_list pts_v = obj.get_pts_v();
@@ -950,9 +947,9 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
        ssgLeaf *leaf = gen_leaf( path, GL_POINTS, material,
                                  nodes, normals, texcoords,
                                  vertex_index, tex_index,
-                                 false, lights );
+                                 false, ground_lights );
 
-       object->addKid( leaf );
+       geometry->addKid( leaf );
     }
 
     // generate triangles
@@ -966,9 +963,9 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
        ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLES, material,
                                  nodes, normals, texcoords,
                                  vertex_index, tex_index,
-                                 is_base, lights );
+                                 is_base, ground_lights );
 
-       object->addKid( leaf );
+       geometry->addKid( leaf );
     }
 
     // generate strips
@@ -982,9 +979,9 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
        ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material,
                                  nodes, normals, texcoords,
                                  vertex_index, tex_index,
-                                 is_base, lights );
+                                 is_base, ground_lights );
 
-       object->addKid( leaf );
+       geometry->addKid( leaf );
     }
 
     // generate fans
@@ -998,10 +995,10 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
        ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_FAN, material,
                                  nodes, normals, texcoords,
                                  vertex_index, tex_index,
-                                 is_base, lights );
+                                 is_base, ground_lights );
 
-       object->addKid( leaf );
+       geometry->addKid( leaf );
     }
 
-    return object;
+    return true;
 }
index 05a7180d7afc78f3180197b4646519de4e49abeb..68ff0f98f2b73fd33e9af443e475d0e6c689c947 100644 (file)
@@ -57,16 +57,23 @@ SG_USING_STD(string);
 #define FG_MAX_NODES 4000
 
 
-// Load a binary object file
-ssgBranch *fgBinObjLoad(const string& path, FGTileEntry *tile,
-                       ssgVertexArray *lights, const bool is_base);
+// Load an Binary obj file
+bool fgBinObjLoad( const string& path, const bool is_base,
+                  Point3D *center,
+                  double *bounding_radius,
+                  ssgBranch* geometry,
+                  ssgBranch* rwy_lights,
+                  ssgVertexArray *ground_lights );
 
 // Load an ascii object file
 ssgBranch *fgAsciiObjLoad(const string& path, FGTileEntry *tile,
                          ssgVertexArray *lights, const bool is_base);
 
 // Generate an ocean tile
-ssgBranch *fgGenTile( const string& path, FGTileEntry *t);
+bool fgGenTile( const string& path, SGBucket b,
+               Point3D *center,
+               double *bounding_radius,
+               ssgBranch* geometry );
 
 
 // Create an ssg leaf
index e9a719133f9fcfd497ec86017c3693d98cc014c3..adc92e04ee01158ff70dc5c6c465d09248b66473 100644 (file)
@@ -959,22 +959,42 @@ ssgLeaf* FGTileEntry::gen_lights( ssgVertexArray *lights, int inc, float bright
 
 ssgBranch*
 FGTileEntry::obj_load( const std::string& path,
-                      ssgVertexArray* lights, bool is_base )
+                      ssgVertexArray* ground_lights, bool is_base )
 {
-    ssgBranch* result = 0;
+    ssgBranch* geometry = new ssgBranch;
+    ssgBranch* rwy_lights = new ssgBranch;
+
+    Point3D c;                 // returned center point
+    double br;                 // returned bounding radius
 
     // try loading binary format
-    result = fgBinObjLoad( path, this, lights, is_base );
-    if ( result == NULL ) {
-       // next try the older ascii format
-       result = fgAsciiObjLoad( path, this, lights, is_base );
-       if ( result == NULL ) {
+    if ( fgBinObjLoad( path, is_base,
+                      &c, &br, geometry, rwy_lights, ground_lights ) )
+    {
+       if ( is_base ) {
+           center = c;
+           bounding_radius = br;
+       }
+    } else {
+       // next try the older ascii format, this is some ugly
+       // weirdness because the ascii loader is *old* and hasn't been
+       // updated, but hopefully we can can the ascii format soon.
+       ssgBranch *tmp = fgAsciiObjLoad( path, this, ground_lights, is_base );
+       if ( tmp ) {
+           return tmp;
+       } else {
            // default to an ocean tile
-           result = fgGenTile( path, this );
+           if ( fgGenTile( path, tile_bucket, &c, &br, geometry ) ) {
+               center = c;
+               bounding_radius = br;
+           } else {
+               SG_LOG( SG_TERRAIN, SG_ALERT,
+                       "Warning: failed to generate ocean tile!" );
+           }
        }
     }
 
-    return result;
+    return geometry;
 }
 
 
index 45ec4d8f8c15b5755a83e81e22836a884d1606ea..0abcebaab0651d2407c4e8feb6f9201e80f7c1b1 100644 (file)
@@ -104,6 +104,8 @@ class FGTileEntry {
 
 public:
 
+    /* CLO123 FROM HERE TO THE CORRESPONDING MARKER ARE THINGS THAT
+       CAN BE DELETED AFTER WE DROP THE ASCII SCENERY FORMAT */
     typedef vector < sgVec3 * > free_vec3_list;
     typedef vector < sgVec2 * > free_vec2_list;
     typedef vector < unsigned short * > free_index_list;
@@ -111,6 +113,7 @@ public:
     // node list
     point_list nodes;
     int ncount;
+    /* CLO123 MARKER */
 
     // global tile culling data
     Point3D center;
@@ -180,7 +183,8 @@ private:
     volatile int pending_models;
 
     ssgBranch* obj_load( const std::string& path,
-                        ssgVertexArray* lights, bool is_base );
+                        ssgVertexArray* gound_lights,
+                        bool is_base );
 
     ssgLeaf* gen_lights( ssgVertexArray *lights, int inc, float bright );