#include "AIEntity.hxx"
-extern ssgRoot* scene; // The global Flightgear scene graph
-
FGAIEntity::~FGAIEntity() {
}
sgCoord shippos;
FastWorldCoordinate(&shippos, sc);
position->setTransform( &shippos );
- scene->addKid(position);
+ globals->get_scene_graph()->addKid(position);
//cout << "Transform called\n";
}
class FGAircraftModel;
class FGModelMgr;
+class ssgRoot;
+class ssgBranch;
+
/**
* Bucket for subsystem pointers representing the sim's state.
// 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();
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.
// 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 );
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);
glEnable( GL_DEPTH_TEST );
ssgSetNearFar( scene_nearplane, scene_farplane );
- ssgCullAndDraw( scene );
+ ssgCullAndDraw( globals->get_scene_graph() );
// change state for lighting here
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.
////////////////////////////////////////////////////////////////////
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" );
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 );
#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
//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
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;
FGAircraftModel::FGAircraftModel ()
: _aircraft(0),
+ _selector(new ssgSelector),
_scene(new ssgRoot),
_nearplane(0.01f),
_farplane(100.0f)
{
delete _aircraft;
delete _scene;
+ // SSG will delete it
+ globals->get_aircraft_branch()->removeKid(_selector);
}
void
_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
// 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);
}
}
private:
FG3DModel * _aircraft;
+ ssgSelector * _selector;
ssgRoot * _scene;
float _nearplane;
float _farplane;
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
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);
void
FGModelMgr::draw ()
{
- ssgSetNearFar(_nearplane, _farplane);
- ssgCullAndDraw(_scene);
+// ssgSetNearFar(_nearplane, _farplane);
+// ssgCullAndDraw(_scene);
}
vector<Instance *> _instances;
- ssgRoot * _scene;
- float _nearplane;
- float _farplane;
+ ssgSelector * _selector;
};
#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 );
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;
// 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();
}
// and ... just in case we missed something ...
- terrain_branch->removeAllKids();
+ globals->get_terrain_branch()->removeAllKids();
}
#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;
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 "
}