From: curt Date: Wed, 13 May 1998 18:29:56 +0000 (+0000) Subject: Added a keyboard binding to dynamically adjust field of view. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c57071acfd540f3c329991f86854ec825567e5be;p=flightgear.git Added a keyboard binding to dynamically adjust field of view. Added a command line option to specify fov. Adjusted terrain color. Root path info moved to fgOPTIONS. Added ability to parse options out of a config file. --- diff --git a/Main/GLUTkey.cxx b/Main/GLUTkey.cxx index a542b685b..3b1e27d8f 100644 --- a/Main/GLUTkey.cxx +++ b/Main/GLUTkey.cxx @@ -106,6 +106,9 @@ void GLUTkey(unsigned char k, int x, int y) { case 87: /* W key */ displayInstruments = !displayInstruments; return; + case 88: /* X key */ + o->fov *= 1.05; + return; case 90: /* Z key */ w->visibility /= 1.10; xglFogf (GL_FOG_START, w->visibility / 1000000.0 ); @@ -168,6 +171,9 @@ void GLUTkey(unsigned char k, int x, int y) { case 116: /* t key */ t->warp_delta += 30; return; + case 120: /* X key */ + o->fov /= 1.05; + return; case 122: /* z key */ w->visibility *= 1.10; xglFogf (GL_FOG_START, w->visibility / 1000000.0 ); @@ -179,7 +185,8 @@ void GLUTkey(unsigned char k, int x, int y) { // if( fg_DebugOutput ) { // fclose( fg_DebugOutput ); // } - exit(0); + fgPrintf( FG_INPUT, FG_EXIT, + "Program exiting normally at user request.\n"); } } } @@ -267,12 +274,19 @@ void GLUTspecialkey(int k, int x, int y) { /* $Log$ -/* Revision 1.7 1998/05/07 23:14:14 curt -/* Added "D" key binding to set autopilot heading. -/* Made frame rate calculation average out over last 10 frames. -/* Borland C++ floating point exception workaround. -/* Added a --tile-radius=n option. +/* Revision 1.8 1998/05/13 18:29:56 curt +/* Added a keyboard binding to dynamically adjust field of view. +/* Added a command line option to specify fov. +/* Adjusted terrain color. +/* Root path info moved to fgOPTIONS. +/* Added ability to parse options out of a config file. /* + * Revision 1.7 1998/05/07 23:14:14 curt + * Added "D" key binding to set autopilot heading. + * Made frame rate calculation average out over last 10 frames. + * Borland C++ floating point exception workaround. + * Added a --tile-radius=n option. + * * Revision 1.6 1998/04/28 01:20:20 curt * Type-ified fgTIME and fgVIEW. * Added a command line option to disable textures. diff --git a/Main/GLUTmain.cxx b/Main/GLUTmain.cxx index 95d501ede..1a896331f 100644 --- a/Main/GLUTmain.cxx +++ b/Main/GLUTmain.cxx @@ -225,10 +225,12 @@ static void fgInitVisuals( void ) { static void fgUpdateViewParams( void ) { fgFLIGHT *f; fgLIGHT *l; + fgOPTIONS *o; fgVIEW *v; f = current_aircraft.flight; l = &cur_light_params; + o = ¤t_options; v = ¤t_view; fgViewUpdate(f, v, l); @@ -239,13 +241,13 @@ static void fgUpdateViewParams( void ) { // Tell GL we are about to modify the projection parameters xglMatrixMode(GL_PROJECTION); xglLoadIdentity(); - gluPerspective(65.0, 2.0/win_ratio, 1.0, 100000.0); + gluPerspective(o->fov, 2.0/win_ratio, 1.0, 100000.0); } else { xglViewport(0, 0 , (GLint)winWidth, (GLint) winHeight); // Tell GL we are about to modify the projection parameters xglMatrixMode(GL_PROJECTION); xglLoadIdentity(); - gluPerspective(65.0, 1.0/win_ratio, 10.0, 100000.0); + gluPerspective(o->fov, 1.0/win_ratio, 10.0, 100000.0); } xglMatrixMode(GL_MODELVIEW); @@ -332,8 +334,8 @@ static void fgRenderFrame( void ) { double angle; GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; - GLfloat color[4] = { 0.54, 0.44, 0.29, 1.0 }; - + GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 }; + l = &cur_light_params; o = ¤t_options; t = &cur_time_params; @@ -425,8 +427,8 @@ static void fgRenderFrame( void ) { xglMaterialfv (GL_FRONT, GL_DIFFUSE, white); } else { xglDisable( GL_TEXTURE_2D ); - xglMaterialfv (GL_FRONT, GL_AMBIENT, color); - xglMaterialfv (GL_FRONT, GL_DIFFUSE, color); + xglMaterialfv (GL_FRONT, GL_AMBIENT, terrain_color); + xglMaterialfv (GL_FRONT, GL_DIFFUSE, terrain_color); } fgTileMgrRender(); @@ -675,9 +677,12 @@ int fgGlutInitEvents( void ) { // Main ... int main( int argc, char **argv ) { fgFLIGHT *f; + fgOPTIONS *o; + char config[256]; int result; // Used in command line argument. f = current_aircraft.flight; + o = ¤t_options; #ifdef HAVE_BC5PLUS _control87(MCW_EM, MCW_EM); /* defined in float.h */ @@ -693,14 +698,27 @@ int main( int argc, char **argv ) { fgPrintf( FG_GENERAL, FG_EXIT, "GLUT initialization failed ...\n" ); } - // Parse remaining command line options - result = current_options.parse(argc, argv); + // Attempt to locate and parse a config file + // First check fg_root + strcpy(config, o->fg_root); + strcat(config, "/system.fgfsrc"); + result = o->parse_config_file(config); + + // Next check home directory + if ( getenv("HOME") != NULL ) { + strcpy(config, getenv("HOME")); + strcat(config, "/.fgfsrc"); + result = o->parse_config_file(config); + } + // Parse remaining command line options + // These will override anything specified in a config file + result = o->parse_command_line(argc, argv); if ( result != FG_OPTIONS_OK ) { // Something must have gone horribly wrong with the command // line parsing or maybe the user just requested help ... :-) - current_options.usage(); - fgPrintf( FG_GENERAL, FG_EXIT, "\nShutting down ...\n"); + o->usage(); + fgPrintf( FG_GENERAL, FG_EXIT, "\nExiting ...\n"); } // These are a few miscellaneous things that aren't really @@ -750,6 +768,13 @@ extern "C" { // $Log$ +// Revision 1.14 1998/05/13 18:29:57 curt +// Added a keyboard binding to dynamically adjust field of view. +// Added a command line option to specify fov. +// Adjusted terrain color. +// Root path info moved to fgOPTIONS. +// Added ability to parse options out of a config file. +// // Revision 1.13 1998/05/11 18:18:15 curt // For flat shading use "glHint (GL_FOG_HINT, GL_FASTEST )" // diff --git a/Main/fg_init.cxx b/Main/fg_init.cxx index 9dd947301..133689ef7 100644 --- a/Main/fg_init.cxx +++ b/Main/fg_init.cxx @@ -169,26 +169,23 @@ int fgInitPosition( void ) { // General house keeping initializations int fgInitGeneral( void ) { fgGENERAL *g; + fgOPTIONS *o; int i; g = &general; + o = ¤t_options; fgPrintf( FG_GENERAL, FG_INFO, "General Initialization\n" ); fgPrintf( FG_GENERAL, FG_INFO, "======= ==============\n" ); - // determine the fg root path. - if( !(g->root_dir) ) { - // If not set by command line test for environmental var.. - g->root_dir = getenv("FG_ROOT"); - if ( !g->root_dir ) { - // No root path set? Then assume, we will exit if this is - // wrong when looking for support files. - fgPrintf( FG_GENERAL, FG_EXIT, "%s %s\n", - "Cannot continue without environment variable FG_ROOT", - "being defined."); - } + if ( !strlen(o->fg_root) ) { + // No root path set? Then assume, we will exit if this is + // wrong when looking for support files. + fgPrintf( FG_GENERAL, FG_EXIT, "%s %s\n", + "Cannot continue without environment variable FG_ROOT", + "being defined."); } - fgPrintf( FG_GENERAL, FG_INFO, "FG_ROOT = %s\n\n", g->root_dir); + fgPrintf( FG_GENERAL, FG_INFO, "FG_ROOT = %s\n\n", o->fg_root); // prime the frame rate counter pump for ( i = 0; i < FG_FRAME_RATE_HISTORY; i++ ) { @@ -387,6 +384,13 @@ int fgInitSubsystems( void ) { // $Log$ +// Revision 1.12 1998/05/13 18:29:58 curt +// Added a keyboard binding to dynamically adjust field of view. +// Added a command line option to specify fov. +// Adjusted terrain color. +// Root path info moved to fgOPTIONS. +// Added ability to parse options out of a config file. +// // Revision 1.11 1998/05/07 23:14:15 curt // Added "D" key binding to set autopilot heading. // Made frame rate calculation average out over last 10 frames. diff --git a/Main/options.cxx b/Main/options.cxx index 498e1a1c5..61eaf96f8 100644 --- a/Main/options.cxx +++ b/Main/options.cxx @@ -33,6 +33,7 @@ #include #include +#include #include "options.hxx" @@ -45,6 +46,24 @@ fgOPTIONS current_options; fgOPTIONS::fgOPTIONS( void ) { // set initial values/defaults + if ( getenv("FG_ROOT") != NULL ) { + // fg_root could be anywhere, so default to environmental + // variable $FG_ROOT if it is set. + + strcpy(fg_root, getenv("FG_ROOT")); + } else { + // Otherwise, default to a random compiled in location if + // $FG_ROOT is not set. This can still be overridden from the + // command line or a config file. + +#if defined(WIN32) + strcpy(fg_root, "\\FlightGear"); +#else + strcpy(fg_root, "/usr/local/lib/FlightGear"); +#endif + } + + // default airport id strcpy(airport_id, ""); // Features @@ -52,6 +71,7 @@ fgOPTIONS::fgOPTIONS( void ) { // Rendering options fog = 1; + fov = 65.0; fullscreen = 0; shading = 1; skyblend = 1; @@ -66,6 +86,52 @@ fgOPTIONS::fgOPTIONS( void ) { } +// Parse an int out of a --foo-bar=n type option +static int parse_int(char *arg) { + int result; + + // advance past the '=' + while ( (arg[0] != '=') && (arg[0] != '\0') ) { + arg++; + } + + if ( arg[0] == '=' ) { + arg++; + } + + printf("parse_int(): arg = %s\n", arg); + + result = atoi(arg); + + printf("parse_int(): result = %d\n", result); + + return(result); +} + + +// Parse an int out of a --foo-bar=n type option +static double parse_double(char *arg) { + double result; + + // advance past the '=' + while ( (arg[0] != '=') && (arg[0] != '\0') ) { + arg++; + } + + if ( arg[0] == '=' ) { + arg++; + } + + printf("parse_double(): arg = %s\n", arg); + + result = atof(arg); + + printf("parse_double(): result = %.4f\n", result); + + return(result); +} + + // parse time string in the form of [+-]hh:mm:ss, returns the value in seconds static double parse_time(char *time_str) { char num[256]; @@ -163,82 +229,118 @@ static int parse_time_offset(char *time_str) { } -// Parse an int out of a --foo-bar=n type option -static int parse_int(char *arg, int min, int max) { - int result; +// Parse --tile-radius=n type option - // advance past the '=' - while ( (arg[0] != '=') && (arg[0] != '\0') ) { - arg++; - } +#define FG_RADIUS_MIN 3 +#define FG_RADIUS_MAX 9 - if ( arg[0] == '=' ) { - arg++; +static int parse_tile_radius(char *arg) { + int radius, tmp; + + radius = parse_int(arg); + + // radius must be odd + tmp = radius / 2; + if ( radius == ( tmp * 2 ) ) { + radius -= 1; } - printf("parse_int(): arg = %s\n", arg); + if ( radius < FG_RADIUS_MIN ) { radius = FG_RADIUS_MIN; } + if ( radius > FG_RADIUS_MAX ) { radius = FG_RADIUS_MAX; } - result = atoi(arg); + printf("parse_tile_radius(): radius = %d\n", radius); - if ( result < min ) { result = min; } - if ( result > max ) { result = max; } + return(radius); +} - printf("parse_int(): result = %d\n", result); - return(result); + +// Parse --fov=x.xx type option + +#define FG_FOV_MIN 0.1 +#define FG_FOV_MAX 179.9 + +static double parse_fov(char *arg) { + double fov; + + fov = parse_double(arg); + + if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; } + if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; } + + printf("parse_fov(): result = %.4f\n", fov); + + return(fov); +} + + +// Parse a single option +int fgOPTIONS::parse_option( char *arg ) { + // General Options + if ( (strcmp(arg, "--help") == 0) || + (strcmp(arg, "-h") == 0) ) { + // help/usage request + return(FG_OPTIONS_HELP); + } else if ( strcmp(arg, "--disable-hud") == 0 ) { + hud_status = 0; + } else if ( strcmp(arg, "--enable-hud") == 0 ) { + hud_status = 1; + } else if ( strncmp(arg, "--airport-id=", 13) == 0 ) { + arg += 13; + strncpy(airport_id, arg, 4); + } else if ( strncmp(arg, "--fg-root=", 10) == 0 ) { + arg += 10; + strcpy(fg_root, arg); + } else if ( strcmp(arg, "--disable-fog") == 0 ) { + fog = 0; + } else if ( strcmp(arg, "--enable-fog") == 0 ) { + fog = 1; + } else if ( strncmp(arg, "--fov=", 6) == 0 ) { + fov = parse_fov(arg); + } else if ( strcmp(arg, "--disable-fullscreen") == 0 ) { + fullscreen = 0; + } else if ( strcmp(arg, "--enable-fullscreen") == 0 ) { + fullscreen = 1; + } else if ( strcmp(arg, "--shading-flat") == 0 ) { + shading = 0; + } else if ( strcmp(arg, "--shading-smooth") == 0 ) { + shading = 1; + } else if ( strcmp(arg, "--disable-skyblend") == 0 ) { + skyblend = 0; + } else if ( strcmp(arg, "--enable-skyblend") == 0 ) { + skyblend = 1; + } else if ( strcmp(arg, "--disable-textures") == 0 ) { + textures = 0; + } else if ( strcmp(arg, "--enable-textures") == 0 ) { + textures = 1; + } else if ( strcmp(arg, "--disable-wireframe") == 0 ) { + wireframe = 0; + } else if ( strcmp(arg, "--enable-wireframe") == 0 ) { + wireframe = 1; + } else if ( strncmp(arg, "--tile-radius=", 14) == 0 ) { + tile_radius = parse_tile_radius(arg); + } else if ( strncmp(arg, "--time-offset=", 14) == 0 ) { + time_offset = parse_time_offset(arg); + } else { + return(FG_OPTIONS_ERROR); + } + + return(FG_OPTIONS_OK); } // Parse the command line options -int fgOPTIONS::parse( int argc, char **argv ) { +int fgOPTIONS::parse_command_line( int argc, char **argv ) { int i = 1; + int result; - fgPrintf(FG_GENERAL, FG_INFO, "Processing arguments\n"); + fgPrintf(FG_GENERAL, FG_INFO, "Processing command line arguments\n"); while ( i < argc ) { fgPrintf(FG_GENERAL, FG_INFO, "argv[%d] = %s\n", i, argv[i]); - // General Options - if ( (strcmp(argv[i], "--help") == 0) || - (strcmp(argv[i], "-h") == 0) ) { - // help/usage request - return(FG_OPTIONS_HELP); - } else if ( strcmp(argv[i], "--disable-hud") == 0 ) { - hud_status = 0; - } else if ( strcmp(argv[i], "--enable-hud") == 0 ) { - hud_status = 1; - } else if ( strncmp(argv[i], "--airport-id=", 13) == 0 ) { - argv[i] += 13; - strncpy(airport_id, argv[i], 4); - } else if ( strcmp(argv[i], "--disable-fog") == 0 ) { - fog = 0; - } else if ( strcmp(argv[i], "--enable-fog") == 0 ) { - fog = 1; - } else if ( strcmp(argv[i], "--disable-fullscreen") == 0 ) { - fullscreen = 0; - } else if ( strcmp(argv[i], "--enable-fullscreen") == 0 ) { - fullscreen = 1; - } else if ( strcmp(argv[i], "--shading-flat") == 0 ) { - shading = 0; - } else if ( strcmp(argv[i], "--shading-smooth") == 0 ) { - shading = 1; - } else if ( strcmp(argv[i], "--disable-skyblend") == 0 ) { - skyblend = 0; - } else if ( strcmp(argv[i], "--enable-skyblend") == 0 ) { - skyblend = 1; - } else if ( strcmp(argv[i], "--disable-textures") == 0 ) { - textures = 0; - } else if ( strcmp(argv[i], "--enable-textures") == 0 ) { - textures = 1; - } else if ( strcmp(argv[i], "--disable-wireframe") == 0 ) { - wireframe = 0; - } else if ( strcmp(argv[i], "--enable-wireframe") == 0 ) { - wireframe = 1; - } else if ( strncmp(argv[i], "--tile-radius=", 14) == 0 ) { - tile_radius = parse_int(argv[i], 3, 9); - } else if ( strncmp(argv[i], "--time-offset=", 14) == 0 ) { - time_offset = parse_time_offset(argv[i]); - } else { - return(FG_OPTIONS_ERROR); + result = parse_option(argv[i]); + if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) { + return(result); } i++; @@ -248,6 +350,44 @@ int fgOPTIONS::parse( int argc, char **argv ) { } +// Parse the command line options +int fgOPTIONS::parse_config_file( char *path ) { + char fgpath[256], line[256]; + fgFile f; + int len, result; + + strcpy(fgpath, path); + strcat(fgpath, ".gz"); + + // first try "path.gz" + if ( (f = fgopen(fgpath, "rb")) == NULL ) { + // next try "path" + if ( (f = fgopen(path, "rb")) == NULL ) { + return(FG_OPTIONS_ERROR); + } + } + + fgPrintf(FG_GENERAL, FG_INFO, "Processing config file: %s\n", path); + + while ( fggets(f, line, 250) != NULL ) { + // strip trailing newline if it exists + len = strlen(line); + if ( line[len-1] == '\n' ) { + line[len-1] = '\0'; + } + + result = parse_option(line); + if ( result == FG_OPTIONS_ERROR ) { + fgPrintf( FG_GENERAL, FG_EXIT, + "Config file parse error: %s '%s'\n", path, line ); + } + } + + fgclose(f); + return(FG_OPTIONS_OK); +} + + // Print usage message void fgOPTIONS::usage ( void ) { printf("Usage: fg [ options ... ]\n"); @@ -255,6 +395,7 @@ void fgOPTIONS::usage ( void ) { printf("General Options:\n"); printf("\t--help -h: print usage\n"); + printf("\t--fg-root=path: specify the root path for all the data files\n"); printf("\n"); printf("Features:\n"); @@ -269,6 +410,7 @@ void fgOPTIONS::usage ( void ) { printf("Rendering Options:\n"); printf("\t--disable-fog: disable fog/haze\n"); printf("\t--enable-fog: enable fog/haze\n"); + printf("\t--fov=xx.x: specify the field of view angle in degrees\n"); printf("\t--disable-fullscreen: disable fullscreen mode\n"); printf("\t--enable-fullscreen: enable fullscreen mode\n"); printf("\t--shading-flat: enable flat shading\n"); @@ -296,6 +438,13 @@ fgOPTIONS::~fgOPTIONS( void ) { // $Log$ +// Revision 1.9 1998/05/13 18:29:59 curt +// Added a keyboard binding to dynamically adjust field of view. +// Added a command line option to specify fov. +// Adjusted terrain color. +// Root path info moved to fgOPTIONS. +// Added ability to parse options out of a config file. +// // Revision 1.8 1998/05/07 23:14:16 curt // Added "D" key binding to set autopilot heading. // Made frame rate calculation average out over last 10 frames. diff --git a/Main/options.hxx b/Main/options.hxx index e455c1761..1ed98a66b 100644 --- a/Main/options.hxx +++ b/Main/options.hxx @@ -40,6 +40,8 @@ class fgOPTIONS { public: + // The flight gear "root" directory + char fg_root[256]; // ID of initial starting airport char airport_id[5]; @@ -49,6 +51,7 @@ public: // Rendering options int fog; // Fog enabled/disabled + double fov; // Field of View int fullscreen; // Full screen mode enabled/disabled int shading; // shading method, 0 = Flat, 1 = Smooth int skyblend; // Blend sky to haze (using polygons) or just clear @@ -67,8 +70,14 @@ public: // Constructor fgOPTIONS( void ); + // Parse a single option + int parse_option( char *arg ); + + // Parse the command line options + int parse_command_line( int argc, char **argv ); + // Parse the command line options - int parse( int argc, char **argv ); + int parse_config_file( char *path ); // Print usage message void usage ( void ); @@ -86,6 +95,13 @@ extern fgOPTIONS current_options; // $Log$ +// Revision 1.7 1998/05/13 18:29:59 curt +// Added a keyboard binding to dynamically adjust field of view. +// Added a command line option to specify fov. +// Adjusted terrain color. +// Root path info moved to fgOPTIONS. +// Added ability to parse options out of a config file. +// // Revision 1.6 1998/05/06 03:16:26 curt // Added an averaged global frame rate counter. // Added an option to control tile radius.