1 // FGMagRibbon.cxx - Built-in layer for the magnetic compass ribbon layer.
3 // Written by David Megginson, started January 2000.
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.
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.
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.
25 #include "FGMagRibbon.hxx"
28 FGMagRibbon::FGMagRibbon (int w, int h)
29 : FGTexturedLayer(w, h)
31 FGCroppedTexture texture("Aircraft/Instruments/Textures/compass-ribbon.rgb");
34 fgGetNode("/instrumentation/magnetic-compass/indicated-heading-deg",
41 double heading = _magcompass_node->getDoubleValue();
42 double xoffset, yoffset;
44 while (heading >= 360.0) {
47 while (heading < 0.0) {
51 if (heading >= 60.0 && heading <= 180.0) {
52 xoffset = heading / 240.0;
54 } else if (heading >= 150.0 && heading <= 270.0) {
55 xoffset = (heading - 90.0) / 240.0;
57 } else if (heading >= 240.0 && heading <= 360.0) {
58 xoffset = (heading - 180.0) / 240.0;
63 xoffset = (heading - 270.0) / 240.0;
67 xoffset = 1.0 - xoffset;
68 // Adjust to put the number in the centre
71 FGCroppedTexture *t = getTexture();
72 t->setCrop(xoffset, yoffset, xoffset + 0.5, yoffset + 0.25);
74 glPushAttrib(GL_DEPTH_BUFFER_BIT);
75 glEnable(GL_DEPTH_TEST);
76 FGTexturedLayer::draw();
80 // end of FGMagRibbon.cxx