]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_tbi.cxx
new HUD (work in progress)
[flightgear.git] / src / Instrumentation / HUD / HUD_tbi.cxx
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
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     _bank_scale_radius(n->getFloatValue("bank-scale-radius", 250.0))
32 {
33     if (!_bank_scale) {
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);
38     }
39 }
40
41
42 void HUD::TurnBankIndicator::draw(void)
43 {
44     if (!_bank.isValid() || !_sideslip.isValid())
45         return;
46
47     float bank = _bank.getFloatValue();
48     float sideslip = _sideslip.getFloatValue();
49
50     float span = get_span();
51     Rect My_box = get_location();
52     Point centroid = get_centroid();
53
54     float cen_x = centroid.x;
55     float cen_y = centroid.y;
56
57     float tee_height = My_box.bottom;
58     float tee = -tee_height;
59     float ss_const = 2 * sideslip * span / 40.0;  // sideslip angle pixels per deg (width represents 40 deg)
60
61     glPushMatrix();
62     glTranslatef(cen_x, cen_y, 0.0);
63     glRotatef(-bank, 0.0, 0.0, 1.0);
64
65     if (!_bank_scale) {
66        glBegin(GL_LINES);
67
68        if (!_gap_width) {
69            glVertex2f(-span, 0.0);
70            glVertex2f(span, 0.0);
71
72        } else {
73            glVertex2f(-span, 0.0);
74            glVertex2f(-_gap_width, 0.0);
75            glVertex2f(_gap_width, 0.0);
76            glVertex2f(span, 0.0);
77        }
78
79        // draw teemarks
80        glVertex2f(_gap_width, 0.0);
81        glVertex2f(_gap_width, tee);
82        glVertex2f(-_gap_width, 0.0);
83        glVertex2f(-_gap_width, tee);
84        glEnd();
85
86        glBegin(GL_LINE_LOOP);
87        glVertex2f(ss_const, -_gap_width);
88        glVertex2f(ss_const + _gap_width, 0.0);
89        glVertex2f(ss_const, _gap_width);
90        glVertex2f(ss_const - _gap_width, 0.0);
91        glEnd();
92
93
94     } else { // draw MIL-STD 1878B/4.2.2.4 bank scale
95         draw_line(cen_x - 1.0, My_box.top, cen_x + 1.0, My_box.top);
96         draw_line(cen_x - 1.0, My_box.top, cen_x - 1.0, My_box.top + 10.0);
97         draw_line(cen_x + 1.0, My_box.top, cen_x + 1.0, My_box.top + 10.0);
98         draw_line(cen_x - 1.0, My_box.top + 10.0, cen_x + 1.0, My_box.top + 10.0);
99
100         float x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
101         float xc, yc;
102         float r = _bank_scale_radius;
103         float r1 = r - 10.0;
104         float r2 = r - 5.0;
105
106         xc = My_box.left + My_box.right / 2.0 ;
107         yc = My_box.top + r;
108
109         // first n last lines
110         x1 = xc + r * cos(255.0 * SGD_DEGREES_TO_RADIANS);
111         y1 = yc + r * sin(255.0 * SGD_DEGREES_TO_RADIANS);
112
113         x2 = xc + r1 * cos(255.0 * SGD_DEGREES_TO_RADIANS);
114         y2 = yc + r1 * sin(255.0 * SGD_DEGREES_TO_RADIANS);
115         draw_line(x1, y1, x2, y2);
116
117         x1 = xc + r * cos(285.0 * SGD_DEGREES_TO_RADIANS);
118         y1 = yc + r * sin(285.0 * SGD_DEGREES_TO_RADIANS);
119
120         x2 = xc + r1 * cos(285.0 * SGD_DEGREES_TO_RADIANS);
121         y2 = yc + r1 * sin(285.0 * SGD_DEGREES_TO_RADIANS);
122         draw_line(x1, y1, x2, y2);
123
124         // second n fifth  lines
125         x1 = xc + r * cos(260.0 * SGD_DEGREES_TO_RADIANS);
126         y1 = yc + r * sin(260.0 * SGD_DEGREES_TO_RADIANS);
127
128         x2 = xc + r2 * cos(260.0 * SGD_DEGREES_TO_RADIANS);
129         y2 = yc + r2 * sin(260.0 * SGD_DEGREES_TO_RADIANS);
130         draw_line(x1, y1, x2, y2);
131
132         x1 = xc + r * cos(280.0 * SGD_DEGREES_TO_RADIANS);
133         y1 = yc + r * sin(280.0 * SGD_DEGREES_TO_RADIANS);
134
135         x2 = xc + r2 * cos(280.0 * SGD_DEGREES_TO_RADIANS);
136         y2 = yc + r2 * sin(280.0 * SGD_DEGREES_TO_RADIANS);
137         draw_line(x1, y1, x2, y2);
138
139         // third n fourth lines
140         x1 = xc + r * cos(265.0 * SGD_DEGREES_TO_RADIANS);
141         y1 = yc + r * sin(265.0 * SGD_DEGREES_TO_RADIANS);
142
143
144         x2 = xc + r2 * cos(265.0 * SGD_DEGREES_TO_RADIANS);
145         y2 = yc + r2 * sin(265.0 * SGD_DEGREES_TO_RADIANS);
146         draw_line(x1, y1, x2, y2);
147
148         x1 = xc + r * cos(275.0 * SGD_DEGREES_TO_RADIANS);
149         y1 = yc + r * sin(275.0 * SGD_DEGREES_TO_RADIANS);
150
151         x2 = xc + r2 * cos(275.0 * SGD_DEGREES_TO_RADIANS);
152         y2 = yc + r2 * sin(275.0 * SGD_DEGREES_TO_RADIANS);
153         draw_line(x1, y1, x2, y2);
154
155         // draw marker
156         r = _bank_scale_radius + 5.0;  // add gap
157
158         // upper polygon
159         float valbank = bank * 15.0 / _bank.max(); // total span of TSI is 30 degrees
160         float valsideslip = sideslip * 15.0 / _sideslip.max();
161
162         // values 270, 225 and 315 are angles in degrees...
163         x1 = xc + r * cos((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
164         y1 = yc + r * sin((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
165
166         x2 = x1 + 6.0 * cos(225 * SGD_DEGREES_TO_RADIANS);
167         y2 = y1 + 6.0 * sin(225 * SGD_DEGREES_TO_RADIANS);
168
169         x3 = x1 + 6.0 * cos(315 * SGD_DEGREES_TO_RADIANS);
170         y3 = y1 + 6.0 * sin(315 * SGD_DEGREES_TO_RADIANS);
171
172         draw_line(x1, y1, x2, y2);
173         draw_line(x2, y2, x3, y3);
174         draw_line(x3, y3, x1, y1);
175
176         // lower polygon                                // FIXME this is inefficient and wrong!
177         x1 = xc + r * cos((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
178         y1 = yc + r * sin((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
179
180         x2 = x1 + 6.0 * cos(225 * SGD_DEGREES_TO_RADIANS);
181         y2 = y1 + 6.0 * sin(225 * SGD_DEGREES_TO_RADIANS);
182
183         x3 = x1 + 6.0 * cos(315 * SGD_DEGREES_TO_RADIANS);
184         y3 = y1 + 6.0 * sin(315 * SGD_DEGREES_TO_RADIANS);
185
186         x4 = x1 + 10.0 * cos(225 * SGD_DEGREES_TO_RADIANS);
187         y4 = y1 + 10.0 * sin(225 * SGD_DEGREES_TO_RADIANS);
188
189         x5 = x1 + 10.0 * cos(315 * SGD_DEGREES_TO_RADIANS);
190         y5 = y1 + 10.0 * sin(315 * SGD_DEGREES_TO_RADIANS);
191
192         float cosss = cos(valsideslip * SGD_DEGREES_TO_RADIANS);
193         float sinss = sin(valsideslip * SGD_DEGREES_TO_RADIANS);
194
195         x2 = x2 + cosss;
196         y2 = y2 + sinss;
197         x3 = x3 + cosss;
198         y3 = y3 + sinss;
199         x4 = x4 + cosss;
200         y4 = y4 + sinss;
201         x5 = x5 + cosss;
202         y5 = y5 + sinss;
203
204         draw_line(x2, y2, x3, y3);
205         draw_line(x3, y3, x5, y5);
206         draw_line(x5, y5, x4, y4);
207         draw_line(x4, y4, x2, y2);
208     }
209     glPopMatrix();
210 }
211
212