]> git.mxchange.org Git - flightgear.git/blob - src/Model/acmodel.cxx
Get rid of non-portable fmax call.
[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 <plib/sg.h>
13 #include <plib/ssg.h>
14
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
20 #include <Main/globals.hxx>
21 #include <Main/fg_props.hxx>
22 #include <Main/viewmgr.hxx>
23 #include "acmodel.hxx"
24
25
26 \f
27 ////////////////////////////////////////////////////////////////////////
28 // Implementation of FGAircraftModel
29 ////////////////////////////////////////////////////////////////////////
30
31 FGAircraftModel::FGAircraftModel ()
32   : _aircraft(0),
33     _scene(new ssgRoot),
34     _nearplane(0.01f),
35     _farplane(5000.0f)
36 {
37 }
38
39 FGAircraftModel::~FGAircraftModel ()
40 {
41   delete _aircraft;
42   delete _scene;
43 }
44
45 void 
46 FGAircraftModel::init ()
47 {
48   _aircraft = new FG3DModel;
49   _aircraft->init(fgGetString("/sim/model/path", "Models/Geometry/glider.ac"));
50   _scene->addKid(_aircraft->getSceneGraph());
51 }
52
53 void 
54 FGAircraftModel::bind ()
55 {
56   // No-op
57 }
58
59 void 
60 FGAircraftModel::unbind ()
61 {
62   // No-op
63 }
64
65 void
66 FGAircraftModel::update (int dt)
67 {
68   int view_number = globals->get_viewmgr()->get_current();
69
70   if (view_number == 0 && !fgGetBool("/sim/view/internal")) {
71     _aircraft->setVisible(false);
72   } else {
73     _aircraft->setVisible(true);
74   }
75
76   _aircraft->setPosition(fgGetDouble("/position/longitude-deg"),
77                          fgGetDouble("/position/latitude-deg"),
78                          fgGetDouble("/position/altitude-ft"));
79   _aircraft->setOrientation(fgGetDouble("/orientation/roll-deg"),
80                             fgGetDouble("/orientation/pitch-deg"),
81                             fgGetDouble("/orientation/heading-deg"));
82   _aircraft->update(dt);
83
84 }
85
86 void
87 FGAircraftModel::draw ()
88 {
89                                 // OK, now adjust the clip planes and draw
90                                 // FIXME: view number shouldn't be 
91                                 // hard-coded.
92   if (_aircraft->getVisible()) {
93     glClearDepth(1);
94     glClear(GL_DEPTH_BUFFER_BIT);
95     ssgSetNearFar(_nearplane, _farplane);
96     ssgCullAndDraw(_scene);
97   }
98
99 }
100
101 // end of model.cxx