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