]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/cockpit.cxx
Merge commit 'refs/merge-requests/1552' of git@gitorious.org:fg/flightgear into next
[flightgear.git] / src / Cockpit / cockpit.cxx
1 // cockpit.cxx -- routines to draw a cockpit (initial draft)
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  - nomimarketing@mail.telepac.pt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <simgear/compiler.h>
29 #include <simgear/sg_inlines.h>
30
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34
35 #include <simgear/constants.h>
36 #include <simgear/debug/logstream.hxx>
37 #include <simgear/props/props.hxx>
38 #include <simgear/timing/sg_time.hxx>
39
40 #include <Include/general.hxx>
41
42 #include <Main/globals.hxx>
43 #include <Main/fg_props.hxx>
44 #include <Main/viewmgr.hxx>
45 #include <Main/viewer.hxx>
46 #include <Scenery/scenery.hxx>
47 #include <GUI/gui.h>
48
49 #include "cockpit.hxx"
50 #include "hud.hxx"
51
52 // The following routines obtain information concerntin the aircraft's
53 // current state and return it to calling instrument display routines.
54 // They should eventually be member functions of the aircraft.
55 //
56
57 float get_latitude( void )
58 {
59     return fgGetDouble("/position/latitude-deg");
60 }
61
62 float get_lat_min( void )
63 {
64     double a, d;
65
66     a = fgGetDouble("/position/latitude-deg");
67     if (a < 0.0) {
68         a = -a;
69     }
70     d = (double) ( (int) a);
71     float lat_min = (a - d) * 60.0;
72
73     return lat_min;
74 }
75
76
77 float get_longitude( void )
78 {
79     return fgGetDouble("/position/longitude-deg");
80 }
81
82
83 char*
84 get_formated_gmt_time( void )
85 {
86     static char buf[32];
87     const struct tm *p = globals->get_time_params()->getGmt();
88     sprintf( buf, "%d/%d/%4d %d:%02d:%02d",
89          p->tm_mon+1, p->tm_mday, 1900 + p->tm_year,
90          p->tm_hour, p->tm_min, p->tm_sec);
91
92     return buf;
93 }
94
95
96 float get_long_min( void )
97 {
98     double  a, d;
99     a = fgGetDouble("/position/longitude-deg");
100     if (a < 0.0) {
101         a = -a;
102     }
103     d = (double) ( (int) a);
104     float lon_min = (a - d) * 60.0;
105
106     return lon_min;
107 }
108
109 float get_throttleval( void )
110 {
111     // Hack limiting to one engine
112     return globals->get_controls()->get_throttle( 0 );
113 }
114
115 float get_aileronval( void )
116 {
117     return globals->get_controls()->get_aileron();
118 }
119
120 float get_elevatorval( void )
121 {
122     return globals->get_controls()->get_elevator();
123 }
124
125 float get_elev_trimval( void )
126 {
127     return globals->get_controls()->get_elevator_trim();
128 }
129
130 float get_rudderval( void )
131 {
132     return globals->get_controls()->get_rudder();
133 }
134
135 float get_speed( void )
136 {
137     static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
138
139     float speed = fgGetDouble("/velocities/airspeed-kt")
140         * speedup_node->getIntValue();
141
142     return speed;
143 }
144
145 float get_mach(void)
146 {
147     return fgGetDouble("/velocities/mach");
148 }
149
150 float get_aoa( void )
151 {
152     return fgGetDouble("/orientation/alpha-deg");
153 }
154
155 float get_roll( void )
156 {
157     return fgGetDouble("/orientation/roll-deg") * SG_DEGREES_TO_RADIANS;
158 }
159
160 float get_pitch( void )
161 {
162     return fgGetDouble("/orientation/pitch-deg") * SG_DEGREES_TO_RADIANS;
163 }
164
165 float get_heading( void )
166 {
167     return fgGetDouble("/orientation/heading-deg");
168 }
169
170 float get_altitude( void )
171 {
172     static const SGPropertyNode *startup_units_node
173         = fgGetNode("/sim/startup/units");
174
175     if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
176         return fgGetDouble("/position/altitude-ft");
177     } else {
178         return fgGetDouble("/position/altitude-ft") * SG_FEET_TO_METER;
179     }
180 }
181
182 float get_agl( void )
183 {
184     static const SGPropertyNode *startup_units_node
185         = fgGetNode("/sim/startup/units");
186
187     if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
188         return fgGetDouble("/position/altitude-agl-ft");
189     } else {
190         return fgGetDouble("/position/altitude-agl-ft") * SG_FEET_TO_METER;
191     }
192 }
193
194 float get_sideslip( void )
195 {
196     return fgGetDouble("/orientation/side-slip-rad");
197 }
198
199 float get_frame_rate( void )
200 {
201     return general.get_frame_rate();
202 }
203
204 float get_fov( void )
205 {
206     return globals->get_current_view()->get_fov();
207 }
208
209 float get_vfc_ratio( void )
210 {
211     // float vfc = current_view.get_vfc_ratio();
212     // return (vfc);
213     return 0.0;
214 }
215
216 float get_vfc_tris_drawn   ( void )
217 {
218     // float rendered = current_view.get_tris_rendered();
219     // return (rendered);
220     return 0.0;
221 }
222
223 float get_vfc_tris_culled   ( void )
224 {
225     // float culled = current_view.get_tris_culled();
226     // return (culled);
227     return 0.0;
228 }
229
230 float get_climb_rate( void )
231 {
232     static const SGPropertyNode *startup_units_node
233         = fgGetNode("/sim/startup/units");
234
235     float climb_rate = fgGetDouble("/velocities/vertical-speed-fps", 0.0);
236     if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
237         climb_rate *= 60.0;
238     } else {
239         climb_rate *= SG_FEET_TO_METER * 60.0;
240     }
241
242     return climb_rate;
243 }
244
245
246 float get_view_direction( void )
247 {
248     double view_off = 360.0 - globals->get_current_view()->getHeadingOffset_deg();
249     double view = fgGetDouble("/orientation/heading-deg") + view_off;
250     SG_NORMALIZE_RANGE(view, 0.0, 360.0);
251     return view;
252 }
253
254 // Added by Markus Hof on 5. Jan 2004
255 float get_dme( void )
256 {
257     static const SGPropertyNode * dme_node =
258         fgGetNode("/instrumentation/dme/indicated-distance-nm");
259
260     return dme_node->getFloatValue();
261 }
262
263 float get_Ax   ( void )
264 {
265     return fgGetDouble("/accelerations/ned/north-accel-fps_sec", 0.0);
266 }
267
268 float get_anzg   ( void )
269 {
270     return fgGetDouble("/accelerations/n-z-cg-fps_sec", 0.0);
271 }
272
273 #ifdef ENABLE_SP_FDM
274 float get_aux1 (void)
275 {
276     return fgGetDouble("/fdm-ada/ship-lat", 0.0);
277 }
278
279 float get_aux2 (void)
280 {
281     return fgGetDouble("/fdm-ada/ship-lon", 0.0);
282 }
283
284 float get_aux3 (void)
285 {
286     return fgGetDouble("/fdm-ada/ship-alt", 0.0);
287 }
288
289 float get_aux4 (void)
290 {
291     return fgGetDouble("/fdm-ada/skijump-dist", 0.0);
292 }
293
294 float get_aux5 (void)
295 {
296     return fgGetDouble("/fdm-ada/aux5", 0.0);
297 }
298
299 float get_aux6 (void)
300 {
301     return fgGetDouble("/fdm-ada/aux6", 0.0);
302 }
303
304 float get_aux7 (void)
305 {
306     return fgGetDouble("/fdm-ada/aux7", 0.0);
307 }
308
309 float get_aux8 (void)
310 {
311     return fgGetDouble("/fdm-ada/aux8", 0.0);}
312
313 float get_aux9 (void)
314 {
315     return fgGetDouble("/fdm-ada/aux9", 0.0);}
316
317 float get_aux10 (void)
318 {
319     return fgGetDouble("/fdm-ada/aux10", 0.0);
320 }
321
322 float get_aux11 (void)
323 {
324     return fgGetDouble("/fdm-ada/aux11", 0.0);
325 }
326
327 float get_aux12 (void)
328 {
329     return fgGetDouble("/fdm-ada/aux12", 0.0);
330 }
331
332 float get_aux13 (void)
333 {
334     return fgGetDouble("/fdm-ada/aux13", 0.0);
335 }
336
337 float get_aux14 (void)
338 {
339     return fgGetDouble("/fdm-ada/aux14", 0.0);
340 }
341
342 float get_aux15 (void)
343 {
344     return fgGetDouble("/fdm-ada/aux15", 0.0);
345 }
346
347 float get_aux16 (void)
348 {
349     return fgGetDouble("/fdm-ada/aux16", 0.0);
350 }
351
352 float get_aux17 (void)
353 {
354     return fgGetDouble("/fdm-ada/aux17", 0.0);
355 }
356
357 float get_aux18 (void)
358 {
359     return fgGetDouble("/fdm-ada/aux18", 0.0);
360 }
361 #endif
362
363
364 bool fgCockpitInit()
365 {
366     SG_LOG( SG_COCKPIT, SG_INFO, "Initializing cockpit subsystem" );
367
368     //  cockpit->code = 1;  /* It will be aircraft dependent */
369     //  cockpit->status = 0;
370
371     // If aircraft has HUD specified we will get the specs from its def
372     // file. For now we will depend upon hard coding in hud?
373
374     // We must insure that the existing instrument link is purged.
375     // This is done by deleting the links in the list.
376
377     // HI_Head is now a null pointer so we can generate a new list from the
378     // current aircraft.
379
380     fgHUDInit();
381
382     return true;
383 }
384
385 void fgCockpitUpdate( osg::State* state ) {
386
387     static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
388     static const SGPropertyNode * ysize_node = fgGetNode("/sim/startup/ysize");
389     static const SGPropertyNode * hud_visibility_node
390         = fgGetNode("/sim/hud/visibility");
391
392     int iwidth   = xsize_node->getIntValue();
393     int iheight  = ysize_node->getIntValue();
394
395                                 // FIXME: inefficient
396     if ( hud_visibility_node->getBoolValue() ) {
397         // This will check the global hud linked list pointer.
398         // If there is anything to draw it will.
399         fgUpdateHUD( state );
400     }
401
402     glViewport( 0, 0, iwidth, iheight );
403 }
404
405
406
407
408
409 struct FuncTable {
410     const char *name;
411     FLTFNPTR func;
412 } fn_table[] = {
413     { "agl", get_agl },
414     { "aileronval", get_aileronval },
415     { "altitude", get_altitude },
416     { "anzg", get_anzg },
417     { "aoa", get_aoa },
418     { "ax", get_Ax },
419     { "climb", get_climb_rate },
420     { "elevatortrimval", get_elev_trimval },
421     { "elevatorval", get_elevatorval },
422     { "fov", get_fov },
423     { "framerate", get_frame_rate },
424     { "heading", get_heading },
425     { "latitude", get_latitude },
426     { "longitude", get_longitude },
427     { "mach", get_mach },
428     { "rudderval", get_rudderval },
429     { "speed", get_speed },
430     { "throttleval", get_throttleval },
431     { "view_direction", get_view_direction },
432     { "vfc_tris_culled", get_vfc_tris_culled },
433     { "vfc_tris_drawn", get_vfc_tris_drawn },
434 #ifdef ENABLE_SP_FDM
435     { "aux1", get_aux1 },
436     { "aux2", get_aux2 },
437     { "aux3", get_aux3 },
438     { "aux4", get_aux4 },
439     { "aux5", get_aux5 },
440     { "aux6", get_aux6 },
441     { "aux7", get_aux7 },
442     { "aux8", get_aux8 },
443     { "aux9", get_aux9 },
444     { "aux10", get_aux10 },
445     { "aux11", get_aux11 },
446     { "aux12", get_aux12 },
447     { "aux13", get_aux13 },
448     { "aux14", get_aux14 },
449     { "aux15", get_aux15 },
450     { "aux16", get_aux16 },
451     { "aux17", get_aux17 },
452     { "aux18", get_aux18 },
453 #endif
454     { 0, 0 },
455 };
456
457
458 FLTFNPTR get_func(const char *name)
459 {
460     for (int i = 0; fn_table[i].name; i++)
461         if (!strcmp(fn_table[i].name, name))
462             return fn_table[i].func;
463
464     return 0;
465 }
466
467