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 Rect scrn_rect = get_location();
45 y = (float)(scrn_rect.top);
46 x = (float)(scrn_rect.left);
47 glEnable(GL_POINT_SMOOTH);
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);
61 glDisable(GL_POINT_SMOOTH);
64 float offset = 90.0 * SGD_DEGREES_TO_RADIANS;
65 float r1 = 10.0; //size of carrot
66 float theta = _input.getFloatValue();
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);
77 draw_line(x1, y1, x2, y2);
78 draw_line(x1, y1, x3, y3);
79 snprintf(buf, BUFSIZE, "%3.1f\n", theta);
82 int l = abs((int)theta);
85 draw_text(x, y, buf, 0);
87 draw_text(x - 1.0, y, buf, 0);
89 draw_text(x - 2.0, y, buf, 0);