]> git.mxchange.org Git - flightgear.git/blob - Cockpit/hud_tbi.cxx
c38c26b2779c5f8258f2d814bddd7fdca1c65025
[flightgear.git] / Cockpit / hud_tbi.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include <config.h>
3 #endif
4
5 #ifdef HAVE_WINDOWS_H
6 #  include <windows.h>
7 #endif
8 #include <stdlib.h>
9 #include <string.h>
10 #include <Aircraft/aircraft.h>
11 #include <Debug/fg_debug.h>
12 #include <Include/fg_constants.h>
13 #include <Math/fg_random.h>
14 #include <Math/mat3.h>
15 #include <Math/polar3d.hxx>
16 #include <Scenery/scenery.hxx>
17 #include <Time/fg_timer.hxx>
18 #include <Weather/weather.h>
19
20
21 #include "hud.hxx"
22 //============ Top of fgTBI_instr class member definitions ==============
23
24 fgTBI_instr ::
25 fgTBI_instr( int              x,
26              int              y,
27              UINT             width,
28              UINT             height,
29              DBLFNPTR  chn1_source,
30              DBLFNPTR  chn2_source,
31              double    maxBankAngle,
32              double    maxSlipAngle,
33              UINT      gap_width,
34              bool      working ) :
35                dual_instr_item( x, y, width, height,
36                                 chn1_source,
37                                 chn2_source,
38                                 working,
39                                 HUDS_TOP),
40                BankLimit      (maxBankAngle),
41                SlewLimit      (maxSlipAngle),
42                scr_hole       (gap_width   )
43 {
44 }
45
46 fgTBI_instr :: ~fgTBI_instr() {}
47
48 fgTBI_instr :: fgTBI_instr( const fgTBI_instr & image):
49                  dual_instr_item( (const dual_instr_item &) image),
50                  BankLimit( image.BankLimit),
51                  SlewLimit( image.SlewLimit),
52                  scr_hole ( image.scr_hole )
53 {
54 }
55
56 fgTBI_instr & fgTBI_instr ::
57 operator = (const fgTBI_instr & rhs )
58 {
59   if( !(this == &rhs)) {
60     dual_instr_item::operator = (rhs);
61     BankLimit = rhs.BankLimit;
62     SlewLimit = rhs.SlewLimit;
63     scr_hole  = rhs.scr_hole;
64     }
65    return *this;
66 }
67
68 //
69 //      Draws a Turn Bank Indicator on the screen
70 //
71
72  void fgTBI_instr :: draw( void )
73 {
74   int x_inc1, y_inc1;
75   int x_inc2, y_inc2;
76   int x_t_inc1, y_t_inc1;
77
78   int d_bottom_x, d_bottom_y;
79   int d_right_x, d_right_y;
80   int d_top_x, d_top_y;
81   int d_left_x, d_left_y;
82
83   int inc_b_x, inc_b_y;
84   int inc_r_x, inc_r_y;
85   int inc_t_x, inc_t_y;
86   int inc_l_x, inc_l_y;
87   RECT My_box = get_location();
88   POINT centroid = get_centroid();
89   int tee_height = My_box.bottom;
90
91 //      struct fgFLIGHT *f = &current_aircraft.flight;
92   double sin_bank, cos_bank;
93   double bank_angle, sideslip_angle;
94   double ss_const; // sideslip angle pixels per rad
95
96   bank_angle     = current_ch2();  // Roll limit +/- 30 degrees
97   if( bank_angle < -FG_PI_2/3 ) {
98     bank_angle = -FG_PI_2/3;
99     }
100   else
101     if( bank_angle > FG_PI_2/3 ) {
102       bank_angle = FG_PI_2/3;
103       }
104   sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
105   if( sideslip_angle < -FG_PI/9 ) {
106     sideslip_angle = -FG_PI/9;
107     }
108   else
109     if( sideslip_angle > FG_PI/9 ) {
110       sideslip_angle = FG_PI/9;
111       }
112
113         // sin_bank = sin( FG_2PI-FG_Phi );
114         // cos_bank = cos( FG_2PI-FG_Phi );
115   sin_bank = sin(FG_2PI-bank_angle);
116   cos_bank = cos(FG_2PI-bank_angle);
117
118   x_inc1 = (int)(get_span() * cos_bank);
119   y_inc1 = (int)(get_span() * sin_bank);
120   x_inc2 = (int)(scr_hole  * cos_bank);
121   y_inc2 = (int)(scr_hole  * sin_bank);
122
123   x_t_inc1 = (int)(tee_height * sin_bank);
124   y_t_inc1 = (int)(tee_height * cos_bank);
125
126   d_bottom_x = 0;
127   d_bottom_y = (int)(-scr_hole);
128   d_right_x  = (int)(scr_hole);
129   d_right_y  = 0;
130   d_top_x    = 0;
131   d_top_y    = (int)(scr_hole);
132   d_left_x   = (int)(-scr_hole);
133   d_left_y   = 0;
134
135   ss_const = (get_span()*2)/(FG_2PI/9);  // width represents 40 degrees
136
137   d_bottom_x += (int)(sideslip_angle*ss_const);
138   d_right_x  += (int)(sideslip_angle*ss_const);
139   d_left_x   += (int)(sideslip_angle*ss_const);
140   d_top_x    += (int)(sideslip_angle*ss_const);
141
142   inc_b_x = (int)(d_bottom_x*cos_bank-d_bottom_y*sin_bank);
143   inc_b_y = (int)(d_bottom_x*sin_bank+d_bottom_y*cos_bank);
144   inc_r_x = (int)(d_right_x*cos_bank-d_right_y*sin_bank);
145   inc_r_y = (int)(d_right_x*sin_bank+d_right_y*cos_bank);
146   inc_t_x = (int)(d_top_x*cos_bank-d_top_y*sin_bank);
147   inc_t_y = (int)(d_top_x*sin_bank+d_top_y*cos_bank);
148   inc_l_x = (int)(d_left_x*cos_bank-d_left_y*sin_bank);
149   inc_l_y = (int)(d_left_x*sin_bank+d_left_y*cos_bank);
150
151   if( scr_hole == 0 )
152     {
153     drawOneLine( centroid.x - x_inc1, centroid.y - y_inc1, \
154                  centroid.x + x_inc1, centroid.y + y_inc1 );
155     }
156   else
157     {
158     drawOneLine( centroid.x - x_inc1, centroid.y - y_inc1, \
159                  centroid.x - x_inc2, centroid.y - y_inc2 );
160     drawOneLine( centroid.x + x_inc2, centroid.y + y_inc2, \
161                  centroid.x + x_inc1, centroid.y + y_inc1 );
162     }
163
164   // draw teemarks
165   drawOneLine( centroid.x + x_inc2,            \
166                  centroid.y + y_inc2,          \
167                centroid.x + x_inc2 + x_t_inc1, \
168                  centroid.y + y_inc2 - y_t_inc1 );
169   drawOneLine( centroid.x - x_inc2,            \
170                  centroid.y - y_inc2,          \
171                centroid.x - x_inc2 + x_t_inc1, \
172                  centroid.y - y_inc2 - y_t_inc1 );
173
174   // draw sideslip diamond (it is not yet positioned correctly )
175   drawOneLine( centroid.x + inc_b_x, \
176                centroid.y + inc_b_y, \
177                centroid.x + inc_r_x, \
178                centroid.y + inc_r_y );
179   drawOneLine( centroid.x + inc_r_x, \
180                centroid.y + inc_r_y, \
181                centroid.x + inc_t_x, \
182                centroid.y + inc_t_y );
183   drawOneLine( centroid.x + inc_t_x, \
184                centroid.y + inc_t_y, \
185                centroid.x + inc_l_x, \
186                centroid.y + inc_l_y );
187   drawOneLine( centroid.x + inc_l_x, \
188                centroid.y + inc_l_y, \
189                centroid.x + inc_b_x, \
190                centroid.y + inc_b_y );
191
192 }