]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/built_in/FGMagRibbon.cxx
Yank out all the glut dependencies and concentrate them in a (easily
[flightgear.git] / src / Cockpit / built_in / FGMagRibbon.cxx
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., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 //  $Id$
20
21
22 #include "FGMagRibbon.hxx"
23
24
25 FGMagRibbon::FGMagRibbon (int w, int h)
26   : FGTexturedLayer(w, h)
27 {
28   FGCroppedTexture texture("Aircraft/Instruments/Textures/compass-ribbon.rgb");
29   setTexture(texture);
30   _magcompass_node =
31       fgGetNode("/instrumentation/magnetic-compass/indicated-heading-deg",
32                 true);
33 }
34
35 void
36 FGMagRibbon::draw ()
37 {
38   double heading = _magcompass_node->getDoubleValue();
39   double xoffset, yoffset;
40
41   while (heading >= 360.0) {
42     heading -= 360.0;
43   }
44   while (heading < 0.0) {
45     heading += 360.0;
46   }
47
48   if (heading >= 60.0 && heading <= 180.0) {
49     xoffset = heading / 240.0;
50     yoffset = 0.75;
51   } else if (heading >= 150.0 && heading <= 270.0) {
52     xoffset = (heading - 90.0) / 240.0;
53     yoffset = 0.50;
54   } else if (heading >= 240.0 && heading <= 360.0) {
55     xoffset = (heading - 180.0) / 240.0;
56     yoffset = 0.25;
57   } else {
58     if (heading < 270.0)
59       heading += 360.0;
60     xoffset = (heading - 270.0) / 240.0;
61     yoffset = 0.0;
62   }
63
64   xoffset = 1.0 - xoffset;
65                                 // Adjust to put the number in the centre
66   xoffset -= 0.25;
67
68   FGCroppedTexture &t = getTexture();
69   t.setCrop(xoffset, yoffset, xoffset + 0.5, yoffset + 0.25);
70
71   glPushAttrib(GL_DEPTH_BUFFER_BIT);
72   glEnable(GL_DEPTH_TEST);
73   FGTexturedLayer::draw();
74   glPopAttrib();
75 }
76
77 // end of FGMagRibbon.cxx