]> git.mxchange.org Git - flightgear.git/commitdiff
Fix for vanishing-model problem: models are drawn in the same scene
authordavid <david>
Sat, 13 Apr 2002 21:36:22 +0000 (21:36 +0000)
committerdavid <david>
Sat, 13 Apr 2002 21:36:22 +0000 (21:36 +0000)
graph as the terrain, except for internal cockpit view.  The SSG
scene-graph variables (except for the lighting root -- I'll get that
later) are now held in globals.hxx.

FGModelMgr::draw() is obsolete; I'll remove it in a future revision.

src/ATC/AIEntity.cxx
src/Main/globals.hxx
src/Main/main.cxx
src/Model/acmodel.cxx
src/Model/acmodel.hxx
src/Model/modelmgr.cxx
src/Model/modelmgr.hxx
src/Scenery/hitlist.cxx
src/Scenery/newcache.cxx
src/Scenery/tilemgr.cxx

index 67ba889eba031cfb13316277ce6f63aaacec540e..2eb8ba1d662e2adf85d88eb31d56afb970dd0146 100644 (file)
@@ -36,8 +36,6 @@
 
 #include "AIEntity.hxx"
 
-extern ssgRoot* scene; // The global Flightgear scene graph
-
 FGAIEntity::~FGAIEntity() {
 }
 
@@ -55,7 +53,7 @@ void FGAIEntity::Transform() {
     sgCoord shippos;
     FastWorldCoordinate(&shippos, sc);
     position->setTransform( &shippos );
-    scene->addKid(position);
+    globals->get_scene_graph()->addKid(position);
     //cout << "Transform called\n";
 }
 
index 9d5b0518bf4ecfe0eae4b95d51c7589a345f1682..67bea6200022342ce39218fe2a973552a870e685 100644 (file)
@@ -67,6 +67,9 @@ class FGAIMgr;
 class FGAircraftModel;
 class FGModelMgr;
 
+class ssgRoot;
+class ssgBranch;
+
 
 /**
  * Bucket for subsystem pointers representing the sim's state.
@@ -158,6 +161,14 @@ private:
     // list of serial port-like configurations
     string_list *channel_options_list;
 
+    // SSG scene graph
+    ssgRoot * scene_graph;
+    ssgBranch * terrain_branch;
+    ssgBranch * gnd_lights_branch;
+    ssgBranch * rwy_lights_branch;
+    ssgBranch * models_branch;
+    ssgBranch * aircraft_branch;
+
 public:
 
     FGGlobals();
@@ -268,6 +279,40 @@ public:
        channel_options_list = l;
     }
 
+    inline ssgRoot * get_scene_graph () const { return scene_graph; }
+    inline void set_scene_graph (ssgRoot * s) { scene_graph = s; }
+
+    inline ssgBranch * get_terrain_branch () const { return terrain_branch; }
+    inline void set_terrain_branch (ssgBranch * t) { terrain_branch = t; }
+
+    inline ssgBranch * get_gnd_lights_branch () const {
+      return gnd_lights_branch;
+    }
+    inline void set_gnd_lights_branch (ssgBranch * t) {
+      gnd_lights_branch = t;
+    }
+
+    inline ssgBranch * get_rwy_lights_branch () const {
+      return rwy_lights_branch;
+    }
+    inline void set_rwy_lights_branch (ssgBranch * t) {
+      rwy_lights_branch = t;
+    }
+
+    inline ssgBranch * get_models_branch () const {
+      return models_branch;
+    }
+    inline void set_models_branch (ssgBranch * t) {
+      models_branch = t;
+    }
+
+    inline ssgBranch * get_aircraft_branch () const {
+      return aircraft_branch;
+    }
+    inline void set_aircraft_branch (ssgBranch * t) {
+      aircraft_branch = t;
+    }
+
 
     /**
      * Save the current state as the initial state.
index 9ce9970a558511b1307d56b1c93fa309d822823c..c2b46a6bfc68f9d29073c623c60729d10dc0cd7b 100644 (file)
@@ -183,12 +183,6 @@ static long global_multi_loop;
 // forward declaration
 void fgReshape( int width, int height );
 
-// ssg variables
-ssgRoot *scene = NULL;
-ssgBranch *terrain_branch = NULL;
-ssgBranch *gnd_lights_branch = NULL;
-ssgBranch *rwy_lights_branch = NULL;
-
 // fog constants.  I'm a little nervous about putting actual code out
 // here but it seems to work (?)
 static const double m_log01 = -log( 0.01 );
@@ -375,7 +369,7 @@ void trRenderFrame( void ) {
     ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
     glEnable( GL_DEPTH_TEST );
     ssgSetNearFar( scene_nearplane, scene_farplane );
-    ssgCullAndDraw( scene );
+    ssgCullAndDraw( globals->get_scene_graph() );
 
     // draw the lights
     glFogf (GL_FOG_DENSITY, fog_exp2_punch_through);
@@ -655,7 +649,7 @@ void fgRenderFrame( void ) {
        glEnable( GL_DEPTH_TEST );
 
         ssgSetNearFar( scene_nearplane, scene_farplane );
-       ssgCullAndDraw( scene );
+       ssgCullAndDraw( globals->get_scene_graph() );
 
        // change state for lighting here
 
@@ -1483,6 +1477,35 @@ int mainLoop( int argc, char **argv ) {
     SGPath modelpath( globals->get_fg_root() );
     ssgModelPath( (char *)modelpath.c_str() );
   
+    // Scene graph root
+    globals->set_scene_graph(new ssgRoot);
+    globals->get_scene_graph()->setName( "Scene" );
+
+    lighting = new ssgRoot;
+    lighting->setName( "Lighting" );
+
+    // Terrain branch
+    globals->set_terrain_branch(new ssgBranch);
+    globals->get_terrain_branch()->setName( "Terrain" );
+    globals->get_scene_graph()->addKid( globals->get_terrain_branch() );
+
+    globals->set_models_branch(new ssgBranch);
+    globals->get_models_branch()->setName( "Models" );
+    globals->get_scene_graph()->addKid( globals->get_models_branch() );
+
+    globals->set_aircraft_branch(new ssgBranch);
+    globals->get_aircraft_branch()->setName( "Aircraft" );
+    globals->get_scene_graph()->addKid( globals->get_aircraft_branch() );
+
+    // Lighting
+    globals->set_gnd_lights_branch(new ssgBranch);
+    globals->get_gnd_lights_branch()->setName( "Ground Lighting" );
+    lighting->addKid( globals->get_gnd_lights_branch() );
+
+    globals->set_rwy_lights_branch(new ssgBranch);
+    globals->get_rwy_lights_branch()->setName( "Runway Lighting" );
+    lighting->addKid( globals->get_rwy_lights_branch() );
+
     ////////////////////////////////////////////////////////////////////
     // Initialize the general model subsystem.
     ////////////////////////////////////////////////////////////////////
@@ -1509,13 +1532,6 @@ int mainLoop( int argc, char **argv ) {
     viewmgr->bind();
 
 
-    // Scene graph root
-    scene = new ssgRoot;
-    scene->setName( "Scene" );
-
-    lighting = new ssgRoot;
-    lighting->setName( "Lighting" );
-
     // Initialize the sky
     SGPath ephem_data_path( globals->get_fg_root() );
     ephem_data_path.append( "Astro" );
@@ -1555,20 +1571,6 @@ int mainLoop( int argc, char **argv ) {
     SGMagVar *magvar = new SGMagVar();
     globals->set_mag( magvar );
 
-    // Terrain branch
-    terrain_branch = new ssgBranch;
-    terrain_branch->setName( "Terrain" );
-    scene->addKid( terrain_branch );
-
-    // Lighting
-    gnd_lights_branch = new ssgBranch;
-    gnd_lights_branch->setName( "Ground Lighting" );
-    lighting->addKid( gnd_lights_branch );
-
-    rwy_lights_branch = new ssgBranch;
-    rwy_lights_branch->setName( "Runway Lighting" );
-    lighting->addKid( rwy_lights_branch );
-
     // airport = new ssgBranch;
     // airport->setName( "Airport Lighting" );
     // lighting->addKid( airport );
@@ -1580,7 +1582,8 @@ int mainLoop( int argc, char **argv ) {
 #ifdef FG_NETWORK_OLK
     // Do the network intialization
     if ( fgGetBool("/sim/networking/network-olk") ) {
-       printf("Multipilot mode %s\n", fg_net_init( scene ) );
+       printf("Multipilot mode %s\n",
+              fg_net_init( globals->get_scene_graph() ) );
     }
 #endif
 
@@ -1819,7 +1822,7 @@ void fgLoadDCS(void) {
                                                    //dummy_tile->lightmaps_sequence->setTraversalMaskBits( SSGTRAV_HOT );
                                                        lightpoints_transform->addKid( dummy_tile->lightmaps_sequence );
                                                        lightpoints_transform->ref();
-                                                       gnd_lights_branch->addKid( lightpoints_transform );
+                                                       globals->get_gnd_lights_branch()->addKid( lightpoints_transform );
                                                } 
                                        } //if in1 
                 } //if objc
@@ -1833,7 +1836,7 @@ void fgLoadDCS(void) {
 
         SG_LOG ( SG_TERRAIN, SG_ALERT, "Finished object processing." );
 
-        terrain_branch->addKid( ship_sel ); //add selector node to root node 
+        globals->get_terrain_branch()->addKid( ship_sel ); //add selector node to root node 
     }
 
     return;
index 16c1f1c56a9a8dc73f4ffc3b36bd339512a6a83d..fd6bda35e116e4dae23d277444c30847599a28b9 100644 (file)
@@ -30,6 +30,7 @@
 
 FGAircraftModel::FGAircraftModel ()
   : _aircraft(0),
+    _selector(new ssgSelector),
     _scene(new ssgRoot),
     _nearplane(0.01f),
     _farplane(100.0f)
@@ -40,6 +41,8 @@ FGAircraftModel::~FGAircraftModel ()
 {
   delete _aircraft;
   delete _scene;
+                               // SSG will delete it
+  globals->get_aircraft_branch()->removeKid(_selector);
 }
 
 void 
@@ -48,6 +51,8 @@ FGAircraftModel::init ()
   _aircraft = new FG3DModel;
   _aircraft->init(fgGetString("/sim/model/path", "Models/Geometry/glider.ac"));
   _scene->addKid(_aircraft->getSceneGraph());
+  _selector->addKid(_aircraft->getSceneGraph());
+  globals->get_aircraft_branch()->addKid(_selector);
 }
 
 void 
@@ -90,13 +95,14 @@ FGAircraftModel::draw ()
                                // FIXME: view number shouldn't be 
                                // hard-coded.
   int view_number = globals->get_viewmgr()->get_current();
-  if (_aircraft->getVisible()) {
-    if (view_number == 0) {
-      glClearDepth(1);
-      glClear(GL_DEPTH_BUFFER_BIT);
-      ssgSetNearFar(_nearplane, _farplane);
-    }
+  if (_aircraft->getVisible() && view_number == 0) {
+    glClearDepth(1);
+    glClear(GL_DEPTH_BUFFER_BIT);
+    ssgSetNearFar(_nearplane, _farplane);
     ssgCullAndDraw(_scene);
+    _selector->select(0);
+  } else {
+    _selector->select(1);
   }
 
 }
index 743f162ea6a87a6f36ae672e60d6066ed21005b7..08ffd139fcc0151a354254ccc39588951e76dbc8 100644 (file)
@@ -39,6 +39,7 @@ public:
 private:
 
   FG3DModel * _aircraft;
+  ssgSelector * _selector;
   ssgRoot * _scene;
   float _nearplane;
   float _farplane;
index 90fd78cc229aa04f76a07b4046062226b449d1ef..4ed1c6bbbdde00f149ca50f0b8d54552ab1c721d 100644 (file)
@@ -9,18 +9,17 @@
 
 
 FGModelMgr::FGModelMgr ()
-  : _scene(new ssgRoot),
-    _nearplane(0.5f),
-    _farplane(120000.0f)
+  : _selector(new ssgSelector)
 {
 }
 
 FGModelMgr::~FGModelMgr ()
 {
   for (int i = 0; i < _instances.size(); i++) {
+    globals->get_models_branch()
+      ->removeKid(_instances[i]->model->getSceneGraph());
     delete _instances[i];
   }
-  delete _scene;
 }
 
 void
@@ -76,8 +75,8 @@ FGModelMgr::init ()
     else
       model->setHeadingDeg(node->getDoubleValue("heading-deg"));
 
-                               // Add this model to the scene graph
-    _scene->addKid(model->getSceneGraph());
+                               // Add this model to the global scene graph
+    globals->get_scene_graph()->addKid(model->getSceneGraph());
 
                                // Save this instance for updating
     _instances.push_back(instance);
@@ -124,8 +123,8 @@ FGModelMgr::update (int dt)
 void
 FGModelMgr::draw ()
 {
-  ssgSetNearFar(_nearplane, _farplane);
-  ssgCullAndDraw(_scene);
+//   ssgSetNearFar(_nearplane, _farplane);
+//   ssgCullAndDraw(_scene);
 }
 
 
index 1ea8aef6d5c274d0a93f9947bc3f07cf63243da7..15933d63cc42122e2f650abc0c9a6e4c7144e6ad 100644 (file)
@@ -57,9 +57,7 @@ private:
 
   vector<Instance *> _instances;
 
-  ssgRoot * _scene;
-  float _nearplane;
-  float _farplane;
+  ssgSelector * _selector;
 
 };
 
index 21ef767fd171b38349bc91de4366861981dcdcb4..9e2d6eb19f93986e317e512f9229c96fffaf4727 100644 (file)
@@ -20,8 +20,6 @@
 
 #include "hitlist.hxx"
 
-extern ssgBranch *terrain_branch;
-
 // forward declaration of our helper/convenience functions
 static void sgMultMat4(sgdMat4 dst, sgdMat4 m1, sgMat4 m2);
 static void ssgGetEntityTransform(ssgEntity *entity, sgMat4 m );
@@ -509,8 +507,7 @@ bool fgCurrentElev( sgdVec3 abs_view_pos, sgdVec3 scenery_center,
     sgdCopyVec3(orig, view_pos );
     sgdCopyVec3(dir, abs_view_pos );
 
-    // !! why is terrain not globals->get_terrain()
-    hit_list->Intersect( terrain_branch, orig, dir );
+    hit_list->Intersect( globals->get_terrain_branch(), orig, dir );
 
     int this_hit=0;
     Point3D geoc;
index 4968b08e0fed26da8cf2370edb0bbc8404f85d80..f7f599fb9b7e669962849727e9fb489cbc9bd814 100644 (file)
@@ -182,8 +182,6 @@ bool FGNewCache::make_space() {
 
 // Clear all completely loaded tiles (ignores partially loaded tiles)
 void FGNewCache::clear_cache() {
-    // This is a hack that should really get cleaned up at some point
-    extern ssgBranch *terrain_branch;
 
     tile_map_iterator current = tile_cache.begin();
     tile_map_iterator end = tile_cache.end();
@@ -199,7 +197,7 @@ void FGNewCache::clear_cache() {
     }
 
     // and ... just in case we missed something ... 
-    terrain_branch->removeAllKids();
+    globals->get_terrain_branch()->removeAllKids();
 }
 
 
index 0847248d44c3d265c05b7e1d5c23766aeb09fbc1..19a46febf8331c76f9bdc70560b8a034a925af67 100644 (file)
 
 #define TEST_LAST_HIT_CACHE
 
-extern ssgRoot *scene;
-extern ssgBranch *terrain_branch;      // branch that holds world geometry
-extern ssgBranch *gnd_lights_branch;   // branch that holds ground lighting
-extern ssgBranch *rwy_lights_branch;   // branch that holds runway lighting
-
 // the tile manager
 FGTileMgr global_tile_mgr;
 
@@ -335,9 +330,9 @@ int FGTileMgr::update( double lon, double lat, double visibility_meters ) {
        FGTileEntry* e = attach_queue.front();
        attach_queue.pop();
 #endif
-       e->add_ssg_nodes( terrain_branch,
-                         gnd_lights_branch,
-                         rwy_lights_branch );
+       e->add_ssg_nodes( globals->get_terrain_branch(),
+                         globals->get_gnd_lights_branch(),
+                         globals->get_rwy_lights_branch() );
        // cout << "Adding ssg nodes for "
     }