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/misc/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 <Scenery/scenery.hxx>
26 #include "model_panel.hxx"
28 #include "acmodel.hxx"
32 ////////////////////////////////////////////////////////////////////////
33 // Implementation of FGAircraftModel
34 ////////////////////////////////////////////////////////////////////////
36 FGAircraftModel::FGAircraftModel ()
38 _selector(new ssgSelector),
45 FGAircraftModel::~FGAircraftModel ()
50 globals->get_scenery()->get_aircraft_branch()->removeKid(_selector);
54 FGAircraftModel::init ()
56 _aircraft = new SGModelPlacement;
57 string path = fgGetString("/sim/model/path", "Models/Geometry/glider.ac");
59 ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(),
62 globals->get_sim_time_sec() );
63 _aircraft->init( model );
64 } catch (const sg_exception &ex) {
65 SG_LOG(SG_GENERAL, SG_ALERT, "Failed to load aircraft from " << path);
66 SG_LOG(SG_GENERAL, SG_ALERT, "(Falling back to glider.ac.)");
67 ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(),
68 "Models/Geometry/glider.ac",
70 globals->get_sim_time_sec() );
71 _aircraft->init( model );
73 _scene->addKid(_aircraft->getSceneGraph());
74 _selector->addKid(_aircraft->getSceneGraph());
75 globals->get_scenery()->get_aircraft_branch()->addKid(_selector);
79 FGAircraftModel::bind ()
85 FGAircraftModel::unbind ()
91 FGAircraftModel::update (double dt)
93 int view_number = globals->get_viewmgr()->get_current();
95 if (view_number == 0 && !fgGetBool("/sim/view/internal")) {
96 _aircraft->setVisible(false);
98 _aircraft->setVisible(true);
101 _aircraft->setPosition(fgGetDouble("/position/longitude-deg"),
102 fgGetDouble("/position/latitude-deg"),
103 fgGetDouble("/position/altitude-ft"));
104 _aircraft->setOrientation(fgGetDouble("/orientation/roll-deg"),
105 fgGetDouble("/orientation/pitch-deg"),
106 fgGetDouble("/orientation/heading-deg"));
107 _aircraft->update( globals->get_scenery()->get_center() );
112 FGAircraftModel::draw ()
114 // OK, now adjust the clip planes and draw
115 // FIXME: view number shouldn't be
117 int view_number = globals->get_viewmgr()->get_current();
118 if (_aircraft->getVisible() && view_number == 0) {
120 glClear(GL_DEPTH_BUFFER_BIT);
121 ssgSetNearFar(_nearplane, _farplane);
122 ssgCullAndDraw(_scene);
123 _selector->select(0);
125 _selector->select(1);