1 // HUD_dial.cxx -- HUD Dial Instrument
3 // Written by Michele America, started September 1997.
5 // Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
6 // Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
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.
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.
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.
25 HUD::Dial::Dial(HUD *hud, const SGPropertyNode *n, float x, float y) :
27 _radius(n->getFloatValue("radius")),
28 _divisions(n->getIntValue("divisions"))
33 void HUD::Dial::draw(void)
35 if (!_input.isValid())
38 const int BUFSIZE = 80;
41 glEnable(GL_POINT_SMOOTH);
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);
55 glDisable(GL_POINT_SMOOTH);
58 float offset = 90.0 * SGD_DEGREES_TO_RADIANS;
59 const float R = 10.0; //size of carrot
60 float theta = _input.getFloatValue();
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);
71 draw_line(x1, y1, x2, y2);
72 draw_line(x1, y1, x3, y3);
73 snprintf(buf, BUFSIZE, "%3.1f\n", theta);
76 int l = abs((int)theta);
79 draw_text(_x, _y, buf, 0);
81 draw_text(_x - 1.0, _y, buf, 0);
83 draw_text(_x - 2.0, _y, buf, 0);