]> git.mxchange.org Git - flightgear.git/blob - Cockpit/hud_ladr.cxx
C++ ifying ...
[flightgear.git] / Cockpit / hud_ladr.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.hxx>
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
19
20 #include "hud.hxx"
21 //====================== Top of HudLadder Class =======================
22 HudLadder ::
23   HudLadder(  int       x,
24               int       y,
25               UINT      width,
26               UINT      height,
27               DBLFNPTR  ptch_source,
28               DBLFNPTR  roll_source,
29               double    span_units,
30               double    major_div,
31               double    minor_div,
32               UINT      screen_hole,
33               UINT      lbl_pos,
34               bool      working) :
35                dual_instr_item( x, y, width, height,
36                                 ptch_source,
37                                 roll_source,
38                                 working,
39                                 HUDS_RIGHT),
40                width_units    ( span_units   ),
41                div_units      ( major_div < 0? -major_div: major_div ),
42                minor_div      ( minor_div    ),
43                label_pos      ( lbl_pos      ),
44                scr_hole       ( screen_hole  ),
45                vmax           ( span_units/2 ),
46                vmin           ( -vmax        )
47 {
48   if( !width_units ) {
49     width_units = 45;
50     }
51   factor = (double)get_span() / (double) width_units;
52 }
53
54 HudLadder ::
55   ~HudLadder()
56 {
57 }
58
59 HudLadder ::
60   HudLadder( const HudLadder & image ) :
61         dual_instr_item( (dual_instr_item &) image),
62         width_units    ( image.width_units   ),
63         div_units      ( image.div_units     ),
64         label_pos      ( image.label_pos     ),
65         scr_hole       ( image.scr_hole      ),
66         vmax           ( image.vmax ),
67         vmin           ( image.vmin ),
68         factor         ( image.factor        )
69 {
70 }
71 HudLadder & HudLadder ::
72   operator = ( const HudLadder & rhs )
73 {
74   if( !(this == &rhs)) {
75     (dual_instr_item &)(*this) = (dual_instr_item &)rhs;
76     width_units  = rhs.width_units;
77     div_units    = rhs.div_units;
78     label_pos    = rhs.label_pos;
79     scr_hole     = rhs.scr_hole;
80     vmax         = rhs.vmax;
81     vmin         = rhs.vmin;
82     factor       = rhs.factor;
83     }
84   return *this;
85 }
86
87 //
88 //      Draws a climb ladder in the center of the HUD
89 //
90
91 void HudLadder :: draw( void )
92 {
93   double roll_value;
94   double pitch_value;
95   int    marker_y;
96   int    x_ini;
97   int    x_end;
98   int    y_ini;
99   int    y_end;
100   int    new_x_ini;
101   int    new_x_end;
102   int    new_y_ini;
103   int    new_y_end;
104   int    i;
105   POINT  centroid   = get_centroid();
106   RECT   box        = get_location();
107   int    scr_min    = box.top;
108   int    half_span  = box.right >> 1;
109   char   TextLadder[80];
110   int    condition;
111   int    label_length;
112   roll_value        = current_ch2();
113   GLfloat sinRoll   = sin( roll_value );
114   GLfloat cosRoll   = cos( roll_value );
115
116   pitch_value       = current_ch1() * RAD_TO_DEG;
117   vmin              = pitch_value - (double)width_units/2.0;
118   vmax              = pitch_value + (double)width_units/2.0;
119
120 // Box the target.
121   drawOneLine( centroid.x - 5, centroid.y,     centroid.x,     centroid.y + 5);
122   drawOneLine( centroid.x,     centroid.y + 5, centroid.x + 5, centroid.y);
123   drawOneLine( centroid.x + 5, centroid.y,     centroid.x,     centroid.y - 5);
124   drawOneLine( centroid.x,     centroid.y - 5, centroid.x - 5, centroid.y);
125
126   for( i=(int)vmin; i<=(int)vmax; i++ )  {  // Through integer pitch values...
127     condition = 1;
128     if( condition )      {
129       marker_y = centroid.y + (int)(((double)(i - pitch_value) * factor) + .5);
130       if( div_units ) {
131         if( !(i % div_units ))    {        //  At integral multiple of div
132           sprintf( TextLadder, "%d", i );
133           label_length = strlen( TextLadder );
134           if( scr_hole == 0 )           {
135             if( i ) {
136               x_ini = centroid.x - half_span;
137               }
138             else {                         // Make zero point wider on left
139               x_ini = centroid.x - half_span - 10;
140               }
141             y_ini = marker_y;
142             x_end = centroid.x + half_span;
143             y_end = marker_y;
144             new_x_ini = centroid.x + (int)(
145                        (x_ini - centroid.x) * cosRoll -
146                        (y_ini - centroid.y) * sinRoll);
147             new_y_ini = centroid.y + (int)(             \
148                        (x_ini - centroid.x) * sinRoll + \
149                        (y_ini - centroid.y) * cosRoll);
150             new_x_end = centroid.x + (int)(             \
151                        (x_end - centroid.x) * cosRoll - \
152                        (y_end - centroid.y) * sinRoll);
153             new_y_end = centroid.y + (int)(             \
154                        (x_end - centroid.x) * sinRoll + \
155                        (y_end - centroid.y) * cosRoll);
156
157             if( i >= 0 ) { // Above zero draw solid lines
158               drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
159               }
160             else         { // Below zero draw dashed lines.
161               glEnable(GL_LINE_STIPPLE);
162               glLineStipple( 1, 0x00FF );
163               drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
164               glDisable(GL_LINE_STIPPLE);
165               }
166             // Calculate the position of the left text and write it.
167             new_x_ini = centroid.x + (int)(
168                         (x_ini - 8 * label_length- 4 - centroid.x) * cosRoll -
169                         (y_ini - 4 ) * sinRoll);
170             new_y_ini = centroid.y + (int)(
171                         (x_ini - 8 * label_length- 4 - centroid.x) * sinRoll +
172                         (y_ini - 4 - centroid.y) * cosRoll);
173             strokeString( new_x_ini , new_y_ini ,
174                         TextLadder, GLUT_STROKE_ROMAN,
175                         roll_value );
176
177             // Calculate the position of the right text and write it.
178             new_x_end = centroid.x + (int)(                  \
179                        (x_end + 24 - 8 * label_length - centroid.x) * cosRoll - \
180                        (y_end -  4 - centroid.y) * sinRoll);
181             new_y_end = centroid.y + (int)(                  \
182                        (x_end + 24 - 8 * label_length - centroid.x) * sinRoll + \
183                        (y_end -  4 - centroid.y) * cosRoll);
184             strokeString( new_x_end,  new_y_end,
185                           TextLadder, GLUT_STROKE_ROMAN,
186                           roll_value );
187             }
188           else   {  // Draw ladder with space in the middle of the lines
189                     // Start by calculating the points and drawing the
190                     // left side lines.
191             if( i != 0 )  {
192               x_ini = centroid.x - half_span;
193               }
194             else          {
195               x_ini = centroid.x - half_span - 10;
196               }
197             y_ini = marker_y;
198             x_end = centroid.x - half_span + scr_hole/2;
199             y_end = marker_y;
200
201             new_x_end = centroid.x+  (int)(             \
202                         (x_end - centroid.x) * cosRoll -\
203                         (y_end - centroid.y) * sinRoll);
204             new_y_end = centroid.y+ (int)(              \
205                         (x_end - centroid.x) * sinRoll +\
206                         (y_end - centroid.y) * cosRoll);
207             new_x_ini = centroid.x + (int)(              \
208                         (x_ini - centroid.x) * cosRoll -\
209                         (y_ini - centroid.y) * sinRoll);
210             new_y_ini = centroid.y + (int)(             \
211                         (x_ini - centroid.x) * sinRoll +\
212                         (y_ini - centroid.y) * cosRoll);
213
214             if( i >= 0 )
215               {
216               drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
217               }
218             else  {
219               glEnable(GL_LINE_STIPPLE);
220               glLineStipple( 1, 0x00FF );
221               drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
222               glDisable(GL_LINE_STIPPLE);
223               }
224             // Now calculate the location of the left side label using
225             // the previously calculated start of the left side line.
226
227             x_ini = x_ini - (label_length + 32 + centroid.x);
228             if( i < 0) {
229               x_ini -= 8;
230               }
231             else {
232               if( i == 0 ) {
233                 x_ini += 20;
234                 }
235               }
236             y_ini = y_ini - ( 4 + centroid.y);
237
238             new_x_ini = centroid.x + (int)(x_ini * cosRoll - y_ini * sinRoll);
239             new_y_ini = centroid.y + (int)(x_ini * sinRoll + y_ini * cosRoll);
240             strokeString( new_x_ini , new_y_ini ,
241                           TextLadder, GLUT_STROKE_MONO_ROMAN,
242                           roll_value );
243
244             // Now calculate and draw the right side line location
245             x_ini = centroid.x + half_span - scr_hole/2;
246             y_ini = marker_y;
247             if( i != 0 )  {
248               x_end = centroid.x + half_span;
249               }
250             else          {
251               x_end = centroid.x + half_span + 10;
252               }
253             y_end = marker_y;
254
255             new_x_ini = centroid.x + (int)(         \
256                         (x_ini-centroid.x)*cosRoll -\
257                         (y_ini-centroid.y)*sinRoll);
258             new_y_ini = centroid.y + (int)(         \
259                         (x_ini-centroid.x)*sinRoll +\
260                         (y_ini-centroid.y)*cosRoll);
261             new_x_end = centroid.x + (int)(         \
262                         (x_end-centroid.x)*cosRoll -\
263                         (y_end-centroid.y)*sinRoll);
264             new_y_end = centroid.y +  (int)(        \
265                         (x_end-centroid.x)*sinRoll +\
266                         (y_end-centroid.y)*cosRoll);
267
268             if( i >= 0 )
269               {
270               drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
271               }
272             else
273               {
274               glEnable(GL_LINE_STIPPLE);
275               glLineStipple( 1, 0x00FF );
276               drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
277               glDisable(GL_LINE_STIPPLE);
278               }
279
280             // Calculate the location and draw the right side label
281             // using the end of the line as previously calculated.
282             x_end -= centroid.x + label_length - 24;
283             if( i < 0 ) {
284               x_end -= 8;
285               }
286             y_end  = marker_y - ( 4 + centroid.y);
287             new_x_end = centroid.x + (int)( (GLfloat)x_end * cosRoll -
288                                             (GLfloat)y_end * sinRoll);
289             new_y_end = centroid.y + (int)( (GLfloat)x_end * sinRoll +
290                                             (GLfloat)y_end * cosRoll);
291             strokeString( new_x_end,  new_y_end,
292                           TextLadder, GLUT_STROKE_MONO_ROMAN,
293                           roll_value );
294             }
295           }
296         }
297       }
298     }
299 }
300