1 /**************************************************************************
2 * cockpit.cxx -- routines to draw a cockpit (initial draft)
4 * Written by Michele America, started September 1997.
6 * Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
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.
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.
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.
23 * (Log is kept at end of this file)
24 **************************************************************************/
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>
55 #include "cockpit.hxx"
58 // This is a structure that contains all data related to
59 // cockpit/panel/hud system
61 static pCockpit ac_cockpit;
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.
68 double get_latitude( void )
71 f = current_aircraft.flight;
73 // return( toDM(FG_Latitude * RAD_TO_DEG) );
74 return((double)((int)( FG_Latitude * RAD_TO_DEG)) );
76 double get_lat_min( void )
81 f = current_aircraft.flight;
83 a = FG_Latitude * RAD_TO_DEG;
87 d = (double) ( (int) a);
88 return( (a - d) * 60.0);
92 double get_longitude( void )
95 f = current_aircraft.flight;
97 // return( toDM(FG_Longitude * RAD_TO_DEG) );
98 return((double)((int) (FG_Longitude * RAD_TO_DEG)) );
100 double get_long_min( void )
105 f = current_aircraft.flight;
107 a = FG_Longitude * RAD_TO_DEG;
111 d = (double) ( (int) a);
112 return( (a - d) * 60.0);
115 double get_throttleval( void )
117 fgCONTROLS *pcontrols;
119 pcontrols = current_aircraft.controls;
120 return pcontrols->throttle[0]; // Hack limiting to one engine
123 double get_aileronval( void )
125 fgCONTROLS *pcontrols;
127 pcontrols = current_aircraft.controls;
128 return pcontrols->aileron;
131 double get_elevatorval( void )
133 fgCONTROLS *pcontrols;
135 pcontrols = current_aircraft.controls;
136 return pcontrols->elevator;
139 double get_elev_trimval( void )
141 fgCONTROLS *pcontrols;
143 pcontrols = current_aircraft.controls;
144 return pcontrols->elevator_trim;
147 double get_rudderval( void )
149 fgCONTROLS *pcontrols;
151 pcontrols = current_aircraft.controls;
152 return pcontrols->rudder;
155 double get_speed( void )
159 f = current_aircraft.flight;
160 return( FG_V_equiv_kts ); // Make an explicit function call.
163 double get_aoa( void )
167 f = current_aircraft.flight;
168 return( FG_Gamma_vert_rad * RAD_TO_DEG );
171 double get_roll( void )
175 f = current_aircraft.flight;
179 double get_pitch( void )
183 f = current_aircraft.flight;
187 double get_heading( void )
191 f = current_aircraft.flight;
192 return( FG_Psi * RAD_TO_DEG );
195 double get_altitude( void )
198 // double rough_elev;
200 f = current_aircraft.flight;
201 // rough_elev = mesh_altitude(FG_Longitude * RAD_TO_ARCSEC,
202 // FG_Latitude * RAD_TO_ARCSEC);
204 return( FG_Altitude * FEET_TO_METER /* -rough_elev */ );
207 double get_agl( void )
212 f = current_aircraft.flight;
213 agl = FG_Altitude * FEET_TO_METER - scenery.cur_elev;
218 double get_sideslip( void )
222 f = current_aircraft.flight;
227 double get_frame_rate( void )
233 return pgeneral->frame_rate;
236 double get_fov( void )
238 return (current_options.get_fov());
241 double get_vfc_ratio( void )
245 pview = ¤t_view;
247 return pview->vfc_ratio;
250 double get_vfc_tris_drawn ( void )
252 return current_view.tris_rendered;
256 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
258 fgPrintf( FG_COCKPIT, FG_INFO, "Initializing cockpit subsystem\n");
260 // cockpit->code = 1; /* It will be aircraft dependent */
261 // cockpit->status = 0;
263 // If aircraft has HUD specified we will get the specs from its def
264 // file. For now we will depend upon hard coding in hud?
266 // We must insure that the existing instrument link is purged.
267 // This is done by deleting the links in the list.
269 // HI_Head is now a null pointer so we can generate a new list from the
272 fgHUDInit( cur_aircraft );
273 ac_cockpit = new fg_Cockpit();
279 fgPrintf( FG_COCKPIT, FG_INFO,
280 " Code %d Status %d\n",
281 ac_cockpit->code(), ac_cockpit->status() );
287 void fgCockpitUpdate( void ) {
290 pview = ¤t_view;
292 fgPrintf( FG_COCKPIT, FG_DEBUG,
293 "Cockpit: code %d status %d\n",
294 ac_cockpit->code(), ac_cockpit->status() );
296 if ( current_options.get_hud_status() ) {
297 // This will check the global hud linked list pointer.
298 // If these is anything to draw it will.
303 if ( current_options.get_panel_status() &&
304 (fabs(pview->view_offset) < 0.2) ) {
312 /* Revision 1.14 1998/08/24 20:05:15 curt
313 /* Added a second minimalistic HUD.
314 /* Added code to display the number of triangles rendered.
316 * Revision 1.13 1998/08/22 01:19:27 curt
317 * Omit panel code because it's texture loading overruns array bounds.
319 * Revision 1.12 1998/07/13 21:28:00 curt
320 * Converted the aoa scale to a radio altimeter.
322 * Revision 1.11 1998/07/13 21:00:45 curt
323 * Integrated Charlies latest HUD updates.
324 * Wrote access functions for current fgOPTIONS.
326 * Revision 1.10 1998/07/08 14:41:08 curt
327 * Renamed polar3d.h to polar3d.hxx
329 * Revision 1.9 1998/06/27 16:47:53 curt
330 * Incorporated Friedemann Reinhard's <mpt218@faupt212.physik.uni-erlangen.de>
331 * first pass at an isntrument panel.
333 * Revision 1.8 1998/05/17 16:58:12 curt
334 * Added a View Frustum Culling ratio display to the hud.
336 * Revision 1.7 1998/05/16 13:04:13 curt
337 * New updates from Charlie Hotchkiss.
339 * Revision 1.6 1998/05/13 18:27:53 curt
340 * Added an fov to hud display.
342 * Revision 1.5 1998/05/11 18:13:10 curt
343 * Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
345 * Revision 1.4 1998/05/03 00:46:45 curt
346 * polar.h -> polar3d.h
348 * Revision 1.3 1998/04/30 12:36:02 curt
349 * C++-ifying a couple source files.
351 * Revision 1.2 1998/04/25 22:06:26 curt
352 * Edited cvs log messages in source files ... bad bad bad!
354 * Revision 1.1 1998/04/24 00:45:54 curt
355 * C++-ifing the code a bit.
357 * Revision 1.13 1998/04/18 04:14:01 curt
358 * Moved fg_debug.c to it's own library.
360 * Revision 1.12 1998/04/14 02:23:09 curt
361 * Code reorganizations. Added a Lib/ directory for more general libraries.
363 * Revision 1.11 1998/03/14 00:32:13 curt
364 * Changed a printf() to a fgPrintf().
366 * Revision 1.10 1998/02/07 15:29:33 curt
367 * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
368 * <chotchkiss@namg.us.anritsu.com>
370 * Revision 1.9 1998/02/03 23:20:14 curt
371 * Lots of little tweaks to fix various consistency problems discovered by
372 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
373 * passed arguments along to the real printf(). Also incorporated HUD changes
374 * by Michele America.
376 * Revision 1.8 1998/01/31 00:43:03 curt
377 * Added MetroWorks patches from Carmen Volpe.
379 * Revision 1.7 1998/01/27 00:47:51 curt
380 * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
381 * system and commandline/config file processing code.
383 * Revision 1.6 1998/01/19 19:27:01 curt
384 * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
385 * This should simplify things tremendously.
387 * Revision 1.5 1998/01/19 18:40:19 curt
388 * Tons of little changes to clean up the code and to remove fatal errors
389 * when building with the c++ compiler.
391 * Revision 1.4 1997/12/30 20:47:34 curt
392 * Integrated new event manager with subsystem initializations.
394 * Revision 1.3 1997/12/15 23:54:33 curt
395 * Add xgl wrappers for debugging.
396 * Generate terrain normals on the fly.
398 * Revision 1.2 1997/12/10 22:37:38 curt
399 * Prepended "fg" on the name of all global structures that didn't have it yet.
400 * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
402 * Revision 1.1 1997/08/29 18:03:20 curt