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