]> git.mxchange.org Git - flightgear.git/blob - Cockpit/cockpit.cxx
Converted to new logstream debugging facility. This allows release
[flightgear.git] / Cockpit / cockpit.cxx
1 //*************************************************************************
2 // cockpit.cxx -- routines to draw a cockpit (initial draft)
3 //
4 // Written by Michele America, started September 1997.
5 //
6 // Copyright (C) 1997  Michele F. America  - nomimarketing@mail.telepac.pt
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., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23 // (Log is kept at end of this file)
24 //*************************************************************************/
25
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #ifdef HAVE_WINDOWS_H          
32 #  include <windows.h>
33 #endif
34
35 #include <GL/glut.h>
36 #include <XGL/xgl.h>
37
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <string.h>
41
42 #include <Aircraft/aircraft.hxx>
43 #include <Debug/logstream.hxx>
44 #include <Include/fg_constants.h>
45 #include <Include/general.h>
46 #include <Main/options.hxx>
47 #include <Main/views.hxx>
48 #include <Math/fg_random.h>
49 #include <Math/mat3.h>
50 #include <Math/polar3d.hxx>
51 #include <Scenery/scenery.hxx>
52 #include <Time/fg_timer.hxx>
53
54 #include "cockpit.hxx"
55
56
57 // This is a structure that contains all data related to
58 // cockpit/panel/hud system
59
60 static pCockpit ac_cockpit;
61
62 // The following routines obtain information concerntin the aircraft's
63 // current state and return it to calling instrument display routines.
64 // They should eventually be member functions of the aircraft.
65 //
66
67 double get_latitude( void )
68 {
69         fgFLIGHT *f;
70         f = current_aircraft.flight;
71
72 //      return( toDM(FG_Latitude * RAD_TO_DEG) );
73         return((double)((int)( FG_Latitude * RAD_TO_DEG)) );
74 }
75 double get_lat_min( void )
76 {
77         fgFLIGHT *f;
78         double      a, d;
79
80         f = current_aircraft.flight;
81         
82         a = FG_Latitude * RAD_TO_DEG;   
83         if (a < 0.0) {
84                 a = -a;
85         }
86         d = (double) ( (int) a);
87         return( (a - d) * 60.0);
88 }
89
90
91 double get_longitude( void )
92 {
93         fgFLIGHT *f;
94         f = current_aircraft.flight;
95
96 //      return( toDM(FG_Longitude * RAD_TO_DEG) );
97         return((double)((int) (FG_Longitude * RAD_TO_DEG)) );
98 }
99 double get_long_min( void )
100 {
101         fgFLIGHT *f;
102         double  a, d;
103
104         f = current_aircraft.flight;
105         
106         a = FG_Longitude * RAD_TO_DEG;  
107         if (a < 0.0) {
108                 a = -a;
109         }
110         d = (double) ( (int) a);
111         return( (a - d) * 60.0);
112 }
113
114 double get_throttleval( void )
115 {
116     return controls.get_throttle( 0 );     // Hack limiting to one engine
117 }
118
119 double get_aileronval( void )
120 {
121     return controls.get_aileron();
122 }
123
124 double get_elevatorval( void )
125 {
126     return controls.get_elevator();
127 }
128
129 double get_elev_trimval( void )
130 {
131     return controls.get_elevator_trim();
132 }
133
134 double get_rudderval( void )
135 {
136     return controls.get_rudder();
137 }
138
139 double get_speed( void )
140 {
141         fgFLIGHT *f;
142
143         f = current_aircraft.flight;
144         return( FG_V_equiv_kts );    // Make an explicit function call.
145 }
146
147 double get_aoa( void )
148 {
149         fgFLIGHT *f;
150               
151         f = current_aircraft.flight;
152         return( FG_Gamma_vert_rad * RAD_TO_DEG );
153 }
154
155 double get_roll( void )
156 {
157         fgFLIGHT *f;
158
159         f = current_aircraft.flight;
160         return( FG_Phi );
161 }
162
163 double get_pitch( void )
164 {
165         fgFLIGHT *f;
166               
167         f = current_aircraft.flight;
168         return( FG_Theta );
169 }
170
171 double get_heading( void )
172 {
173         fgFLIGHT *f;
174
175         f = current_aircraft.flight;
176         return( FG_Psi * RAD_TO_DEG );
177 }
178
179 double get_altitude( void )
180 {
181         fgFLIGHT *f;
182         // double rough_elev;
183
184         f = current_aircraft.flight;
185         // rough_elev = mesh_altitude(FG_Longitude * RAD_TO_ARCSEC,
186         //                                 FG_Latitude  * RAD_TO_ARCSEC);
187
188         if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
189             return FG_Altitude;
190         } else {
191             return FG_Altitude * FEET_TO_METER;
192         }
193 }
194
195 double get_agl( void )
196 {
197         fgFLIGHT *f;
198
199         f = current_aircraft.flight;
200
201         if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
202             return FG_Altitude - scenery.cur_elev * METER_TO_FEET;
203         } else {
204             return FG_Altitude * FEET_TO_METER - scenery.cur_elev;
205         }
206 }
207
208 double get_sideslip( void )
209 {
210         fgFLIGHT *f;
211         
212         f = current_aircraft.flight;
213         
214         return( FG_Beta );
215 }
216
217 double get_frame_rate( void )
218 {
219     fgGENERAL *pgeneral;
220  
221     pgeneral = &general;                     
222  
223     return pgeneral->frame_rate;
224 }
225
226 double get_fov( void )
227 {
228     return (current_options.get_fov()); 
229 }
230
231 double get_vfc_ratio( void )
232 {
233     fgVIEW *pview;
234  
235     pview = &current_view;
236  
237     return pview->vfc_ratio;
238 }
239
240 double get_vfc_tris_drawn   ( void )
241 {
242     return current_view.tris_rendered;
243 }
244
245 double get_climb_rate( void )
246 {
247         fgFLIGHT *f;
248
249         f = current_aircraft.flight;
250
251         if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
252             return FG_Climb_Rate * 60.0;
253         } else {
254             return FG_Climb_Rate * FEET_TO_METER * 60.0;
255         }
256 }
257
258
259 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
260 {
261     FG_LOG( FG_COCKPIT, FG_INFO, "Initializing cockpit subsystem" );
262
263     //  cockpit->code = 1;      /* It will be aircraft dependent */
264     //  cockpit->status = 0;
265
266     // If aircraft has HUD specified we will get the specs from its def
267     // file. For now we will depend upon hard coding in hud?
268     
269     // We must insure that the existing instrument link is purged.
270     // This is done by deleting the links in the list.
271     
272     // HI_Head is now a null pointer so we can generate a new list from the
273     // current aircraft.
274
275     fgHUDInit( cur_aircraft );
276     ac_cockpit = new fg_Cockpit();
277     
278     if ( current_options.get_panel_status() ) {
279         fgPanelInit();
280     }
281
282     FG_LOG( FG_COCKPIT, FG_INFO,
283             "  Code " << ac_cockpit->code() << " Status " 
284             << ac_cockpit->status() );
285     
286     return true;
287 }
288
289
290 void fgCockpitUpdate( void ) {
291     fgVIEW *pview;
292
293     pview = &current_view;
294
295     FG_LOG( FG_COCKPIT, FG_DEBUG,
296             "Cockpit: code " << ac_cockpit->code() << " status " 
297             << ac_cockpit->status() );
298
299     if ( current_options.get_hud_status() ) {
300         // This will check the global hud linked list pointer.
301         // If these is anything to draw it will.
302         fgUpdateHUD();
303     }
304
305     if ( current_options.get_panel_status() && 
306          (fabs(pview->view_offset) < 0.2) ) {
307         fgPanelUpdate();
308     }
309 }
310
311
312 // $Log$
313 // Revision 1.22  1998/11/06 21:17:45  curt
314 // Converted to new logstream debugging facility.  This allows release
315 // builds with no messages at all (and no performance impact) by using
316 // the -DFG_NDEBUG flag.
317 //
318 // Revision 1.21  1998/11/02 23:04:02  curt
319 // HUD units now display in feet by default with meters being a command line
320 // option.
321 //
322 // Revision 1.20  1998/10/25 14:08:40  curt
323 // Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
324 //
325 // Revision 1.19  1998/10/17 01:33:56  curt
326 // C++ ifying ...
327 //
328 // Revision 1.18  1998/10/16 23:27:23  curt
329 // C++-ifying.
330 //
331 // Revision 1.17  1998/09/29 14:56:30  curt
332 // c++-ified comments.
333 //
334 // Revision 1.16  1998/09/29 02:01:06  curt
335 // Added a "rate of climb" indicator.
336 //
337 // Revision 1.15  1998/08/28 18:14:39  curt
338 // Added new cockpit code from Friedemann Reinhard
339 // <mpt218@faupt212.physik.uni-erlangen.de>
340 //
341 // Revision 1.14  1998/08/24 20:05:15  curt
342 // Added a second minimalistic HUD.
343 // Added code to display the number of triangles rendered.
344 //
345 // Revision 1.13  1998/08/22 01:19:27  curt
346 // Omit panel code because it's texture loading overruns array bounds.
347 //
348 // Revision 1.12  1998/07/13 21:28:00  curt
349 // Converted the aoa scale to a radio altimeter.
350 //
351 // Revision 1.11  1998/07/13 21:00:45  curt
352 // Integrated Charlies latest HUD updates.
353 // Wrote access functions for current fgOPTIONS.
354 //
355 // Revision 1.10  1998/07/08 14:41:08  curt
356 // Renamed polar3d.h to polar3d.hxx
357 //
358 // Revision 1.9  1998/06/27 16:47:53  curt
359 // Incorporated Friedemann Reinhard's <mpt218@faupt212.physik.uni-erlangen.de>
360 // first pass at an isntrument panel.
361 //
362 // Revision 1.8  1998/05/17 16:58:12  curt
363 // Added a View Frustum Culling ratio display to the hud.
364 //
365 // Revision 1.7  1998/05/16 13:04:13  curt
366 // New updates from Charlie Hotchkiss.
367 //
368 // Revision 1.6  1998/05/13 18:27:53  curt
369 // Added an fov to hud display.
370 //
371 // Revision 1.5  1998/05/11 18:13:10  curt
372 // Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
373 //
374 // Revision 1.4  1998/05/03 00:46:45  curt
375 // polar.h -> polar3d.h
376 //
377 // Revision 1.3  1998/04/30 12:36:02  curt
378 // C++-ifying a couple source files.
379 //
380 // Revision 1.2  1998/04/25 22:06:26  curt
381 // Edited cvs log messages in source files ... bad bad bad!
382 //
383 // Revision 1.1  1998/04/24 00:45:54  curt
384 // C++-ifing the code a bit.
385 //
386 // Revision 1.13  1998/04/18 04:14:01  curt
387 // Moved fg_debug.c to it's own library.
388 //
389 // Revision 1.12  1998/04/14 02:23:09  curt
390 // Code reorganizations.  Added a Lib/ directory for more general libraries.
391 //
392 // Revision 1.11  1998/03/14 00:32:13  curt
393 // Changed a printf() to a fgPrintf().
394 //
395 // Revision 1.10  1998/02/07 15:29:33  curt
396 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
397 // <chotchkiss@namg.us.anritsu.com>
398 //
399 // Revision 1.9  1998/02/03 23:20:14  curt
400 // Lots of little tweaks to fix various consistency problems discovered by
401 // Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
402 // passed arguments along to the real printf().  Also incorporated HUD changes
403 // by Michele America.
404 //
405 // Revision 1.8  1998/01/31 00:43:03  curt
406 // Added MetroWorks patches from Carmen Volpe.
407 //
408 // Revision 1.7  1998/01/27 00:47:51  curt
409 // Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
410 // system and commandline/config file processing code.
411 //
412 // Revision 1.6  1998/01/19 19:27:01  curt
413 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
414 // This should simplify things tremendously.
415 //
416 // Revision 1.5  1998/01/19 18:40:19  curt
417 // Tons of little changes to clean up the code and to remove fatal errors
418 // when building with the c++ compiler.
419 //
420 // Revision 1.4  1997/12/30 20:47:34  curt
421 // Integrated new event manager with subsystem initializations.
422 //
423 // Revision 1.3  1997/12/15 23:54:33  curt
424 // Add xgl wrappers for debugging.
425 // Generate terrain normals on the fly.
426 //
427 // Revision 1.2  1997/12/10 22:37:38  curt
428 // Prepended "fg" on the name of all global structures that didn't have it yet.
429 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
430 //
431 // Revision 1.1  1997/08/29 18:03:20  curt
432 // Initial revision.
433 //
434