]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/cockpit.cxx
turn a few #include paths from the "foo" form to <foo>
[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
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33
34 #include <simgear/constants.h>
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/props/props.hxx>
37 #include <simgear/timing/sg_time.hxx>
38
39 #include <Aircraft/aircraft.hxx>
40 #include <Include/general.hxx>
41 #ifdef ENABLE_SP_FDM
42 #include <FDM/SP/ADA.hxx>
43 #endif
44 #include <Main/globals.hxx>
45 #include <Main/fg_props.hxx>
46 #include <Main/viewmgr.hxx>
47 #include <Scenery/scenery.hxx>
48 #include <GUI/gui.h>
49
50 #include "cockpit.hxx"
51 #include "hud.hxx"
52
53
54 // The following routines obtain information concerntin the aircraft's
55 // current state and return it to calling instrument display routines.
56 // They should eventually be member functions of the aircraft.
57 //
58
59 float get_latitude( void )
60 {
61     return current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
62 }
63
64 float get_lat_min( void )
65 {
66     double a, d;
67
68     a = current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
69     if (a < 0.0) {
70         a = -a;
71     }
72     d = (double) ( (int) a);
73     float lat_min = (a - d) * 60.0;
74
75     return lat_min;
76 }
77
78
79 float get_longitude( void )
80 {
81     return current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
82 }
83
84
85 char*
86 get_formated_gmt_time( void )
87 {
88     static char buf[32];
89     const struct tm *p = globals->get_time_params()->getGmt();
90     sprintf( buf, "%d/%d/%4d %d:%02d:%02d",
91          p->tm_mon+1, p->tm_mday, 1900 + p->tm_year,
92          p->tm_hour, p->tm_min, p->tm_sec);
93
94     return buf;
95 }
96
97
98 float get_long_min( void )
99 {
100     double  a, d;
101     a = current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
102     if (a < 0.0) {
103         a = -a;
104     }
105     d = (double) ( (int) a);
106     float lon_min = (a - d) * 60.0;
107
108     return lon_min;
109 }
110
111 float get_throttleval( void )
112 {
113     // Hack limiting to one engine
114     return globals->get_controls()->get_throttle( 0 );
115 }
116
117 float get_aileronval( void )
118 {
119     return globals->get_controls()->get_aileron();
120 }
121
122 float get_elevatorval( void )
123 {
124     return globals->get_controls()->get_elevator();
125 }
126
127 float get_elev_trimval( void )
128 {
129     return globals->get_controls()->get_elevator_trim();
130 }
131
132 float get_rudderval( void )
133 {
134     return globals->get_controls()->get_rudder();
135 }
136
137 float get_speed( void )
138 {
139     static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
140
141     float speed = current_aircraft.fdm_state->get_V_calibrated_kts()
142         * speedup_node->getIntValue();
143
144     return speed;
145 }
146
147 float get_mach(void)
148 {
149     return current_aircraft.fdm_state->get_Mach_number();
150 }
151
152 float get_aoa( void )
153 {
154     return current_aircraft.fdm_state->get_Alpha() * SGD_RADIANS_TO_DEGREES;
155 }
156
157 float get_roll( void )
158 {
159     return current_aircraft.fdm_state->get_Phi();
160 }
161
162 float get_pitch( void )
163 {
164     return current_aircraft.fdm_state->get_Theta();
165 }
166
167 float get_heading( void )
168 {
169     return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES;
170 }
171
172 float get_altitude( void )
173 {
174     static const SGPropertyNode *startup_units_node
175         = fgGetNode("/sim/startup/units");
176
177     float altitude;
178
179     if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
180         altitude = current_aircraft.fdm_state->get_Altitude();
181     } else {
182         altitude = (current_aircraft.fdm_state->get_Altitude()
183                     * SG_FEET_TO_METER);
184     }
185
186     return altitude;
187 }
188
189 float get_agl( void )
190 {
191     static const SGPropertyNode *startup_units_node
192         = fgGetNode("/sim/startup/units");
193
194     float agl;
195
196     if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
197         agl = (current_aircraft.fdm_state->get_Altitude()
198                - current_aircraft.fdm_state->get_Runway_altitude());
199     } else {
200         agl = (current_aircraft.fdm_state->get_Altitude()
201                - current_aircraft.fdm_state->get_Runway_altitude()) * SG_FEET_TO_METER;
202     }
203
204     return agl;
205 }
206
207 float get_sideslip( void )
208 {
209     return current_aircraft.fdm_state->get_Beta();
210 }
211
212 float get_frame_rate( void )
213 {
214     return general.get_frame_rate();
215 }
216
217 float get_fov( void )
218 {
219     return globals->get_current_view()->get_fov();
220 }
221
222 float get_vfc_ratio( void )
223 {
224     // float vfc = current_view.get_vfc_ratio();
225     // return (vfc);
226     return 0.0;
227 }
228
229 float get_vfc_tris_drawn   ( void )
230 {
231     // float rendered = current_view.get_tris_rendered();
232     // return (rendered);
233     return 0.0;
234 }
235
236 float get_vfc_tris_culled   ( void )
237 {
238     // float culled = current_view.get_tris_culled();
239     // return (culled);
240     return 0.0;
241 }
242
243 float get_climb_rate( void )
244 {
245     static const SGPropertyNode *startup_units_node
246         = fgGetNode("/sim/startup/units");
247
248     float climb_rate;
249     if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
250         climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
251     } else {
252         climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * SG_FEET_TO_METER * 60.0;
253     }
254
255     return climb_rate;
256 }
257
258
259 float get_view_direction( void )
260 {
261     double view_off = SGD_2PI - globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
262     double view = ( current_aircraft.fdm_state->get_Psi() + view_off)
263         * SGD_RADIANS_TO_DEGREES;
264
265     if (view > 360.)
266         view -= 360.;
267     else if (view<0.)
268         view += 360.;
269
270     return view;
271 }
272
273 // Added by Markus Hof on 5. Jan 2004
274 float get_dme( void )
275 {
276     static const SGPropertyNode * dme_node =
277         fgGetNode("/instrumentation/dme/indicated-distance-nm");
278
279     return dme_node->getFloatValue();
280 }
281
282 // $$$ begin - added, VS Renganathan 13 Oct 2K
283 // #ifdef FIGHTER_HUD
284 float get_Vx   ( void )
285 {
286     // Curt dont comment this and return zero. - Ranga
287     // Please remove comments from get_V_..() function in flight.hxx
288     float Vxx = current_aircraft.fdm_state->get_V_north_rel_ground();
289     return Vxx;
290 }
291
292 float get_Vy   ( void )
293 {
294     // Curt dont comment this and return zero. - Ranga
295     // Please remove comments from get_V_..() function in flight.hxx
296     float Vyy = current_aircraft.fdm_state->get_V_east_rel_ground();
297     return Vyy;
298 }
299
300 float get_Vz   ( void )
301 {
302     // Curt dont comment this and return zero. - Ranga
303     // Please remove comments from get_V_..() function in flight.hxx
304     float Vzz = current_aircraft.fdm_state->get_V_down_rel_ground();
305     return Vzz;
306 }
307
308 float get_Ax   ( void )
309 {
310     float Ax = current_aircraft.fdm_state->get_V_dot_north();
311     return Ax;
312 }
313
314 float get_Ay   ( void )
315 {
316     float Ay = current_aircraft.fdm_state->get_V_dot_east();
317     return Ay;
318 }
319
320 float get_Az   ( void )
321 {
322     float Az = current_aircraft.fdm_state->get_V_dot_down();
323     return Az;
324 }
325
326 float get_anzg   ( void )
327 {
328     float anzg = current_aircraft.fdm_state->get_N_Z_cg();
329     return anzg;
330 }
331
332 #ifdef ENABLE_SP_FDM
333 int get_iaux1 (void)
334 {
335     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
336     return fdm->get_iaux(1);
337 }
338
339 int get_iaux2 (void)
340 {
341     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
342     return fdm->get_iaux(2);
343 }
344
345 int get_iaux3 (void)
346 {
347     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
348     return fdm->get_iaux(3);
349 }
350
351 int get_iaux4 (void)
352 {
353     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
354     return fdm->get_iaux(4);
355 }
356
357 int get_iaux5 (void)
358 {
359     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
360     return fdm->get_iaux(5);
361 }
362
363 int get_iaux6 (void)
364 {
365     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
366     return fdm->get_iaux(6);
367 }
368
369 int get_iaux7 (void)
370 {
371     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
372     return fdm->get_iaux(7);
373 }
374
375 int get_iaux8 (void)
376 {
377     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
378     return fdm->get_iaux(8);
379 }
380
381 int get_iaux9 (void)
382 {
383     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
384     return fdm->get_iaux(9);
385 }
386
387 int get_iaux10 (void)
388 {
389     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
390     return fdm->get_iaux(10);
391 }
392
393 int get_iaux11 (void)
394 {
395     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
396     return fdm->get_iaux(11);
397 }
398
399 int get_iaux12 (void)
400 {
401      FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
402      return fdm->get_iaux(12);
403 }
404
405 float get_aux1 (void)
406 {
407     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
408     return fdm->get_daux(1);
409 }
410
411 float get_aux2 (void)
412 {
413     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
414     return fdm->get_daux(2);
415 }
416
417 float get_aux3 (void)
418 {
419     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
420     return fdm->get_daux(3);
421 }
422
423 float get_aux4 (void)
424 {
425     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
426     return fdm->get_daux(4);
427 }
428
429 float get_aux5 (void)
430 {
431     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
432     return fdm->get_daux(5);
433 }
434
435 float get_aux6 (void)
436 {
437     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
438     return fdm->get_daux(6);
439 }
440
441 float get_aux7 (void)
442 {
443     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
444     return fdm->get_daux(7);
445 }
446
447 float get_aux8 (void)
448 {
449     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
450     return fdm->get_daux(8);
451 }
452
453 float get_aux9 (void)
454 {
455     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
456     return fdm->get_faux(1);
457 }
458
459 float get_aux10 (void)
460 {
461     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
462     return fdm->get_faux(2);
463 }
464
465 float get_aux11 (void)
466 {
467     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
468     return fdm->get_faux(3);
469 }
470
471 float get_aux12 (void)
472 {
473     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
474     return fdm->get_faux(4);
475 }
476
477 float get_aux13 (void)
478 {
479     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
480     return fdm->get_faux(5);
481 }
482
483 float get_aux14 (void)
484 {
485     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
486     return fdm->get_faux(6);
487 }
488
489 float get_aux15 (void)
490 {
491     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
492     return fdm->get_faux(7);
493 }
494
495 float get_aux16 (void)
496 {
497     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
498     return fdm->get_faux(8);
499 }
500
501 float get_aux17 (void)
502 {
503     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
504     return fdm->get_faux(9);
505 }
506
507 float get_aux18 (void)
508 {
509     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
510     return fdm->get_faux(10);
511 }
512 #endif
513
514
515 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
516 {
517     SG_LOG( SG_COCKPIT, SG_INFO, "Initializing cockpit subsystem" );
518
519     //  cockpit->code = 1;  /* It will be aircraft dependent */
520     //  cockpit->status = 0;
521
522     // If aircraft has HUD specified we will get the specs from its def
523     // file. For now we will depend upon hard coding in hud?
524
525     // We must insure that the existing instrument link is purged.
526     // This is done by deleting the links in the list.
527
528     // HI_Head is now a null pointer so we can generate a new list from the
529     // current aircraft.
530
531     fgHUDInit( cur_aircraft );
532
533     return true;
534 }
535
536 void fgCockpitUpdate( osg::State* state ) {
537
538     static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
539     static const SGPropertyNode * ysize_node = fgGetNode("/sim/startup/ysize");
540     static const SGPropertyNode * hud_visibility_node
541         = fgGetNode("/sim/hud/visibility");
542
543     int iwidth   = xsize_node->getIntValue();
544     int iheight  = ysize_node->getIntValue();
545
546                                 // FIXME: inefficient
547     if ( hud_visibility_node->getBoolValue() ) {
548         // This will check the global hud linked list pointer.
549         // If there is anything to draw it will.
550         fgUpdateHUD( state );
551     }
552
553     glViewport( 0, 0, iwidth, iheight );
554 }
555
556
557
558
559
560 struct FuncTable {
561     const char *name;
562     FLTFNPTR func;
563 } fn_table[] = {
564     { "agl", get_agl },
565     { "aileronval", get_aileronval },
566     { "altitude", get_altitude },
567     { "anzg", get_anzg },
568     { "aoa", get_aoa },
569     { "ax", get_Ax },
570     { "climb", get_climb_rate },
571     { "elevatortrimval", get_elev_trimval },
572     { "elevatorval", get_elevatorval },
573     { "fov", get_fov },
574     { "framerate", get_frame_rate },
575     { "heading", get_heading },
576     { "latitude", get_latitude },
577     { "longitude", get_longitude },
578     { "mach", get_mach },
579     { "rudderval", get_rudderval },
580     { "speed", get_speed },
581     { "throttleval", get_throttleval },
582     { "view_direction", get_view_direction },
583     { "vfc_tris_culled", get_vfc_tris_culled },
584     { "vfc_tris_drawn", get_vfc_tris_drawn },
585 #ifdef ENABLE_SP_FDM
586     { "aux1", get_aux1 },
587     { "aux2", get_aux2 },
588     { "aux3", get_aux3 },
589     { "aux4", get_aux4 },
590     { "aux5", get_aux5 },
591     { "aux6", get_aux6 },
592     { "aux7", get_aux7 },
593     { "aux8", get_aux8 },
594     { "aux9", get_aux9 },
595     { "aux10", get_aux10 },
596     { "aux11", get_aux11 },
597     { "aux12", get_aux12 },
598     { "aux13", get_aux13 },
599     { "aux14", get_aux14 },
600     { "aux15", get_aux15 },
601     { "aux16", get_aux16 },
602     { "aux17", get_aux17 },
603     { "aux18", get_aux18 },
604 #endif
605     { 0, 0 },
606 };
607
608
609 FLTFNPTR get_func(const char *name)
610 {
611     for (int i = 0; fn_table[i].name; i++)
612         if (!strcmp(fn_table[i].name, name))
613             return fn_table[i].func;
614
615     return 0;
616 }
617
618