]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_tbi.cxx
Updates to vacuum system model from Alex Perry.
[flightgear.git] / src / 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
9 #include <stdlib.h>
10 #include <string.h>
11
12 #include <simgear/constants.h>
13 #include <simgear/math/fg_random.h>
14 #include <simgear/math/polar3d.hxx>
15
16 #include <Aircraft/aircraft.hxx>
17 #include <Scenery/scenery.hxx>
18 #include <Time/fg_timer.hxx>
19
20 #include "hud.hxx"
21
22
23 //============ Top of fgTBI_instr class member definitions ==============
24
25 fgTBI_instr ::
26 fgTBI_instr( int              x,
27              int              y,
28              UINT             width,
29              UINT             height,
30              FLTFNPTR  chn1_source,
31              FLTFNPTR  chn2_source,
32              float    maxBankAngle,
33              float    maxSlipAngle,
34              UINT      gap_width,
35              bool      working ) :
36                dual_instr_item( x, y, width, height,
37                                 chn1_source,
38                                 chn2_source,
39                                 working,
40                                 HUDS_TOP),
41                BankLimit      ((int)(maxBankAngle)),
42                SlewLimit      ((int)(maxSlipAngle)),
43                scr_hole       (gap_width   )
44 {
45 }
46
47 fgTBI_instr :: ~fgTBI_instr() {}
48
49 fgTBI_instr :: fgTBI_instr( const fgTBI_instr & image):
50                  dual_instr_item( (const dual_instr_item &) image),
51                  BankLimit( image.BankLimit),
52                  SlewLimit( image.SlewLimit),
53                  scr_hole ( image.scr_hole )
54 {
55 }
56
57 fgTBI_instr & fgTBI_instr ::
58 operator = (const fgTBI_instr & rhs )
59 {
60   if( !(this == &rhs)) {
61     dual_instr_item::operator = (rhs);
62     BankLimit = rhs.BankLimit;
63     SlewLimit = rhs.SlewLimit;
64     scr_hole  = rhs.scr_hole;
65     }
66    return *this;
67 }
68
69 //
70 //  Draws a Turn Bank Indicator on the screen
71 //
72
73  void fgTBI_instr :: draw( void )
74 {
75      float bank_angle, sideslip_angle;
76      float ss_const; // sideslip angle pixels per rad
77      float cen_x, cen_y, bank, fspan, tee, hole;
78
79      int span = get_span();
80      
81      float zero = 0.0;
82   
83      RECT My_box = get_location();
84      POINT centroid = get_centroid();
85      int tee_height = My_box.bottom;
86
87      bank_angle     = current_ch2();  // Roll limit +/- 30 degrees
88      
89      if( bank_angle < -FG_PI_2/3 ) {
90          bank_angle = -FG_PI_2/3;
91      } else if( bank_angle > FG_PI_2/3 ) {
92              bank_angle = FG_PI_2/3;
93      }
94      
95      sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
96      
97      if( sideslip_angle < -FG_PI/9 ) {
98          sideslip_angle = -FG_PI/9;
99      } else if( sideslip_angle > FG_PI/9 ) {
100              sideslip_angle = FG_PI/9;
101      }
102
103      cen_x = centroid.x;
104      cen_y = centroid.y;
105      bank  = bank_angle * RAD_TO_DEG;
106      tee   = -tee_height;
107      fspan = span;
108      hole  = scr_hole;
109      ss_const = 2 * sideslip_angle * fspan/(FG_2PI/9);  // width represents 40 degrees
110      
111 //   printf("side_slip: %f   fspan: %f\n", sideslip_angle, fspan);
112 //   printf("ss_const: %f   hole: %f\n", ss_const, hole);
113      
114      glPushMatrix();
115      glTranslatef(cen_x, cen_y, zero);
116      glRotatef(-bank, zero, zero, 1.0);
117     
118      glBegin(GL_LINES);
119      
120      if( !scr_hole )  
121      {
122          glVertex2f( -fspan, zero );
123          glVertex2f(  fspan, zero );
124      } else {
125          glVertex2f( -fspan, zero );
126          glVertex2f( -hole,  zero );
127          glVertex2f(  hole,  zero );
128          glVertex2f(  fspan, zero );
129      }
130      // draw teemarks
131      glVertex2f(  hole, zero );
132      glVertex2f(  hole, tee );
133      glVertex2f( -hole, zero );
134      glVertex2f( -hole, tee );
135      
136      glEnd();
137      
138      glBegin(GL_LINE_LOOP);
139          glVertex2f( ss_const,        -hole);
140          glVertex2f( ss_const + hole,  zero);
141          glVertex2f( ss_const,         hole);
142          glVertex2f( ss_const - hole,  zero);
143      glEnd();
144
145      glPopMatrix();
146 }