]> git.mxchange.org Git - flightgear.git/blob - src/Main/keyboard.cxx
Code clean ups relating to FGOptions ... and moved it into globals-> space.
[flightgear.git] / src / Main / keyboard.cxx
1 // keyboard.cxx -- handle GLUT keyboard events
2 //
3 // Written by Curtis Olson, started May 1997.
4 //
5 // Copyright (C) 1997 - 1999  Curtis L. Olson  - curt@flightgear.org
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #ifdef HAVE_WINDOWS_H
29 #  include <windows.h>                     
30 #endif
31
32 #include <simgear/compiler.h>
33
34 #include <GL/glut.h>
35 #include <simgear/xgl/xgl.h>
36
37 #if defined(FX) && defined(XMESA)
38 #include <GL/xmesa.h>
39 #endif
40
41 #include <stdio.h>
42 #include <stdlib.h>
43
44 #include STL_FSTREAM
45
46 #include <plib/pu.h>            // plib include
47
48 #include <simgear/constants.h>
49 #include <simgear/debug/logstream.hxx>
50 #include <simgear/misc/fgpath.hxx>
51
52 #include <Aircraft/aircraft.hxx>
53 #include <Autopilot/auto_gui.hxx>
54 #include <Autopilot/newauto.hxx>
55 #include <Cockpit/hud.hxx>
56 #include <Cockpit/panel.hxx>
57 #include <Cockpit/panel_io.hxx>
58 #include <GUI/gui.h>
59 #include <Scenery/tilemgr.hxx>
60 #include <Objects/matlib.hxx>
61 #include <Time/light.hxx>
62 #include <Time/tmp.hxx>
63
64 #ifndef FG_OLD_WEATHER
65 #  include <WeatherCM/FGLocalWeatherDatabase.h>
66 #else
67 #  include <Weather/weather.hxx>
68 #endif
69
70 #include "bfi.hxx"
71 #include "globals.hxx"
72 #include "keyboard.hxx"
73 #include "options.hxx"
74 #include "save.hxx"
75
76                                 // From main.cxx
77 extern void fgReshape( int width, int height );
78
79
80 // Handle keyboard events
81 void GLUTkey(unsigned char k, int x, int y) {
82     FGInterface *f;
83     SGTime *t;
84     FGViewer *v;
85     float fov, tmp;
86     static bool winding_ccw = true;
87     int speed;
88
89     f = current_aircraft.fdm_state;
90     v = globals->get_current_view();
91
92     FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
93     if ( puKeyboard(k, PU_DOWN) ) {
94         return;
95     }
96
97     if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
98         FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
99         switch (k) {
100         case 1: // Ctrl-A key
101             current_autopilot->set_AltitudeMode( 
102                   FGAutopilot::FG_ALTITUDE_LOCK );
103             current_autopilot->set_AltitudeEnabled(
104                   ! current_autopilot->get_AltitudeEnabled()
105                 );
106             return;
107         case 7: // Ctrl-G key
108             current_autopilot->set_AltitudeMode( 
109                   FGAutopilot::FG_ALTITUDE_GS1 );
110             current_autopilot->set_AltitudeEnabled(
111                   ! current_autopilot->get_AltitudeEnabled()
112                 );
113             return;
114         case 8: // Ctrl-H key
115             current_autopilot->set_HeadingMode( 
116                   FGAutopilot::FG_HEADING_LOCK );
117             current_autopilot->set_HeadingEnabled(
118                   ! current_autopilot->get_HeadingEnabled()
119                 );
120             return;
121         case 14: // Ctrl-N key
122             current_autopilot->set_HeadingMode( 
123                   FGAutopilot::FG_HEADING_NAV1 );
124             current_autopilot->set_HeadingEnabled(
125                   ! current_autopilot->get_HeadingEnabled()
126                 );
127             return;
128         case 18: // Ctrl-R key
129             // temporary
130             winding_ccw = !winding_ccw;
131             if ( winding_ccw ) {
132                 glFrontFace ( GL_CCW );
133             } else {
134                 glFrontFace ( GL_CW );
135             }
136             return;
137         case 19: // Ctrl-S key
138             current_autopilot->set_AutoThrottleEnabled(
139                   ! current_autopilot->get_AutoThrottleEnabled()
140                 );
141             return;
142         case 20: // Ctrl-T key
143             current_autopilot->set_AltitudeMode( 
144                   FGAutopilot::FG_ALTITUDE_TERRAIN );
145             current_autopilot->set_AltitudeEnabled(
146                   ! current_autopilot->get_AltitudeEnabled()
147                 );
148             return;
149         case 21: // Ctrl-U key
150             // add 1000' of emergency altitude.  Possibly good for 
151             // unflipping yourself :-)
152             {
153                 double alt = cur_fdm_state->get_Altitude() + 1000;
154                 fgFDMForceAltitude( globals->get_options()->get_flight_model(), 
155                                     alt * FEET_TO_METER );
156             }
157             return;
158         case 49: // numeric keypad 1
159             v->set_goal_view_offset( FG_PI * 0.75 );
160             if ( globals->get_options()->get_view_mode() ==
161                  FGOptions::FG_VIEW_FOLLOW )
162             {
163                 globals->get_pilot_view()->set_pilot_offset(-25.0, 25.0, 1.0);
164                 v->set_view_offset( FG_PI * 0.75 );
165             }
166             return;
167         case 50: // numeric keypad 2
168             v->set_goal_view_offset( FG_PI );
169             if ( globals->get_options()->get_view_mode() ==
170                  FGOptions::FG_VIEW_FOLLOW )
171             {
172                 globals->get_pilot_view()->set_pilot_offset(-25.0, 0.0, 1.0);
173                 v->set_view_offset( FG_PI );
174             }
175             return;
176         case 51: // numeric keypad 3
177             v->set_goal_view_offset( FG_PI * 1.25 );
178             if ( globals->get_options()->get_view_mode() ==
179                  FGOptions::FG_VIEW_FOLLOW )
180             {
181                 globals->get_pilot_view()->set_pilot_offset(-25.0, -25.0, 1.0);
182                 v->set_view_offset( FG_PI * 1.25 );
183             }
184             return;
185         case 52: // numeric keypad 4
186             v->set_goal_view_offset( FG_PI * 0.50 );
187             if ( globals->get_options()->get_view_mode() ==
188                  FGOptions::FG_VIEW_FOLLOW )
189             {
190                 globals->get_pilot_view()->set_pilot_offset(0.0, 25.0, 1.0);
191                 v->set_view_offset( FG_PI * 0.50 );
192             }
193             return;
194         case 54: // numeric keypad 6
195             v->set_goal_view_offset( FG_PI * 1.50 );
196             if ( globals->get_options()->get_view_mode() ==
197                  FGOptions::FG_VIEW_FOLLOW )
198             {
199                 globals->get_pilot_view()->set_pilot_offset(0.0, -25.0, 1.0);
200                 v->set_view_offset( FG_PI * 1.50 );
201             }
202             return;
203         case 55: // numeric keypad 7
204             v->set_goal_view_offset( FG_PI * 0.25 );
205             if ( globals->get_options()->get_view_mode() ==
206                  FGOptions::FG_VIEW_FOLLOW )
207             {
208                 globals->get_pilot_view()->set_pilot_offset(25.0, 25.0, 1.0);
209                 v->set_view_offset( FG_PI * 0.25 );
210             }
211             return;
212         case 56: // numeric keypad 8
213             v->set_goal_view_offset( 0.00 );
214             if ( globals->get_options()->get_view_mode() ==
215                  FGOptions::FG_VIEW_FOLLOW )
216             {
217                 globals->get_pilot_view()->set_pilot_offset(25.0, 0.0, 1.0);
218                 v->set_view_offset( 0.00 );
219             }
220             return;
221         case 57: // numeric keypad 9
222             v->set_goal_view_offset( FG_PI * 1.75 );
223             if ( globals->get_options()->get_view_mode() ==
224                  FGOptions::FG_VIEW_FOLLOW )
225             {
226                 globals->get_pilot_view()->set_pilot_offset(25.0, -25.0, 1.0);
227                 v->set_view_offset( FG_PI * 1.75 );
228             }
229             return;
230         case 65: // A key
231             speed = globals->get_options()->get_speed_up();
232             speed--;
233             if ( speed < 1 ) {
234                 speed = 1;
235             }
236             globals->get_options()->set_speed_up( speed );
237             return;
238         case 72: // H key
239             // status = globals->get_options()->get_hud_status();
240             // globals->get_options()->set_hud_status(!status);
241             HUD_brightkey( true );
242             return;
243         case 73: // I key
244             // Minimal Hud
245             fgHUDInit2(&current_aircraft);
246             return;
247         case 77: // M key
248             globals->inc_warp( -60 );
249             fgUpdateSkyAndLightingParams();
250             return;
251         case 80: // P key
252             globals->get_options()->toggle_panel();
253             break;
254         case 84: // T key
255             globals->inc_warp_delta( -30 );
256             fgUpdateSkyAndLightingParams();
257             return;
258         case 87: // W key
259 #if defined(FX) && !defined(WIN32)
260             global_fullscreen = ( !global_fullscreen );
261 #  if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
262             XMesaSetFXmode( global_fullscreen ? 
263                             XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
264 #  endif
265 #endif
266             return;
267         case 88: // X key
268             fov = globals->get_options()->get_fov();
269             fov *= 1.05;
270             if ( fov > FG_FOV_MAX ) {
271                 fov = FG_FOV_MAX;
272             }
273             globals->get_options()->set_fov(fov);
274             v->force_update_fov_math();
275             return;
276         case 90: // Z key
277 #ifndef FG_OLD_WEATHER
278             tmp = WeatherDatabase->getWeatherVisibility();
279             tmp /= 1.10;
280             WeatherDatabase->setWeatherVisibility( tmp );
281 #else
282             tmp = current_weather.get_visibility();   // in meters
283             tmp /= 1.10;
284             current_weather.set_visibility( tmp );
285 #endif
286             return;
287         }
288     } else {
289         FG_LOG( FG_INPUT, FG_DEBUG, "" );
290         switch (k) {
291         case 50: // numeric keypad 2
292             if ( current_autopilot->get_AltitudeEnabled() ) {
293                 current_autopilot->AltitudeAdjust( 100 );
294             } else {
295                 controls.move_elevator(-0.05);
296             }
297             return;
298         case 56: // numeric keypad 8
299             if ( current_autopilot->get_AltitudeEnabled() ) {
300                 current_autopilot->AltitudeAdjust( -100 );
301             } else {
302                 controls.move_elevator(0.05);
303             }
304             return;
305         case 49: // numeric keypad 1
306             controls.move_elevator_trim(-0.001);
307             return;
308         case 55: // numeric keypad 7
309             controls.move_elevator_trim(0.001);
310             return;
311         case 52: // numeric keypad 4
312             controls.move_aileron(-0.05);
313             return;
314         case 54: // numeric keypad 6
315             controls.move_aileron(0.05);
316             return;
317         case 48: // numeric keypad Ins
318             if ( current_autopilot->get_HeadingEnabled() ) {
319                 current_autopilot->HeadingAdjust( -1 );
320             } else {
321                 controls.move_rudder(-0.05);
322             }
323             return;
324         case 13: // numeric keypad Enter
325             if ( current_autopilot->get_HeadingEnabled() ) {
326                 current_autopilot->HeadingAdjust( 1 );
327             } else {
328                 controls.move_rudder(0.05);
329             }
330             return;
331         case 53: // numeric keypad 5
332             controls.set_aileron(0.0);
333             controls.set_elevator(0.0);
334             controls.set_rudder(0.0);
335             return;
336         case 57: // numeric keypad 9 (Pg Up)
337             if ( current_autopilot->get_AutoThrottleEnabled() ) {
338                 current_autopilot->AutoThrottleAdjust( 5 );
339             } else {
340                 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
341             }
342             return;
343         case 51: // numeric keypad 3 (Pg Dn)
344             if ( current_autopilot->get_AutoThrottleEnabled() ) {
345                 current_autopilot->AutoThrottleAdjust( -5 );
346             } else {
347                 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );
348             }
349             return;
350         case 91: // [ key
351             controls.move_flaps(-0.34);
352             FG_LOG( FG_INPUT, FG_INFO,
353                     "Set flaps to " << controls.get_flaps() );
354             return;
355         case 93: // ] key
356             controls.move_flaps(0.34);
357             FG_LOG( FG_INPUT, FG_INFO,
358                     "Set flaps to " << controls.get_flaps() );
359             return;
360         case 97: // a key
361             speed = globals->get_options()->get_speed_up();
362             speed++;
363             globals->get_options()->set_speed_up( speed );
364             return;
365         case 98: // b key
366             int b_ret;
367             double b_set;
368             b_ret = int( controls.get_brake( 0 ) );
369             b_set = double(!b_ret);
370             controls.set_brake( FGControls::ALL_WHEELS, b_set);
371             return;
372         case 44: // , key
373             if (controls.get_brake(0) > 0.0) {
374                 controls.set_brake(0, 0.0);
375             } else {
376                 controls.set_brake(0, 1.0);
377             }
378             return;
379         case 46: // . key
380             if (controls.get_brake(1) > 0.0) {
381                 controls.set_brake(1, 0.0);
382             } else {
383                 controls.set_brake(1, 1.0);
384             }
385             return;
386         case 104: // h key
387             HUD_masterswitch( true );
388             return;
389         case 105: // i key
390             fgHUDInit(&current_aircraft);  // normal HUD
391             return;
392         case 109: // m key
393             globals->inc_warp( 60 );
394             fgUpdateSkyAndLightingParams();
395             return;
396         case 112: // p key
397             globals->set_freeze( ! globals->get_freeze() );
398
399             {
400                 FGBucket p( f->get_Longitude() * RAD_TO_DEG,
401                             f->get_Latitude() * RAD_TO_DEG );
402                 FGPath tile_path( globals->get_options()->get_fg_root() );
403                 tile_path.append( "Scenery" );
404                 tile_path.append( p.gen_base_path() );
405                 tile_path.append( p.gen_index_str() );
406
407                 // printf position and attitude information
408                 FG_LOG( FG_INPUT, FG_INFO,
409                         "Lon = " << f->get_Longitude() * RAD_TO_DEG
410                         << "  Lat = " << f->get_Latitude() * RAD_TO_DEG
411                         << "  Altitude = " << f->get_Altitude() * FEET_TO_METER
412                         );
413                 FG_LOG( FG_INPUT, FG_INFO,
414                         "Heading = " << f->get_Psi() * RAD_TO_DEG 
415                         << "  Roll = " << f->get_Phi() * RAD_TO_DEG
416                         << "  Pitch = " << f->get_Theta() * RAD_TO_DEG );
417                 FG_LOG( FG_INPUT, FG_INFO, tile_path.c_str());
418             }
419             return;
420         case 116: // t key
421             globals->inc_warp_delta( 30 );
422             fgUpdateSkyAndLightingParams();
423             return;
424         case 118: // v key
425 //          globals->get_options()->cycle_view_mode();
426             if ( globals->get_options()->get_view_mode() ==
427                  FGOptions::FG_VIEW_FOLLOW )
428             {
429                 globals->get_options()->set_view_mode(FGOptions::FG_VIEW_PILOT);
430                 v->set_goal_view_offset( 0.0 );
431                 v->set_view_offset( 0.0 );
432             } else if ( globals->get_options()->get_view_mode() ==
433                         FGOptions::FG_VIEW_PILOT )
434             {
435                 globals->get_options()->set_view_mode( FGOptions::FG_VIEW_FOLLOW );
436                 v->set_goal_view_offset( FG_PI * 1.75 );
437                 v->set_view_offset( FG_PI * 1.75 );
438                 globals->get_pilot_view()->set_pilot_offset(25.0, -25.0, 1.0);
439             }
440             fgReshape( globals->get_current_view()->get_winWidth(),
441                        globals->get_current_view()->get_winHeight() );
442             return;
443         case 120: // x key
444             fov = globals->get_options()->get_fov();
445             fov /= 1.05;
446             if ( fov < FG_FOV_MIN ) {
447                 fov = FG_FOV_MIN;
448             }
449             globals->get_options()->set_fov(fov);
450             v->force_update_fov_math();
451             return;
452         case 122: // z key
453 #ifndef FG_OLD_WEATHER
454             tmp = WeatherDatabase->getWeatherVisibility();
455             tmp *= 1.10;
456             WeatherDatabase->setWeatherVisibility( tmp );
457 #else
458             tmp = current_weather.get_visibility();   // in meters
459             tmp *= 1.10;
460             current_weather.set_visibility( tmp );
461 #endif
462             return;
463         case 27: // ESC
464             // if( fg_DebugOutput ) {
465             //   fclose( fg_DebugOutput );
466             // }
467             FG_LOG( FG_INPUT, FG_ALERT, 
468                     "Program exit requested." );
469             ConfirmExitDialog();
470             return;
471         }
472     }
473 }
474
475
476 // Handle "special" keyboard events
477 void GLUTspecialkey(int k, int x, int y) {
478     FGViewer *v;
479
480     v = globals->get_current_view();
481
482     FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k );
483
484     if ( puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN) ) {
485         return;
486     }
487
488     if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
489         FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
490         switch (k) {
491         case GLUT_KEY_F1: {
492             ifstream input("fgfs.sav");
493             if (input.good() && fgLoadFlight(input)) {
494                 input.close();
495                 FG_LOG(FG_INPUT, FG_INFO, "Restored flight from fgfs.sav");
496             } else {
497                 FG_LOG(FG_INPUT, FG_ALERT, "Cannot load flight from fgfs.sav");
498             }
499             return;
500         }
501         case GLUT_KEY_F2: {
502             FG_LOG(FG_INPUT, FG_INFO, "Saving flight");
503             ofstream output("fgfs.sav");
504             if (output.good() && fgSaveFlight(output)) {
505                 output.close();
506                 FG_LOG(FG_INPUT, FG_INFO, "Saved flight to fgfs.sav");
507             } else {
508                 FG_LOG(FG_INPUT, FG_ALERT, "Cannot save flight to fgfs.sav");
509             }
510             return;
511         }
512         case GLUT_KEY_F3: {
513           string panel_path =
514             current_properties.getStringValue("/sim/panel/path",
515                                               "Panels/Default/default.xml");
516           FGPanel * new_panel = fgReadPanel(panel_path);
517           if (new_panel == 0) {
518             FG_LOG(FG_INPUT, FG_ALERT,
519                    "Error reading new panel from " << panel_path);
520             return;
521           }
522           FG_LOG(FG_INPUT, FG_INFO, "Loaded new panel from " << panel_path);
523           delete current_panel;
524           current_panel = new_panel;
525           return;
526         }
527         case GLUT_KEY_F4: {
528           FGPath props_path(globals->get_options()->get_fg_root());
529           props_path.append("preferences.xml");
530           FG_LOG(FG_INPUT, FG_INFO, "Rereading global preferences");
531           if (!readPropertyList(props_path.str(), &current_properties)) {
532             FG_LOG(FG_INPUT, FG_ALERT,
533                    "Failed to reread global preferences from "
534                    << props_path.str());
535           } else {
536             FG_LOG(FG_INPUT, FG_INFO, "Finished Reading global preferences");
537           }
538           return;
539         }
540         case GLUT_KEY_F5: {
541           current_panel->setYOffset(current_panel->getYOffset() - 5);
542           fgReshape(globals->get_current_view()->get_winWidth(),
543                     globals->get_current_view()->get_winHeight());
544           return;
545         }
546         case GLUT_KEY_F6: {
547           current_panel->setYOffset(current_panel->getYOffset() + 5);
548           fgReshape(globals->get_current_view()->get_winWidth(),
549                     globals->get_current_view()->get_winHeight());
550           return;
551         }
552         case GLUT_KEY_F7: {
553           current_panel->setXOffset(current_panel->getXOffset() - 5);
554           return;
555         }
556         case GLUT_KEY_F8: {
557           current_panel->setXOffset(current_panel->getXOffset() + 5);
558           return;
559         }
560         case GLUT_KEY_END: // numeric keypad 1
561             v->set_goal_view_offset( FG_PI * 0.75 );
562             if ( globals->get_options()->get_view_mode() ==
563                  FGOptions::FG_VIEW_FOLLOW)
564             {
565                 globals->get_pilot_view()->set_pilot_offset(-25.0, 25.0, 1.0);
566                 v->set_view_offset( FG_PI * 0.75 );
567             }
568             return;
569         case GLUT_KEY_DOWN: // numeric keypad 2
570             v->set_goal_view_offset( FG_PI );
571             if ( globals->get_options()->get_view_mode() ==
572                  FGOptions::FG_VIEW_FOLLOW )
573             {
574                 globals->get_pilot_view()->set_pilot_offset(-25.0, 0.0, 1.0);
575                 v->set_view_offset( FG_PI );
576             }
577             return;
578         case GLUT_KEY_PAGE_DOWN: // numeric keypad 3
579             v->set_goal_view_offset( FG_PI * 1.25 );
580             if ( globals->get_options()->get_view_mode() ==
581                  FGOptions::FG_VIEW_FOLLOW)
582             {
583                 globals->get_pilot_view()->set_pilot_offset(-25.0, -25.0, 1.0);
584                 v->set_view_offset( FG_PI * 1.25 );
585             }
586             return;
587         case GLUT_KEY_LEFT: // numeric keypad 4
588             v->set_goal_view_offset( FG_PI * 0.50 );
589             if ( globals->get_options()->get_view_mode() ==
590                  FGOptions::FG_VIEW_FOLLOW )
591             {
592                 globals->get_pilot_view()->set_pilot_offset(0.0, 25.0, 1.0);
593                 v->set_view_offset( FG_PI * 0.50 );
594             }
595             return;
596         case GLUT_KEY_RIGHT: // numeric keypad 6
597             v->set_goal_view_offset( FG_PI * 1.50 );
598             if ( globals->get_options()->get_view_mode() ==
599                  FGOptions::FG_VIEW_FOLLOW )
600             {
601                 globals->get_pilot_view()->set_pilot_offset(0.0, -25.0, 1.0);
602                 v->set_view_offset( FG_PI * 1.50 );
603             }
604             return;
605         case GLUT_KEY_HOME: // numeric keypad 7
606             v->set_goal_view_offset( FG_PI * 0.25 );
607             if ( globals->get_options()->get_view_mode() ==
608                  FGOptions::FG_VIEW_FOLLOW )
609             {
610                 globals->get_pilot_view()->set_pilot_offset(25.0, 25.0, 1.0);
611                 v->set_view_offset( FG_PI * 0.25 );
612             }
613             return;
614         case GLUT_KEY_UP: // numeric keypad 8
615             v->set_goal_view_offset( 0.00 );
616             if ( globals->get_options()->get_view_mode() ==
617                  FGOptions::FG_VIEW_FOLLOW )
618             {
619                 globals->get_pilot_view()->set_pilot_offset(25.0, 0.0, 1.0);
620                 v->set_view_offset( 0.00 );
621             }
622             return;
623         case GLUT_KEY_PAGE_UP: // numeric keypad 9
624             v->set_goal_view_offset( FG_PI * 1.75 );
625             if ( globals->get_options()->get_view_mode() ==
626                  FGOptions::FG_VIEW_FOLLOW )
627             {
628                 globals->get_pilot_view()->set_pilot_offset(25.0, -25.0, 1.0);
629                 v->set_view_offset( FG_PI * 1.75 );
630             }
631             return;
632         }
633     } else {
634         FG_LOG( FG_INPUT, FG_DEBUG, "" );
635         switch (k) {
636         case GLUT_KEY_F2: // F2 Reload Tile Cache...
637             {
638                 bool freeze;
639                 FG_LOG(FG_INPUT, FG_INFO, "ReIniting TileCache");
640                 if ( !freeze ) 
641                     globals->set_freeze( true );
642                 BusyCursor(0);
643                 if ( global_tile_mgr.init() ) {
644                     // Load the local scenery data
645                     global_tile_mgr.update( 
646                         cur_fdm_state->get_Longitude() * RAD_TO_DEG,
647                         cur_fdm_state->get_Latitude() * RAD_TO_DEG );
648                 } else {
649                     FG_LOG( FG_GENERAL, FG_ALERT, 
650                             "Error in Tile Manager initialization!" );
651                     exit(-1);
652                 }
653                 BusyCursor(1);
654                 if ( !freeze )
655                    globals->set_freeze( false );
656                 return;
657             }
658         case GLUT_KEY_F3: // F3 Take a screen shot
659             fgDumpSnapShot();
660             return;
661         case GLUT_KEY_F6: // F6 toggles Autopilot target location
662             if ( current_autopilot->get_HeadingMode() !=
663                  FGAutopilot::FG_HEADING_WAYPOINT ) {
664                 current_autopilot->set_HeadingMode(
665                     FGAutopilot::FG_HEADING_WAYPOINT );
666                 current_autopilot->set_HeadingEnabled( true );
667             } else {
668                 current_autopilot->set_HeadingMode(
669                     FGAutopilot::FG_HEADING_LOCK );
670             }
671             return;
672         case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
673             globals->get_options()->cycle_fog();
674         
675             if ( globals->get_options()->get_fog() ==
676                  FGOptions::FG_FOG_DISABLED )
677             {
678                 FG_LOG( FG_INPUT, FG_INFO, "Fog disabled" );
679             } else if ( globals->get_options()->get_fog() == 
680                         FGOptions::FG_FOG_FASTEST )
681             {
682                 FG_LOG( FG_INPUT, FG_INFO, 
683                         "Fog enabled, hint set to fastest" );
684             } else if ( globals->get_options()->get_fog() ==
685                         FGOptions::FG_FOG_NICEST )
686             {
687                 FG_LOG( FG_INPUT, FG_INFO,
688                         "Fog enabled, hint set to nicest" );
689             }
690
691             return;
692         case GLUT_KEY_F9: // F9 toggles textures on and off...
693             FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
694             if ( globals->get_options()->get_textures() ) {
695                 globals->get_options()->set_textures( false );
696                 material_lib.set_step( 1 );
697             } else {
698                 globals->get_options()->set_textures( true );
699                 material_lib.set_step( 0 );
700             }
701             return;
702         case GLUT_KEY_F10: // F10 toggles menu on and off...
703             FG_LOG(FG_INPUT, FG_INFO, "Invoking call back function");
704             guiToggleMenu();
705             return;
706         case GLUT_KEY_F11: // F11 Altitude Dialog.
707             FG_LOG(FG_INPUT, FG_INFO, "Invoking Altitude call back function");
708             NewAltitude( NULL );
709             return;
710         case GLUT_KEY_F12: // F12 Heading Dialog...
711             FG_LOG(FG_INPUT, FG_INFO, "Invoking Heading call back function");
712             NewHeading( NULL );
713             return;
714         case GLUT_KEY_UP:
715             if ( current_autopilot->get_AltitudeEnabled() ) {
716                 current_autopilot->AltitudeAdjust( -100 );
717             } else {
718                 controls.move_elevator(0.05);
719             }
720             return;
721         case GLUT_KEY_DOWN:
722             if ( current_autopilot->get_AltitudeEnabled() ) {
723                 current_autopilot->AltitudeAdjust( 100 );
724             } else {
725                 controls.move_elevator(-0.05);
726             }
727             return;
728         case GLUT_KEY_LEFT:
729             controls.move_aileron(-0.05);
730             return;
731         case GLUT_KEY_RIGHT:
732             controls.move_aileron(0.05);
733             return;
734         case GLUT_KEY_HOME: // numeric keypad 1
735             controls.move_elevator_trim(0.001);
736             return;
737         case GLUT_KEY_END: // numeric keypad 7
738             controls.move_elevator_trim(-0.001);
739             return;
740         case GLUT_KEY_INSERT: // numeric keypad Ins
741             if ( current_autopilot->get_HeadingEnabled() ) {
742                 current_autopilot->HeadingAdjust( -1 );
743             } else {
744                 controls.move_rudder(-0.05);
745             }
746             return;
747         case 13: // numeric keypad Enter
748             if ( current_autopilot->get_HeadingEnabled() ) {
749                 current_autopilot->HeadingAdjust( 1 );
750             } else {
751                 controls.move_rudder(0.05);
752             }
753             return;
754         case 53: // numeric keypad 5
755             controls.set_aileron(0.0);
756             controls.set_elevator(0.0);
757             controls.set_rudder(0.0);
758             return;
759         case GLUT_KEY_PAGE_UP: // numeric keypad 9 (Pg Up)
760             if ( current_autopilot->get_AutoThrottleEnabled() ) {
761                 current_autopilot->AutoThrottleAdjust( 5 );
762             } else {
763                 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
764             }
765             return;
766         case GLUT_KEY_PAGE_DOWN: // numeric keypad 3 (Pg Dn)
767             if ( current_autopilot->get_AutoThrottleEnabled() ) {
768                 current_autopilot->AutoThrottleAdjust( -5 );
769             } else {
770                 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );
771             }
772             return;
773         }
774     }
775 }
776
777