]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_dial.cxx
new HUD (work in progress)
[flightgear.git] / src / Instrumentation / HUD / HUD_dial.cxx
1 // HUD_dial.cxx -- HUD Dial Instrument
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  [micheleamerica#geocities:com]
6 // Copyright (C) 2006  Melchior FRANZ  [mfranz#aon:at]
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #include "HUD.hxx"
23
24
25 HUD::Dial::Dial(HUD *hud, const SGPropertyNode *n, float x, float y) :
26     Scale(hud, n, x, y),
27     _radius(n->getFloatValue("radius")),
28     _divisions(n->getIntValue("divisions"))
29 {
30 }
31
32
33 void HUD::Dial::draw(void)
34 {
35     if (!_input.isValid())
36         return;
37
38     const int BUFSIZE = 80;
39     char buf[BUFSIZE];
40
41     Rect scrn_rect = get_location();
42
43     float x, y;
44     float i;
45     y = (float)(scrn_rect.top);
46     x = (float)(scrn_rect.left);
47     glEnable(GL_POINT_SMOOTH);
48     glPointSize(3.0);
49
50     float incr = 360.0 / _divisions;
51     for (i = 0.0; i < 360.0; i += incr) {
52         float i1 = i * SGD_DEGREES_TO_RADIANS;
53         float x1 = x + _radius * cos(i1);
54         float y1 = y + _radius * sin(i1);
55
56         glBegin(GL_POINTS);
57         glVertex2f(x1, y1);
58         glEnd();
59     }
60     glPointSize(1.0);
61     glDisable(GL_POINT_SMOOTH);
62
63
64     float offset = 90.0 * SGD_DEGREES_TO_RADIANS;
65     float r1 = 10.0; //size of carrot
66     float theta = _input.getFloatValue();
67
68     float theta1 = -theta * SGD_DEGREES_TO_RADIANS + offset;
69     float x1 = x + _radius * cos(theta1);
70     float y1 = y + _radius * sin(theta1);
71     float x2 = x1 - r1 * cos(theta1 - 30.0 * SGD_DEGREES_TO_RADIANS);
72     float y2 = y1 - r1 * sin(theta1 - 30.0 * SGD_DEGREES_TO_RADIANS);
73     float x3 = x1 - r1 * cos(theta1 + 30.0 * SGD_DEGREES_TO_RADIANS);
74     float y3 = y1 - r1 * sin(theta1 + 30.0 * SGD_DEGREES_TO_RADIANS);
75
76     // draw carrot
77     draw_line(x1, y1, x2, y2);
78     draw_line(x1, y1, x3, y3);
79     snprintf(buf, BUFSIZE, "%3.1f\n", theta);
80
81     // draw value
82     int l = abs((int)theta);
83     if (l) {
84         if (l < 10)
85             draw_text(x, y, buf, 0);
86         else if (l < 100)
87             draw_text(x - 1.0, y, buf, 0);
88         else if (l < 360)
89             draw_text(x - 2.0, y, buf, 0);
90     }
91 }
92
93