Debian Codegraph @

src/Cockpit/built_in/FGMagRibbon.cxx

raw symbols SCIP
1 // FGMagRibbon.cxx - Built-in layer for the magnetic compass ribbon layer.
2 //
3 // Written by David Megginson, started January 2000.
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 //
19 // $Id$
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include "FGMagRibbon.hxx"
26
27
28 FGMagRibbon::FGMagRibbon (int w, int h)
29 : FGTexturedLayer(w, h)
30 {
31 FGCroppedTexture texture("Aircraft/Instruments/Textures/compass-ribbon.rgb");
32 setTexture(texture);
33 _magcompass_node =
34 fgGetNode("/instrumentation/magnetic-compass/indicated-heading-deg",
35 true);
36 }
37
38 void
39 FGMagRibbon::draw (osg::State& state)
40 {
41 double heading = _magcompass_node->getDoubleValue();
42 double xoffset, yoffset;
43
44 while (heading >= 360.0) {
45 heading -= 360.0;
46 }
47 while (heading < 0.0) {
48 heading += 360.0;
49 }
50
51 if (heading >= 60.0 && heading <= 180.0) {
52 xoffset = heading / 240.0;
53 yoffset = 0.75;
54 } else if (heading >= 150.0 && heading <= 270.0) {
55 xoffset = (heading - 90.0) / 240.0;
56 yoffset = 0.50;
57 } else if (heading >= 240.0 && heading <= 360.0) {
58 xoffset = (heading - 180.0) / 240.0;
59 yoffset = 0.25;
60 } else {
61 if (heading < 270.0)
62 heading += 360.0;
63 xoffset = (heading - 270.0) / 240.0;
64 yoffset = 0.0;
65 }
66
67 xoffset = 1.0 - xoffset;
68 // Adjust to put the number in the centre
69 xoffset -= 0.25;
70
71 FGCroppedTexture *t = getTexture();
72 t->setCrop(xoffset, yoffset, xoffset + 0.5, yoffset + 0.25);
73
74 static osg::ref_ptr<osg::StateSet> stateSet = new osg::StateSet;
75 stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
76
77 state.pushStateSet(stateSet.get());
78 state.apply();
79
80 FGTexturedLayer::draw(state);
81
82 state.popStateSet();
83 state.apply();
84 }
85
86 // end of FGMagRibbon.cxx