]> git.mxchange.org Git - flightgear.git/blob - src/Model/acmodel.cxx
Add normalised glideslope deviation property to nav-radio.
[flightgear.git] / src / Model / acmodel.cxx
1 // model.cxx - manage a 3D aircraft model.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain, and comes with no warranty.
5
6 #ifdef HAVE_CONFIG_H
7 #  include <config.h>
8 #endif
9
10 #include <string.h>             // for strcmp()
11
12 #include <simgear/compiler.h>
13 #include <simgear/debug/logstream.hxx>
14 #include <simgear/structure/exception.hxx>
15 #include <simgear/misc/sg_path.hxx>
16 #include <simgear/scene/model/placement.hxx>
17 #include <simgear/scene/util/SGNodeMasks.hxx>
18
19 #include <Main/globals.hxx>
20 #include <Main/fg_props.hxx>
21 #include <Main/renderer.hxx>
22 #include <Main/viewmgr.hxx>
23 #include <Main/viewer.hxx>
24 #include <Scenery/scenery.hxx>
25
26 #include "model_panel.hxx"
27
28 #include "acmodel.hxx"
29
30 \f
31 ////////////////////////////////////////////////////////////////////////
32 // Implementation of FGAircraftModel
33 ////////////////////////////////////////////////////////////////////////
34
35 FGAircraftModel::FGAircraftModel ()
36   : _aircraft(0)
37 {
38 }
39
40 FGAircraftModel::~FGAircraftModel ()
41 {
42   osg::Node* node = _aircraft->getSceneGraph();
43   globals->get_scenery()->get_aircraft_branch()->removeChild(node);
44
45   delete _aircraft;
46 }
47
48 void 
49 FGAircraftModel::init ()
50 {
51   _aircraft = new SGModelPlacement;
52   string path = fgGetString("/sim/model/path", "Models/Geometry/glider.ac");
53   try {
54     osg::Node *model = fgLoad3DModelPanel( path, globals->get_props());
55     _aircraft->init( model );
56   } catch (const sg_exception &ex) {
57     SG_LOG(SG_GENERAL, SG_ALERT, "Failed to load aircraft from " << path << ':');
58     SG_LOG(SG_GENERAL, SG_ALERT, "  " << ex.getFormattedMessage());
59     SG_LOG(SG_GENERAL, SG_ALERT, "(Falling back to glider.ac.)");
60     osg::Node *model = fgLoad3DModelPanel( "Models/Geometry/glider.ac",
61                                            globals->get_props());
62     _aircraft->init( model );
63   }
64   osg::Node* node = _aircraft->getSceneGraph();
65   // Do not do altitude computations with that model
66   node->setNodeMask(~SG_NODEMASK_TERRAIN_BIT);
67   globals->get_scenery()->get_aircraft_branch()->addChild(node);
68 }
69
70 void
71 FGAircraftModel::bind ()
72 {
73   // No-op
74 }
75
76 void
77 FGAircraftModel::unbind ()
78 {
79   // No-op
80 }
81
82 void
83 FGAircraftModel::update (double dt)
84 {
85   int view_number = globals->get_viewmgr()->get_current();
86   int is_internal = fgGetBool("/sim/current-view/internal");
87
88   if (view_number == 0 && !is_internal) {
89     _aircraft->setVisible(false);
90   } else {
91     _aircraft->setVisible(true);
92   }
93
94   _aircraft->setPosition(fgGetDouble("/position/longitude-deg"),
95                          fgGetDouble("/position/latitude-deg"),
96                          fgGetDouble("/position/altitude-ft"));
97   _aircraft->setOrientation(fgGetDouble("/orientation/roll-deg"),
98                             fgGetDouble("/orientation/pitch-deg"),
99                             fgGetDouble("/orientation/heading-deg"));
100   _aircraft->update();
101 }
102
103
104 // end of model.cxx