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