1 // GLUTkey.cxx -- handle GLUT keyboard events
3 // Written by Curtis Olson, started May 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
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.
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.
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.
35 #if defined(FX) && defined(XMESA)
42 #include <Debug/logstream.hxx>
43 #include <Aircraft/aircraft.hxx>
44 #include <Astro/solarsystem.hxx>
45 #include <Astro/sky.hxx>
46 #include <Autopilot/autopilot.hxx>
47 #include <Cockpit/hud.hxx>
49 #include <Include/fg_constants.h>
50 #include <Scenery/tilemgr.hxx>
51 #include <Objects/materialmgr.hxx>
53 #include <Time/fg_time.hxx>
54 #include <Time/light.hxx>
55 #include <Weather/weather.hxx>
57 #include "GLUTkey.hxx"
58 #include "options.hxx"
61 extern void NewAltitude( puObject *cb );
62 extern void NewHeading( puObject *cb );
64 // Force an update of the sky and lighting parameters
65 static void local_update_sky_and_lighting_params( void ) {
67 SolarSystem::theSolarSystem->rebuild();
68 cur_light_params.Update();
73 // Handle keyboard events
74 void GLUTkey(unsigned char k, int x, int y) {
80 static bool winding_ccw = true;
82 f = current_aircraft.fdm_state;
83 t = FGTime::cur_time_params;
87 FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
88 if ( puKeyboard(k, PU_DOWN) ) {
92 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
93 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
101 case 18: // Ctrl-R key
103 winding_ccw = !winding_ccw;
105 glFrontFace ( GL_CCW );
107 glFrontFace ( GL_CW );
110 case 19: // Ctrl-S key
111 fgAPToggleAutoThrottle();
113 case 20: // Ctrl-T key
114 fgAPToggleTerrainFollow();
116 case 49: // numeric keypad 1
117 v->set_goal_view_offset( FG_PI * 0.75 );
119 case 50: // numeric keypad 2
120 v->set_goal_view_offset( FG_PI );
122 case 51: // numeric keypad 3
123 v->set_goal_view_offset( FG_PI * 1.25 );
125 case 52: // numeric keypad 4
126 v->set_goal_view_offset( FG_PI * 0.50 );
128 case 54: // numeric keypad 6
129 v->set_goal_view_offset( FG_PI * 1.50 );
131 case 55: // numeric keypad 7
132 v->set_goal_view_offset( FG_PI * 0.25 );
134 case 56: // numeric keypad 8
135 v->set_goal_view_offset( 0.00 );
137 case 57: // numeric keypad 9
138 v->set_goal_view_offset( FG_PI * 1.75 );
141 // status = current_options.get_hud_status();
142 // current_options.set_hud_status(!status);
143 HUD_brightkey( true );
147 fgHUDInit2(¤t_aircraft);
151 local_update_sky_and_lighting_params();
154 current_options.toggle_panel();
157 t->adjust_warp_delta(-30);
158 local_update_sky_and_lighting_params();
161 #if defined(FX) && !defined(WIN32)
162 global_fullscreen = ( !global_fullscreen );
163 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
164 XMesaSetFXmode( global_fullscreen ?
165 XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
170 fov = current_options.get_fov();
172 if ( fov > FG_FOV_MAX ) {
175 current_options.set_fov(fov);
176 v->force_update_fov_math();
179 tmp = w->get_visibility(); // in meters
181 w->set_visibility( tmp );
185 FG_LOG( FG_INPUT, FG_DEBUG, "" );
187 case 50: // numeric keypad 2
188 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
189 fgAPAltitudeAdjust( 100 );
191 controls.move_elevator(-0.05);
194 case 56: // numeric keypad 8
195 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
196 fgAPAltitudeAdjust( -100 );
198 controls.move_elevator(0.05);
201 case 49: // numeric keypad 1
202 controls.move_elevator_trim(-0.001);
204 case 55: // numeric keypad 7
205 controls.move_elevator_trim(0.001);
207 case 52: // numeric keypad 4
208 controls.move_aileron(-0.05);
210 case 54: // numeric keypad 6
211 controls.move_aileron(0.05);
213 case 48: // numeric keypad Ins
214 if( fgAPHeadingEnabled() ) {
215 fgAPHeadingAdjust( -1 );
217 controls.move_rudder(-0.05);
220 case 13: // numeric keypad Enter
221 if( fgAPHeadingEnabled() ) {
222 fgAPHeadingAdjust( 1 );
224 controls.move_rudder(0.05);
227 case 53: // numeric keypad 5
228 controls.set_aileron(0.0);
229 controls.set_elevator(0.0);
230 controls.set_rudder(0.0);
232 case 57: // numeric keypad 9 (Pg Up)
233 if( fgAPAutoThrottleEnabled() ) {
234 fgAPAutoThrottleAdjust( 5 );
236 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
239 case 51: // numeric keypad 3 (Pg Dn)
240 if( fgAPAutoThrottleEnabled() ) {
241 fgAPAutoThrottleAdjust( -5 );
243 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );
249 b_ret = int( controls.get_brake( 0 ) );
250 b_set = double(!b_ret);
251 controls.set_brake( FGControls::ALL_WHEELS, b_set);
254 HUD_brightkey( false );
257 fgHUDInit(¤t_aircraft); // normal HUD
260 t->adjust_warp (+60);
261 local_update_sky_and_lighting_params();
264 t->togglePauseMode();
265 // printf position and attitude information
266 FG_LOG( FG_INPUT, FG_INFO,
267 "Lon = " << f->get_Longitude() * RAD_TO_DEG
268 << " Lat = " << f->get_Latitude() * RAD_TO_DEG
269 << " Altitude = " << f->get_Altitude() * FEET_TO_METER );
270 FG_LOG( FG_INPUT, FG_INFO,
271 "Heading = " << f->get_Psi() * RAD_TO_DEG
272 << " Roll = " << f->get_Phi() * RAD_TO_DEG
273 << " Pitch = " << f->get_Theta() * RAD_TO_DEG );
276 t->adjust_warp_delta (+30);
277 local_update_sky_and_lighting_params();
280 fov = current_options.get_fov();
282 if ( fov < FG_FOV_MIN ) {
285 current_options.set_fov(fov);
286 v->force_update_fov_math();
289 tmp = w->get_visibility(); // in meters
291 w->set_visibility( tmp );
294 // if( fg_DebugOutput ) {
295 // fclose( fg_DebugOutput );
297 FG_LOG( FG_INPUT, FG_ALERT,
298 "Program exiting normally at user request." );
306 // Handle "special" keyboard events
307 void GLUTspecialkey(int k, int x, int y) {
312 FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k );
314 if ( puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN) ) {
318 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
319 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
321 case GLUT_KEY_END: // numeric keypad 1
322 v->set_goal_view_offset( FG_PI * 0.75 );
324 case GLUT_KEY_DOWN: // numeric keypad 2
325 v->set_goal_view_offset( FG_PI );
327 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3
328 v->set_goal_view_offset( FG_PI * 1.25 );
330 case GLUT_KEY_LEFT: // numeric keypad 4
331 v->set_goal_view_offset( FG_PI * 0.50 );
333 case GLUT_KEY_RIGHT: // numeric keypad 6
334 v->set_goal_view_offset( FG_PI * 1.50 );
336 case GLUT_KEY_HOME: // numeric keypad 7
337 v->set_goal_view_offset( FG_PI * 0.25 );
339 case GLUT_KEY_UP: // numeric keypad 8
340 v->set_goal_view_offset( 0.00 );
342 case GLUT_KEY_PAGE_UP: // numeric keypad 9
343 v->set_goal_view_offset( FG_PI * 1.75 );
347 FG_LOG( FG_INPUT, FG_DEBUG, "" );
349 case GLUT_KEY_F2: // F2 Reload Tile Cache...
352 FG_LOG(FG_INPUT, FG_INFO, "ReIniting TileCache");
353 FGTime *t = FGTime::cur_time_params;
354 if( (toggle_pause = !t->getPause()) )
355 t->togglePauseMode();
357 if( global_tile_mgr.init() ) {
358 // Load the local scenery data
359 global_tile_mgr.update();
361 FG_LOG( FG_GENERAL, FG_ALERT,
362 "Error in Tile Manager initialization!" );
367 t->togglePauseMode();
370 case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
371 current_options.cycle_fog();
373 if ( current_options.get_fog() == fgOPTIONS::FG_FOG_DISABLED ) {
374 FG_LOG( FG_INPUT, FG_INFO, "Fog disabled" );
375 } else if ( current_options.get_fog() ==
376 fgOPTIONS::FG_FOG_FASTEST )
378 FG_LOG( FG_INPUT, FG_INFO,
379 "Fog enabled, hint set to fastest" );
380 } else if ( current_options.get_fog() ==
381 fgOPTIONS::FG_FOG_NICEST )
383 FG_LOG( FG_INPUT, FG_INFO,
384 "Fog enabled, hint set to nicest" );
388 case GLUT_KEY_F9: // F9 toggles textures on and off...
389 if ( material_mgr.loaded() ) {
390 current_options.get_textures() ?
391 current_options.set_textures(false) :
392 current_options.set_textures(true);
393 FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
395 FG_LOG( FG_INPUT, FG_INFO,
396 "No textures loaded, cannot toggle" );
399 case GLUT_KEY_F10: // F10 toggles menu on and off...
400 FG_LOG(FG_INPUT, FG_INFO, "Invoking call back function");
403 case GLUT_KEY_F11: // F11 Altitude Dialog.
404 FG_LOG(FG_INPUT, FG_INFO, "Invoking Altitude call back function");
407 case GLUT_KEY_F12: // F12 Heading Dialog...
408 FG_LOG(FG_INPUT, FG_INFO, "Invoking Heading call back function");
412 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
413 fgAPAltitudeAdjust( -100 );
415 controls.move_elevator(0.05);
419 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
420 fgAPAltitudeAdjust( 100 );
422 controls.move_elevator(-0.05);
426 controls.move_aileron(-0.05);
429 controls.move_aileron(0.05);
431 case GLUT_KEY_HOME: // numeric keypad 1
432 controls.move_elevator_trim(0.001);
434 case GLUT_KEY_END: // numeric keypad 7
435 controls.move_elevator_trim(-0.001);
437 case GLUT_KEY_INSERT: // numeric keypad Ins
438 if( fgAPHeadingEnabled() ) {
439 fgAPHeadingAdjust( -1 );
441 controls.move_rudder(-0.05);
444 case 13: // numeric keypad Enter
445 if( fgAPHeadingEnabled() ) {
446 fgAPHeadingAdjust( 1 );
448 controls.move_rudder(0.05);
451 case 53: // numeric keypad 5
452 controls.set_aileron(0.0);
453 controls.set_elevator(0.0);
454 controls.set_rudder(0.0);
456 case GLUT_KEY_PAGE_UP: // numeric keypad 9 (Pg Up)
457 if( fgAPAutoThrottleEnabled() ) {
458 fgAPAutoThrottleAdjust( 5 );
460 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
463 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3 (Pg Dn)
464 if( fgAPAutoThrottleEnabled() ) {
465 fgAPAutoThrottleAdjust( -5 );
467 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );