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