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>
20 #include <Main/globals.hxx>
21 #include <Main/fg_props.hxx>
22 #include <Main/viewmgr.hxx>
23 #include <Scenery/scenery.hxx>
25 #include "acmodel.hxx"
30 ////////////////////////////////////////////////////////////////////////
31 // Implementation of FGAircraftModel
32 ////////////////////////////////////////////////////////////////////////
34 FGAircraftModel::FGAircraftModel ()
36 _selector(new ssgSelector),
43 FGAircraftModel::~FGAircraftModel ()
48 globals->get_scenery()->get_aircraft_branch()->removeKid(_selector);
52 FGAircraftModel::init ()
54 _aircraft = new FGModelPlacement;
55 string path = fgGetString("/sim/model/path", "Models/Geometry/glider.ac");
57 _aircraft->init( globals->get_fg_root(),
60 globals->get_sim_time_sec() );
61 } catch (const sg_exception &ex) {
62 SG_LOG(SG_GENERAL, SG_ALERT, "Failed to load aircraft from " << path);
63 SG_LOG(SG_GENERAL, SG_ALERT, "(Falling back to glider.ac.)");
64 _aircraft->init( globals->get_fg_root(),
65 "Models/Geometry/glider.ac",
67 globals->get_sim_time_sec() );
69 _scene->addKid(_aircraft->getSceneGraph());
70 _selector->addKid(_aircraft->getSceneGraph());
71 globals->get_scenery()->get_aircraft_branch()->addKid(_selector);
75 FGAircraftModel::bind ()
81 FGAircraftModel::unbind ()
87 FGAircraftModel::update (double dt)
89 int view_number = globals->get_viewmgr()->get_current();
91 if (view_number == 0 && !fgGetBool("/sim/view/internal")) {
92 _aircraft->setVisible(false);
94 _aircraft->setVisible(true);
97 _aircraft->setPosition(fgGetDouble("/position/longitude-deg"),
98 fgGetDouble("/position/latitude-deg"),
99 fgGetDouble("/position/altitude-ft"));
100 _aircraft->setOrientation(fgGetDouble("/orientation/roll-deg"),
101 fgGetDouble("/orientation/pitch-deg"),
102 fgGetDouble("/orientation/heading-deg"));
103 _aircraft->update( globals->get_scenery()->get_center() );
108 FGAircraftModel::draw ()
110 // OK, now adjust the clip planes and draw
111 // FIXME: view number shouldn't be
113 int view_number = globals->get_viewmgr()->get_current();
114 if (_aircraft->getVisible() && view_number == 0) {
116 glClear(GL_DEPTH_BUFFER_BIT);
117 ssgSetNearFar(_nearplane, _farplane);
118 ssgCullAndDraw(_scene);
119 _selector->select(0);
121 _selector->select(1);