Debian Codegraph @

src/Instrumentation/HUD/HUD_dial.cxx

raw symbols SCIP
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 #include "HUD_private.hxx"
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 glEnable(GL_POINT_SMOOTH);
42 glPointSize(3.0);
43
44 float incr = 360.0 / _divisions;
45 for (float i = 0.0; i < 360.0; i += incr) {
46 float i1 = i * SGD_DEGREES_TO_RADIANS;
47 float x1 = _x + _radius * cos(i1);
48 float y1 = _y + _radius * sin(i1);
49
50 glBegin(GL_POINTS);
51 glVertex2f(x1, y1);
52 glEnd();
53 }
54 glPointSize(1.0);
55 glDisable(GL_POINT_SMOOTH);
56
57
58 float offset = 90.0 * SGD_DEGREES_TO_RADIANS;
59 const float R = 10.0; //size of carrot
60 float theta = _input.getFloatValue();
61
62 float theta1 = -theta * SGD_DEGREES_TO_RADIANS + offset;
63 float x1 = _x + _radius * cos(theta1);
64 float y1 = _y + _radius * sin(theta1);
65 float x2 = x1 - R * cos(theta1 - 30.0 * SGD_DEGREES_TO_RADIANS);
66 float y2 = y1 - R * sin(theta1 - 30.0 * SGD_DEGREES_TO_RADIANS);
67 float x3 = x1 - R * cos(theta1 + 30.0 * SGD_DEGREES_TO_RADIANS);
68 float y3 = y1 - R * sin(theta1 + 30.0 * SGD_DEGREES_TO_RADIANS);
69
70 // draw carrot
71 draw_line(x1, y1, x2, y2);
72 draw_line(x1, y1, x3, y3);
73 snprintf(buf, BUFSIZE, "%3.1f\n", theta);
74
75 // draw value
76 int l = abs((int)theta);
77 if (l) {
78 if (l < 10)
79 draw_text(_x, _y, buf, 0);
80 else if (l < 100)
81 draw_text(_x - 1.0, _y, buf, 0);
82 else if (l < 360)
83 draw_text(_x - 2.0, _y, buf, 0);
84 }
85 }
86
87