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(path);
58 } catch (const sg_exception &ex) {
59 SG_LOG(SG_GENERAL, SG_ALERT, "Failed to load aircraft from " << path);
60 SG_LOG(SG_GENERAL, SG_ALERT, "(Falling back to glider.ac.)");
61 _aircraft->init("Models/Geometry/glider.ac");
63 _scene->addKid(_aircraft->getSceneGraph());
64 _selector->addKid(_aircraft->getSceneGraph());
65 globals->get_scenery()->get_aircraft_branch()->addKid(_selector);
69 FGAircraftModel::bind ()
75 FGAircraftModel::unbind ()
81 FGAircraftModel::update (double dt)
83 int view_number = globals->get_viewmgr()->get_current();
85 if (view_number == 0 && !fgGetBool("/sim/view/internal")) {
86 _aircraft->setVisible(false);
88 _aircraft->setVisible(true);
91 _aircraft->setPosition(fgGetDouble("/position/longitude-deg"),
92 fgGetDouble("/position/latitude-deg"),
93 fgGetDouble("/position/altitude-ft"));
94 _aircraft->setOrientation(fgGetDouble("/orientation/roll-deg"),
95 fgGetDouble("/orientation/pitch-deg"),
96 fgGetDouble("/orientation/heading-deg"));
102 FGAircraftModel::draw ()
104 // OK, now adjust the clip planes and draw
105 // FIXME: view number shouldn't be
107 int view_number = globals->get_viewmgr()->get_current();
108 if (_aircraft->getVisible() && view_number == 0) {
110 glClear(GL_DEPTH_BUFFER_BIT);
111 ssgSetNearFar(_nearplane, _farplane);
112 ssgCullAndDraw(_scene);
113 _selector->select(0);
115 _selector->select(1);