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 (fabs(bank) > 25) {
133 draw_tick(45, r, minor, dir);
134 draw_tick(60, r, major, dir);
137 if (fabs(bank) > 55) {
138 draw_tick(90, r, major, dir);
139 draw_tick(135, r, major, dir);
144 float rr = r + r * 0.5 / 70.0; // little gap for the arrow peak
146 a = (bank + 270.0) * SGD_DEGREES_TO_RADIANS;
147 float x1 = cx + rr * cos(a);
148 float y1 = cy + rr * sin(a);
151 a = (bank + 240.0) * SGD_DEGREES_TO_RADIANS;
152 float x2 = x1 + rr * cos(a);
153 float y2 = y1 + rr * sin(a);
155 a = (bank + 300.0) * SGD_DEGREES_TO_RADIANS;
156 float x3 = x1 + rr * cos(a);
157 float y3 = y1 + rr * sin(a);
159 draw_line(x1, y1, x2, y2);
160 draw_line(x2, y2, x3, y3);
161 draw_line(x3, y3, x1, y1);
165 rr = r + r * 0.5 / 70.0;
166 a = (bank + sideslip + 270.0) * SGD_DEGREES_TO_RADIANS;
167 x1 = cx + rr * cos(a);
168 y1 = cy + rr * sin(a);
171 a = (bank + sideslip + 240.0) * SGD_DEGREES_TO_RADIANS;
172 x2 = x1 + rr * cos(a);
173 y2 = y1 + rr * sin(a);
175 a = (bank + sideslip + 300.0) * SGD_DEGREES_TO_RADIANS;
176 x3 = x1 + rr * cos(a);
177 y3 = y1 + rr * sin(a);
180 a = (bank + sideslip + 240.0) * SGD_DEGREES_TO_RADIANS;
181 float x4 = x1 + rr * cos(a);
182 float y4 = y1 + rr * sin(a);
184 a = (bank + sideslip + 300.0) * SGD_DEGREES_TO_RADIANS;
185 float x5 = x1 + rr * cos(a);
186 float y5 = y1 + rr * sin(a);
188 draw_line(x2, y2, x3, y3);
189 draw_line(x3, y3, x5, y5);
190 draw_line(x5, y5, x4, y4);
191 draw_line(x4, y4, x2, y2);
195 void HUD::TurnBankIndicator::draw_tick(float angle, float r1, float r2, int side)
197 float a = (270 - angle) * SGD_DEGREES_TO_RADIANS;
202 float y1 = _center_y + r1 * s;
203 float y2 = _center_y + r2 * s;
205 draw_line(_center_x - x1, y1, _center_x - x2, y2);
207 draw_line(_center_x + x1, y1, _center_x + x2, y2);
211 void HUD::TurnBankIndicator::draw_line(float x1, float y1, float x2, float y2)
214 float y = 2.0 * _center_y; // mirror vertically
215 Item::draw_line(x1, y - y1, x2, y - y2);
217 Item::draw_line(x1, y1, x2, y2);