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)),
31 _bank_scale_radius(n->getFloatValue("bank-scale-radius", 250.0))
34 _bank.set_max(30.0, false);
35 _bank.set_min(-30.0, false);
36 _sideslip.set_max(20.0, false);
37 _sideslip.set_min(-20.0, false);
42 void HUD::TurnBankIndicator::draw(void)
44 if (!_bank.isValid() || !_sideslip.isValid())
47 float bank = _bank.getFloatValue();
48 float sideslip = _sideslip.getFloatValue();
50 float span = get_span();
52 float tee_height = _h;
53 float tee = -tee_height;
54 float ss_const = 2 * sideslip * span / 40.0; // sideslip angle pixels per deg (width represents 40 deg)
57 glTranslatef(_center_x, _center_y, 0.0);
58 glRotatef(-bank, 0.0, 0.0, 1.0);
64 glVertex2f(-span, 0.0);
65 glVertex2f(span, 0.0);
68 glVertex2f(-span, 0.0);
69 glVertex2f(-_gap_width, 0.0);
70 glVertex2f(_gap_width, 0.0);
71 glVertex2f(span, 0.0);
75 glVertex2f(_gap_width, 0.0);
76 glVertex2f(_gap_width, tee);
77 glVertex2f(-_gap_width, 0.0);
78 glVertex2f(-_gap_width, tee);
81 glBegin(GL_LINE_LOOP);
82 glVertex2f(ss_const, -_gap_width);
83 glVertex2f(ss_const + _gap_width, 0.0);
84 glVertex2f(ss_const, _gap_width);
85 glVertex2f(ss_const - _gap_width, 0.0);
89 } else { // draw MIL-STD 1878B/4.2.2.4 bank scale
90 draw_line(_center_x - 1.0, _y, _center_x + 1.0, _y);
91 draw_line(_center_x - 1.0, _y, _center_x - 1.0, _y + 10.0);
92 draw_line(_center_x + 1.0, _y, _center_x + 1.0, _y + 10.0);
93 draw_line(_center_x - 1.0, _y + 10.0, _center_x + 1.0, _y + 10.0);
95 float x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
97 float r = _bank_scale_radius;
101 xc = _x + _w / 2.0; // FIXME redunant, no?
104 // first n last lines
105 x1 = xc + r * cos(255.0 * SGD_DEGREES_TO_RADIANS);
106 y1 = yc + r * sin(255.0 * SGD_DEGREES_TO_RADIANS);
108 x2 = xc + r1 * cos(255.0 * SGD_DEGREES_TO_RADIANS);
109 y2 = yc + r1 * sin(255.0 * SGD_DEGREES_TO_RADIANS);
110 draw_line(x1, y1, x2, y2);
112 x1 = xc + r * cos(285.0 * SGD_DEGREES_TO_RADIANS);
113 y1 = yc + r * sin(285.0 * SGD_DEGREES_TO_RADIANS);
115 x2 = xc + r1 * cos(285.0 * SGD_DEGREES_TO_RADIANS);
116 y2 = yc + r1 * sin(285.0 * SGD_DEGREES_TO_RADIANS);
117 draw_line(x1, y1, x2, y2);
119 // second n fifth lines
120 x1 = xc + r * cos(260.0 * SGD_DEGREES_TO_RADIANS);
121 y1 = yc + r * sin(260.0 * SGD_DEGREES_TO_RADIANS);
123 x2 = xc + r2 * cos(260.0 * SGD_DEGREES_TO_RADIANS);
124 y2 = yc + r2 * sin(260.0 * SGD_DEGREES_TO_RADIANS);
125 draw_line(x1, y1, x2, y2);
127 x1 = xc + r * cos(280.0 * SGD_DEGREES_TO_RADIANS);
128 y1 = yc + r * sin(280.0 * SGD_DEGREES_TO_RADIANS);
130 x2 = xc + r2 * cos(280.0 * SGD_DEGREES_TO_RADIANS);
131 y2 = yc + r2 * sin(280.0 * SGD_DEGREES_TO_RADIANS);
132 draw_line(x1, y1, x2, y2);
134 // third n fourth lines
135 x1 = xc + r * cos(265.0 * SGD_DEGREES_TO_RADIANS);
136 y1 = yc + r * sin(265.0 * SGD_DEGREES_TO_RADIANS);
139 x2 = xc + r2 * cos(265.0 * SGD_DEGREES_TO_RADIANS);
140 y2 = yc + r2 * sin(265.0 * SGD_DEGREES_TO_RADIANS);
141 draw_line(x1, y1, x2, y2);
143 x1 = xc + r * cos(275.0 * SGD_DEGREES_TO_RADIANS);
144 y1 = yc + r * sin(275.0 * SGD_DEGREES_TO_RADIANS);
146 x2 = xc + r2 * cos(275.0 * SGD_DEGREES_TO_RADIANS);
147 y2 = yc + r2 * sin(275.0 * SGD_DEGREES_TO_RADIANS);
148 draw_line(x1, y1, x2, y2);
151 r = _bank_scale_radius + 5.0; // add gap
154 float valbank = bank * 15.0 / _bank.max(); // total span of TSI is 30 degrees
155 float valsideslip = sideslip * 15.0 / _sideslip.max();
157 // values 270, 225 and 315 are angles in degrees...
158 x1 = xc + r * cos((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
159 y1 = yc + r * sin((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
161 x2 = x1 + 6.0 * cos(225 * SGD_DEGREES_TO_RADIANS);
162 y2 = y1 + 6.0 * sin(225 * SGD_DEGREES_TO_RADIANS);
164 x3 = x1 + 6.0 * cos(315 * SGD_DEGREES_TO_RADIANS);
165 y3 = y1 + 6.0 * sin(315 * SGD_DEGREES_TO_RADIANS);
167 draw_line(x1, y1, x2, y2);
168 draw_line(x2, y2, x3, y3);
169 draw_line(x3, y3, x1, y1);
171 // lower polygon // FIXME this is inefficient and wrong!
172 x1 = xc + r * cos((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
173 y1 = yc + r * sin((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
175 x2 = x1 + 6.0 * cos(225 * SGD_DEGREES_TO_RADIANS);
176 y2 = y1 + 6.0 * sin(225 * SGD_DEGREES_TO_RADIANS);
178 x3 = x1 + 6.0 * cos(315 * SGD_DEGREES_TO_RADIANS);
179 y3 = y1 + 6.0 * sin(315 * SGD_DEGREES_TO_RADIANS);
181 x4 = x1 + 10.0 * cos(225 * SGD_DEGREES_TO_RADIANS);
182 y4 = y1 + 10.0 * sin(225 * SGD_DEGREES_TO_RADIANS);
184 x5 = x1 + 10.0 * cos(315 * SGD_DEGREES_TO_RADIANS);
185 y5 = y1 + 10.0 * sin(315 * SGD_DEGREES_TO_RADIANS);
187 float cosss = cos(valsideslip * SGD_DEGREES_TO_RADIANS);
188 float sinss = sin(valsideslip * SGD_DEGREES_TO_RADIANS);
199 draw_line(x2, y2, x3, y3);
200 draw_line(x3, y3, x5, y5);
201 draw_line(x5, y5, x4, y4);
202 draw_line(x4, y4, x2, y2);