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