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