1 // model.cxx - manage a 3D aircraft model.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain, and comes with no warranty.
10 #include <string.h> // for strcmp()
15 #include <simgear/compiler.h>
16 #include <simgear/debug/logstream.hxx>
17 #include <simgear/structure/exception.hxx>
18 #include <simgear/misc/sg_path.hxx>
19 #include <simgear/scene/model/placement.hxx>
21 #include <Main/globals.hxx>
22 #include <Main/fg_props.hxx>
23 #include <Main/viewmgr.hxx>
24 #include <Main/viewer.hxx>
25 #include <Scenery/scenery.hxx>
27 #include "model_panel.hxx"
29 #include "acmodel.hxx"
33 ////////////////////////////////////////////////////////////////////////
34 // Implementation of FGAircraftModel
35 ////////////////////////////////////////////////////////////////////////
37 FGAircraftModel::FGAircraftModel ()
39 _selector(new ssgSelector),
46 FGAircraftModel::~FGAircraftModel ()
51 globals->get_scenery()->get_aircraft_branch()->removeKid(_selector);
55 FGAircraftModel::init ()
57 _aircraft = new SGModelPlacement;
58 string path = fgGetString("/sim/model/path", "Models/Geometry/glider.ac");
60 ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(),
63 globals->get_sim_time_sec() );
64 _aircraft->init( model );
65 } catch (const sg_exception &ex) {
66 SG_LOG(SG_GENERAL, SG_ALERT, "Failed to load aircraft from " << path);
67 SG_LOG(SG_GENERAL, SG_ALERT, "(Falling back to glider.ac.)");
68 ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(),
69 "Models/Geometry/glider.ac",
71 globals->get_sim_time_sec() );
72 _aircraft->init( model );
74 _scene->addKid(_aircraft->getSceneGraph());
75 _selector->addKid(_aircraft->getSceneGraph());
76 globals->get_scenery()->get_aircraft_branch()->addKid(_selector);
80 FGAircraftModel::bind ()
86 FGAircraftModel::unbind ()
92 FGAircraftModel::update (double dt)
94 int view_number = globals->get_viewmgr()->get_current();
95 int is_internal = globals->get_current_view()->getInternal();
97 if (view_number == 0 && !is_internal) {
98 _aircraft->setVisible(false);
100 _aircraft->setVisible(true);
103 _aircraft->setPosition(fgGetDouble("/position/longitude-deg"),
104 fgGetDouble("/position/latitude-deg"),
105 fgGetDouble("/position/altitude-ft"));
106 _aircraft->setOrientation(fgGetDouble("/orientation/roll-deg"),
107 fgGetDouble("/orientation/pitch-deg"),
108 fgGetDouble("/orientation/heading-deg"));
109 _aircraft->update( globals->get_scenery()->get_center() );
114 FGAircraftModel::draw ()
116 // OK, now adjust the clip planes and draw
117 // FIXME: view number shouldn't be
119 bool is_internal = globals->get_current_view()->getInternal();
120 if (_aircraft->getVisible() && is_internal) {
122 glClear(GL_DEPTH_BUFFER_BIT);
123 ssgSetNearFar(_nearplane, _farplane);
124 ssgCullAndDraw(_scene);
125 _selector->select(0);
127 _selector->select(1);