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