Debian Codegraph @

src/Instrumentation/HUD/HUD_tbi.cxx

raw symbols SCIP
1 // HUD_tbi.cxx -- HUD Turn-Bank-Indicator Instrument
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
6 // Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
7 //
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.
12 //
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.
17 //
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.
21
22 #include "HUD.hxx"
23 #include "HUD_private.hxx"
24
25 HUD::TurnBankIndicator::TurnBankIndicator(HUD *hud, const SGPropertyNode *n, float x, float y) :
26 Item(hud, n, x, 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 {
32 if (!_bank_scale) {
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);
37 }
38 }
39
40
41 void HUD::TurnBankIndicator::draw(void)
42 {
43 if (!_bank.isValid() || !_sideslip.isValid())
44 return;
45
46 if (_bank_scale)
47 draw_scale();
48 else
49 draw_tee();
50 }
51
52
53 void HUD::TurnBankIndicator::draw_tee()
54 {
55 // ___________ /\ ___________
56 // | \/ |
57
58 float bank = _bank.getFloatValue();
59 float sideslip = _sideslip.getFloatValue();
60
61 float span = get_span();
62 float tee = -_h;
63
64 // sideslip angle pixels per deg (width represents 40 deg)
65 float ss_const = 2 * sideslip * span / 40.0;
66
67 glPushMatrix();
68 glTranslatef(_center_x, _center_y, 0.0);
69 glRotatef(-bank, 0.0, 0.0, 1.0);
70
71 glBegin(GL_LINES);
72
73 if (!_gap_width) {
74 glVertex2f(-span, 0.0);
75 glVertex2f(span, 0.0);
76
77 } else {
78 glVertex2f(-span, 0.0);
79 glVertex2f(-_gap_width, 0.0);
80 glVertex2f(_gap_width, 0.0);
81 glVertex2f(span, 0.0);
82 }
83
84 // draw teemarks
85 glVertex2f(_gap_width, 0.0);
86 glVertex2f(_gap_width, tee);
87 glVertex2f(-_gap_width, 0.0);
88 glVertex2f(-_gap_width, tee);
89 glEnd();
90
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);
96 glEnd();
97
98 glPopMatrix();
99 }
100
101
102 void HUD::TurnBankIndicator::draw_scale()
103 {
104 // MIL-STD 1878B/4.2.2.4 bank scale
105 float bank = _bank.getFloatValue();
106 float sideslip = _sideslip.getFloatValue();
107
108 float cx = _center_x;
109 float cy = _center_y;
110
111 float r = _w / 2.0;
112 float minor = r - r * 3.0 / 70.0;
113 float major = r - r * 5.0 / 70.0;
114
115 // hollow 0 degree mark
116 float w = r / 70.0;
117 if (w < 1.0)
118 w = 1.0;
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);
124
125 // tick lines
126 draw_tick(10, r, minor, 0);
127 draw_tick(20, r, minor, 0);
128 draw_tick(30, r, major, 0);
129
130 int dir = bank > 0 ? 1 : -1;
131
132 if (fabs(bank) > 25) {
133 draw_tick(45, r, minor, dir);
134 draw_tick(60, r, major, dir);
135 }
136
137 if (fabs(bank) > 55) {
138 draw_tick(90, r, major, dir);
139 draw_tick(135, r, major, dir);
140 }
141
142 // bank marker
143 float a;
144 float rr = r + r * 0.5 / 70.0; // little gap for the arrow peak
145
146 a = (bank + 270.0) * SGD_DEGREES_TO_RADIANS;
147 float x1 = cx + rr * cos(a);
148 float y1 = cy + rr * sin(a);
149
150 rr = r * 3.0 / 70.0;
151 a = (bank + 240.0) * SGD_DEGREES_TO_RADIANS;
152 float x2 = x1 + rr * cos(a);
153 float y2 = y1 + rr * sin(a);
154
155 a = (bank + 300.0) * SGD_DEGREES_TO_RADIANS;
156 float x3 = x1 + rr * cos(a);
157 float y3 = y1 + rr * sin(a);
158
159 draw_line(x1, y1, x2, y2);
160 draw_line(x2, y2, x3, y3);
161 draw_line(x3, y3, x1, y1);
162
163
164 // sideslip marker
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);
169
170 rr = r * 3.0 / 70.0;
171 a = (bank + sideslip + 240.0) * SGD_DEGREES_TO_RADIANS;
172 x2 = x1 + rr * cos(a);
173 y2 = y1 + rr * sin(a);
174
175 a = (bank + sideslip + 300.0) * SGD_DEGREES_TO_RADIANS;
176 x3 = x1 + rr * cos(a);
177 y3 = y1 + rr * sin(a);
178
179 rr = r * 6.0 / 70.0;
180 a = (bank + sideslip + 240.0) * SGD_DEGREES_TO_RADIANS;
181 float x4 = x1 + rr * cos(a);
182 float y4 = y1 + rr * sin(a);
183
184 a = (bank + sideslip + 300.0) * SGD_DEGREES_TO_RADIANS;
185 float x5 = x1 + rr * cos(a);
186 float y5 = y1 + rr * sin(a);
187
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);
192 }
193
194
195 void HUD::TurnBankIndicator::draw_tick(float angle, float r1, float r2, int side)
196 {
197 float a = (270 - angle) * SGD_DEGREES_TO_RADIANS;
198 float c = cos(a);
199 float s = sin(a);
200 float x1 = r1 * c;
201 float x2 = r2 * c;
202 float y1 = _center_y + r1 * s;
203 float y2 = _center_y + r2 * s;
204 if (side >= 0)
205 draw_line(_center_x - x1, y1, _center_x - x2, y2);
206 if (side <= 0)
207 draw_line(_center_x + x1, y1, _center_x + x2, y2);
208 }
209
210
211 void HUD::TurnBankIndicator::draw_line(float x1, float y1, float x2, float y2)
212 {
213 if (option_top()) {
214 float y = 2.0 * _center_y; // mirror vertically
215 Item::draw_line(x1, y - y1, x2, y - y2);
216 } else
217 Item::draw_line(x1, y1, x2, y2);
218 }
219
220