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