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