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