1 // HUD_tbi.cxx -- HUD Turn-Bank-Indicator 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::TurnBankIndicator::TurnBankIndicator(HUD *hud, const SGPropertyNode *n, float x, float y) :
27 _bank(n->getNode("bank-input", false)),
28 _sideslip(n->getNode("sideslip-input", false)),
29 _gap_width(n->getFloatValue("gap-width", 5)),
30 _bank_scale(n->getBoolValue("bank-scale", false))
33 _bank.set_max(30.0, false);
34 _bank.set_min(-30.0, false);
35 _sideslip.set_max(20.0, false);
36 _sideslip.set_min(-20.0, false);
41 void HUD::TurnBankIndicator::draw(void)
43 if (!_bank.isValid() || !_sideslip.isValid())
53 void HUD::TurnBankIndicator::draw_tee()
55 // ___________ /\ ___________
58 float bank = _bank.getFloatValue();
59 float sideslip = _sideslip.getFloatValue();
61 float span = get_span();
64 // sideslip angle pixels per deg (width represents 40 deg)
65 float ss_const = 2 * sideslip * span / 40.0;
68 glTranslatef(_center_x, _center_y, 0.0);
69 glRotatef(-bank, 0.0, 0.0, 1.0);
74 glVertex2f(-span, 0.0);
75 glVertex2f(span, 0.0);
78 glVertex2f(-span, 0.0);
79 glVertex2f(-_gap_width, 0.0);
80 glVertex2f(_gap_width, 0.0);
81 glVertex2f(span, 0.0);
85 glVertex2f(_gap_width, 0.0);
86 glVertex2f(_gap_width, tee);
87 glVertex2f(-_gap_width, 0.0);
88 glVertex2f(-_gap_width, tee);
91 glBegin(GL_LINE_LOOP);
92 glVertex2f(ss_const, -_gap_width);
93 glVertex2f(ss_const + _gap_width, 0.0);
94 glVertex2f(ss_const, _gap_width);
95 glVertex2f(ss_const - _gap_width, 0.0);
102 void HUD::TurnBankIndicator::draw_scale()
104 // MIL-STD 1878B/4.2.2.4 bank scale
105 float bank = _bank.getFloatValue();
106 float sideslip = _sideslip.getFloatValue();
108 float cx = _center_x;
109 float cy = _center_y;
112 float minor = r - r * 3.0 / 70.0;
113 float major = r - r * 5.0 / 70.0;
115 // hollow 0 degree mark
119 float h = r * 6.0 / 70.0;
120 draw_line(cx - w, _y, cx + w, _y);
121 draw_line(cx - w, _y, cx - w, _y + h);
122 draw_line(cx + w, _y, cx + w, _y + h);
123 draw_line(cx - w, _y + h, cx + w, _y + h);
126 draw_tick(10, r, minor, 0);
127 draw_tick(20, r, minor, 0);
128 draw_tick(30, r, major, 0);
130 int dir = bank > 0 ? 1 : -1;
132 if (fabsf(bank) > 25) {
133 draw_tick(45, r, minor, dir);
134 draw_tick(60, r, major, dir);
137 if (fabsf(bank) > 55) {
138 draw_tick(90, r, major, dir);
139 draw_tick(135, r, major, dir);
143 float a, rr = r + r * 2.0 / 70.0;
145 a = (bank + 270.0) * SGD_DEGREES_TO_RADIANS;
146 float x1 = cx + rr * cos(a);
147 float y1 = cy + rr * sin(a);
150 a = (bank + 240.0) * SGD_DEGREES_TO_RADIANS;
151 float x2 = x1 + rr * cos(a);
152 float y2 = y1 + rr * sin(a);
154 a = (bank + 300.0) * SGD_DEGREES_TO_RADIANS;
155 float x3 = x1 + rr * cos(a);
156 float y3 = y1 + rr * sin(a);
158 draw_line(x1, y1, x2, y2);
159 draw_line(x2, y2, x3, y3);
160 draw_line(x3, y3, x1, y1);
164 rr = r + r * 2.0 / 70.0;
165 a = (bank + sideslip + 270.0) * SGD_DEGREES_TO_RADIANS;
166 x1 = cx + rr * cos(a);
167 y1 = cy + rr * sin(a);
170 a = (bank + sideslip + 240.0) * SGD_DEGREES_TO_RADIANS;
171 x2 = x1 + rr * cos(a);
172 y2 = y1 + rr * sin(a);
174 a = (bank + sideslip + 300.0) * SGD_DEGREES_TO_RADIANS;
175 x3 = x1 + rr * cos(a);
176 y3 = y1 + rr * sin(a);
179 a = (bank + sideslip + 240.0) * SGD_DEGREES_TO_RADIANS;
180 float x4 = x1 + rr * cos(a);
181 float y4 = y1 + rr * sin(a);
183 a = (bank + sideslip + 300.0) * SGD_DEGREES_TO_RADIANS;
184 float x5 = x1 + rr * cos(a);
185 float y5 = y1 + rr * sin(a);
187 draw_line(x2, y2, x3, y3);
188 draw_line(x3, y3, x5, y5);
189 draw_line(x5, y5, x4, y4);
190 draw_line(x4, y4, x2, y2);
194 void HUD::TurnBankIndicator::draw_tick(float angle, float r1, float r2, int side)
196 float a = (270 - angle) * SGD_DEGREES_TO_RADIANS;
201 float y1 = _center_y + r1 * s;
202 float y2 = _center_y + r2 * s;
204 draw_line(_center_x - x1, y1, _center_x - x2, y2);
206 draw_line(_center_x + x1, y1, _center_x + x2, y2);