X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Fmain.cxx;h=05414d4cd278dfd4b3cbc2e0556dee7229c19fba;hb=a6e0a696376ba2d426eb534bb83ec42038a501e7;hp=d669b9072b67a97de5b4f40d99084ca9b02af574;hpb=eccd695f91f8c6c2dae63c3a96382e0a00772306;p=flightgear.git diff --git a/src/Main/main.cxx b/src/Main/main.cxx index d669b9072..05414d4cd 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -25,7 +25,7 @@ # include #endif -#ifdef FG_MATH_EXCEPTION_CLASH +#ifdef SG_MATH_EXCEPTION_CLASH # include #endif @@ -35,7 +35,7 @@ #endif #include -#include +#include #include #include @@ -53,6 +53,10 @@ # include // for stat() #endif +// #ifdef HAVE_LIBX11 +// # include +// #endif + #include #include @@ -60,7 +64,7 @@ #include #include #include -#include +#include #include #include #include @@ -81,6 +85,7 @@ #ifdef FG_NETWORK_OLK #include #endif +#include #include #include #ifdef ENABLE_AUDIO_SUPPORT @@ -95,7 +100,7 @@ // begin - added Venky // $$$ begin - added VS Renganathan -#include +#include #include #include void fgLoadDCS (void); @@ -335,7 +340,7 @@ void fgRenderFrame( void ) { // now work without seg faulting the system. // printf("Ground = %.2f Altitude = %.2f\n", scenery.cur_elev, - // FG_Altitude * FEET_TO_METER); + // FG_Altitude * SG_FEET_TO_METER); // this is just a temporary hack, to make me understand Pui // timerText -> setLabel (ctime (&t->cur_time)); @@ -352,10 +357,10 @@ void fgRenderFrame( void ) { pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Lat_geocentric(), cur_fdm_state->get_Altitude() * - FEET_TO_METER ); + SG_FEET_TO_METER ); pilot_view->set_sea_level_radius( cur_fdm_state-> get_Sea_level_radius() * - FEET_TO_METER ); + SG_FEET_TO_METER ); pilot_view->set_rph( cur_fdm_state->get_Phi(), cur_fdm_state->get_Theta(), cur_fdm_state->get_Psi() ); @@ -365,12 +370,12 @@ void fgRenderFrame( void ) { sgVec3 po; // chase view pilot_offset sgVec3 wup; // chase view world up - sgSetVec3( po, 0.0, 0.0, 50.0 ); + sgSetVec3( po, 0.0, 0.0, 100.0 ); sgCopyVec3( wup, pilot_view->get_world_up() ); sgMat4 CXFM; // chase view + pilot offset xform sgMakeRotMat4( CXFM, - chase_view->get_view_offset() * RAD_TO_DEG - - cur_fdm_state->get_Psi() * RAD_TO_DEG, + chase_view->get_view_offset() * SGD_RADIANS_TO_DEGREES - + cur_fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES, wup ); sgVec3 npo; // new pilot offset after rotation sgVec3 *pPO = PilotOffsetGet(); @@ -380,10 +385,10 @@ void fgRenderFrame( void ) { chase_view->set_geod_view_pos( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Lat_geocentric(), cur_fdm_state->get_Altitude() * - FEET_TO_METER ); + SG_FEET_TO_METER ); chase_view->set_sea_level_radius( cur_fdm_state-> get_Sea_level_radius() * - FEET_TO_METER ); + SG_FEET_TO_METER ); chase_view->set_pilot_offset( npo[0], npo[1], npo[2] ); chase_view->set_view_forward( pilot_view->get_view_pos() ); chase_view->set_view_up( wup ); @@ -476,7 +481,7 @@ void fgRenderFrame( void ) { thesky->set_visibility( current_weather.get_visibility() ); #endif - thesky->modify_vis( cur_fdm_state->get_Altitude() * FEET_TO_METER, + thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER, ( global_multi_loop * fgGetInt("/sim/speed-up") ) / (double)fgGetInt("/sim/model-hz") ); @@ -490,7 +495,7 @@ void fgRenderFrame( void ) { // cout << "----> updating fog params" << endl; // for GL_FOG_EXP - fog_exp_density = -log(0.01 / actual_visibility); + fog_exp_density = -log(0.01) / actual_visibility; // for GL_FOG_EXP2 fog_exp2_density = sqrt( -log(0.01) ) / actual_visibility; @@ -543,7 +548,7 @@ void fgRenderFrame( void ) { globals->get_current_view()->get_world_up(), cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), - cur_fdm_state->get_Altitude() * FEET_TO_METER, + cur_fdm_state->get_Altitude() * SG_FEET_TO_METER, cur_light_params.sun_rotation, globals->get_time_params()->getGst(), globals->get_ephem()->getSunRightAscension(), @@ -555,42 +560,41 @@ void fgRenderFrame( void ) { } glEnable( GL_DEPTH_TEST ); - if ( fgGetString("/sim/rendering/fog") != "disabled" ) { + if ( fgGetString("/sim/rendering/fog") != (string)"disabled" ) { glEnable( GL_FOG ); glFogi( GL_FOG_MODE, GL_EXP2 ); glFogfv( GL_FOG_COLOR, l->adj_fog_color ); } - // set lighting parameters + // set sun/lighting parameters + ssgGetLight( 0 ) -> setPosition( l->sun_vec ); + + // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if + // we only update GL_AMBIENT for our lights we will never get + // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT + // explicitely to black. GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 }; - glLightModelfv( GL_LIGHT_MODEL_AMBIENT, l->scene_ambient ); - glLightfv( GL_LIGHT0, GL_AMBIENT, black ); - glLightfv( GL_LIGHT0, GL_DIFFUSE, l->scene_diffuse ); - // glLightfv(GL_LIGHT0, GL_SPECULAR, white ); + GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; + glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black ); + + ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient ); + ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse ); + // ssgGetLight( 0 ) -> setColour( GL_SPECULAR, l->scene_white ); // texture parameters // glEnable( GL_TEXTURE_2D ); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ; glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ; - // set base color (I don't think this is doing anything here) - // glMaterialfv (GL_FRONT, GL_AMBIENT, white); - // (GL_FRONT, GL_DIFFUSE, white); - // glMaterialfv (GL_FRONT, GL_SPECULAR, white); - // glMaterialfv (GL_FRONT, GL_SHININESS, mat_shininess); - - sgVec3 sunpos; - sgSetVec3( sunpos, l->sun_vec[0], l->sun_vec[1], l->sun_vec[2] ); - ssgGetLight( 0 ) -> setPosition( sunpos ); // glMatrixMode( GL_PROJECTION ); // glLoadIdentity(); float fov = globals->get_current_view()->get_fov(); ssgSetFOV(fov, fov * globals->get_current_view()->get_win_ratio()); - double agl = current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER + double agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER - scenery.cur_elev; - // FG_LOG( FG_ALL, FG_INFO, "visibility is " + // SG_LOG( SG_ALL, SG_INFO, "visibility is " // << current_weather.get_visibility() ); if ( agl > 10.0 ) { @@ -680,7 +684,14 @@ void fgRenderFrame( void ) { if ( fgGetBool("/sim/rendering/skyblend") ) { // draw the sky backdrop + + // we need a white diffuse light for the phase of the moon + ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white ); + thesky->preDraw(); + + // return to the desired diffuse color + ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse ); } // draw the ssg scene @@ -697,7 +708,7 @@ void fgRenderFrame( void ) { if ( fgGetBool("/sim/rendering/skyblend") ) { // draw the sky cloud layers - thesky->postDraw( cur_fdm_state->get_Altitude() * FEET_TO_METER ); + thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER ); } // display HUD && Panel @@ -756,7 +767,7 @@ void fgUpdateTimeDepCalcs() { multi_loop = (long)(((double)elapsed * 0.000001) / cur_fdm_state->get_delta_t() ); cur_fdm_state->set_multi_loop( multi_loop ); - long remainder = elapsed - ( (multi_loop*1000000) * + long remainder = elapsed - (long)( (multi_loop*1000000) * cur_fdm_state->get_delta_t() ); cur_fdm_state->set_remainder( remainder ); // cout << "remainder = " << remainder << endl; @@ -781,9 +792,9 @@ void fgUpdateTimeDepCalcs() { cur_fdm_state->update( 0 ); FGSteam::update( 0 ); - if ( global_tile_mgr.queue_size() == 0 ) { + //if ( global_tile_mgr.queue_size() == 0 ) { initial_freeze = false; - } + //} } if ( fgGetString("/sim/view-mode") == "pilot" ) { @@ -802,38 +813,38 @@ void fgUpdateTimeDepCalcs() { // current_view.goal_view_offset if ( v->get_goal_view_offset() > v->get_view_offset() ) { - if ( v->get_goal_view_offset() - v->get_view_offset() < FG_PI ){ + if ( v->get_goal_view_offset() - v->get_view_offset() < SGD_PI ){ v->inc_view_offset( 0.01 ); } else { v->inc_view_offset( -0.01 ); } } else { - if ( v->get_view_offset() - v->get_goal_view_offset() < FG_PI ){ + if ( v->get_view_offset() - v->get_goal_view_offset() < SGD_PI ){ v->inc_view_offset( -0.01 ); } else { v->inc_view_offset( 0.01 ); } } - if ( v->get_view_offset() > FG_2PI ) { - v->inc_view_offset( -FG_2PI ); + if ( v->get_view_offset() > SGD_2PI ) { + v->inc_view_offset( -SGD_2PI ); } else if ( v->get_view_offset() < 0 ) { - v->inc_view_offset( FG_2PI ); + v->inc_view_offset( SGD_2PI ); } } } - double tmp = -(l->sun_rotation + FG_PI) + double tmp = -(l->sun_rotation + SGD_PI) - (cur_fdm_state->get_Psi() - globals->get_current_view()->get_view_offset() ); while ( tmp < 0.0 ) { - tmp += FG_2PI; + tmp += SGD_2PI; } - while ( tmp > FG_2PI ) { - tmp -= FG_2PI; + while ( tmp > SGD_2PI ) { + tmp -= SGD_2PI; } /* printf("Psi = %.2f, viewoffset = %.2f sunrot = %.2f rottosun = %.2f\n", - FG_Psi * RAD_TO_DEG, current_view.view_offset * RAD_TO_DEG, - -(l->sun_rotation+FG_PI) * RAD_TO_DEG, tmp * RAD_TO_DEG); */ + FG_Psi * SGD_RADIANS_TO_DEGREES, current_view.view_offset * SGD_RADIANS_TO_DEGREES, + -(l->sun_rotation+SGD_PI) * SGD_RADIANS_TO_DEGREES, tmp * SGD_RADIANS_TO_DEGREES); */ l->UpdateAdjFog(); // Update solar system @@ -857,7 +868,7 @@ void fgInitTimeDepCalcs( void ) { static const double alt_adjust_ft = 3.758099; -static const double alt_adjust_m = alt_adjust_ft * FEET_TO_METER; +static const double alt_adjust_m = alt_adjust_ft * SG_FEET_TO_METER; // What should we do when we have nothing else to do? Let's get ready @@ -875,8 +886,8 @@ static void fgMainLoop( void ) { SGTime *t = globals->get_time_params(); - FG_LOG( FG_ALL, FG_DEBUG, "Running Main Loop"); - FG_LOG( FG_ALL, FG_DEBUG, "======= ==== ===="); + SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop"); + SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ===="); #ifdef FG_NETWORK_OLK if ( fgGetBool("/sim/networking/network-olk") ) { @@ -909,31 +920,31 @@ static void fgMainLoop( void ) { /* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n", scenery.cur_elev, - cur_fdm_state->get_Runway_altitude() * FEET_TO_METER, - cur_fdm_state->get_Altitude() * FEET_TO_METER); */ + cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER, + cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */ if ( scenery.cur_elev > -9990 ) { - if ( cur_fdm_state->get_Altitude() * FEET_TO_METER < + if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER < (scenery.cur_elev + alt_adjust_m - 3.0) ) { // now set aircraft altitude above ground printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n", - cur_fdm_state->get_Altitude() * FEET_TO_METER, + cur_fdm_state->get_Altitude() * SG_FEET_TO_METER, scenery.cur_elev + alt_adjust_m - 3.0, scenery.cur_elev + alt_adjust_m ); fgFDMForceAltitude( fgGetString("/sim/flight-model"), scenery.cur_elev + alt_adjust_m ); - FG_LOG( FG_ALL, FG_DEBUG, + SG_LOG( SG_ALL, SG_DEBUG, "<*> resetting altitude to " - << cur_fdm_state->get_Altitude() * FEET_TO_METER + << cur_fdm_state->get_Altitude() * SG_FEET_TO_METER << " meters" ); } } /* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n", scenery.cur_elev, - cur_fdm_state->get_Runway_altitude() * FEET_TO_METER, - cur_fdm_state->get_Altitude() * FEET_TO_METER); */ + cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER, + cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */ // update "time" if ( globals->get_warp_delta() != 0 ) { @@ -951,12 +962,12 @@ static void fgMainLoop( void ) { // update magvar model globals->get_mag()->update( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), - cur_fdm_state->get_Altitude()* FEET_TO_METER, + cur_fdm_state->get_Altitude()* SG_FEET_TO_METER, globals->get_time_params()->getJD() ); // Get elapsed time (in usec) for this past frame elapsed = fgGetTimeInterval(); - FG_LOG( FG_ALL, FG_DEBUG, + SG_LOG( SG_ALL, SG_DEBUG, "Elapsed time interval is = " << elapsed << ", previous remainder is = " << remainder ); @@ -982,7 +993,7 @@ static void fgMainLoop( void ) { #else if ( (t->get_cur_time() != last_time) && (last_time > 0) ) { general.set_frame_rate( frames ); - FG_LOG( FG_ALL, FG_DEBUG, + SG_LOG( SG_ALL, SG_DEBUG, "--> Frame rate is = " << general.get_frame_rate() ); frames = 0; } @@ -999,7 +1010,7 @@ static void fgMainLoop( void ) { fgGetInt("/sim/model-hz")); remainder = elapsed - ( (global_multi_loop*1000000) / fgGetInt("/sim/model-hz") ); - FG_LOG( FG_ALL, FG_DEBUG, + SG_LOG( SG_ALL, SG_DEBUG, "Model iterations needed = " << global_multi_loop << ", new remainder = " << remainder ); @@ -1014,7 +1025,7 @@ static void fgMainLoop( void ) { if ( global_multi_loop > 0 ) { fgUpdateTimeDepCalcs(); } else { - FG_LOG( FG_ALL, FG_DEBUG, + SG_LOG( SG_ALL, SG_DEBUG, "Elapsed time is zero ... we're zinging" ); } @@ -1024,8 +1035,13 @@ static void fgMainLoop( void ) { #endif // see if we need to load any new scenery tiles - global_tile_mgr.update( cur_fdm_state->get_Longitude() * RAD_TO_DEG, - cur_fdm_state->get_Latitude() * RAD_TO_DEG ); + global_tile_mgr.update( cur_fdm_state->get_Longitude() + * SGD_RADIANS_TO_DEGREES, + cur_fdm_state->get_Latitude() + * SGD_RADIANS_TO_DEGREES ); + + // see if we need to load any deferred-load textures + material_lib.load_next_deferred(); // Process/manage pending events global_events.Process(); @@ -1088,7 +1104,7 @@ static void fgMainLoop( void ) { // redraw display fgRenderFrame(); - FG_LOG( FG_ALL, FG_DEBUG, "" ); + SG_LOG( SG_ALL, SG_DEBUG, "" ); } @@ -1115,13 +1131,13 @@ static void fgIdleFunction ( void ) { #if !defined(WIN32) if ( fgGetBool("/sim/startup/intro-music") ) { string lockfile = "/tmp/mpg123.running"; - FGPath mp3file( globals->get_fg_root() ); + SGPath mp3file( globals->get_fg_root() ); mp3file.append( "Sounds/intro.mp3" ); string command = "(touch " + lockfile + "; mpg123 " + mp3file.str() + "> /dev/null 2>&1; /bin/rm " + lockfile + ") &"; - FG_LOG( FG_GENERAL, FG_INFO, + SG_LOG( SG_GENERAL, SG_INFO, "Starting intro music: " << mp3file.str() ); system ( command.c_str() ); } @@ -1145,7 +1161,7 @@ static void fgIdleFunction ( void ) { // a subsystem to flightgear, its initialization call should // located in this routine. if( !fgInitSubsystems()) { - FG_LOG( FG_GENERAL, FG_ALERT, + SG_LOG( SG_GENERAL, SG_ALERT, "Subsystem initializations failed ..." ); exit(-1); } @@ -1169,14 +1185,14 @@ static void fgIdleFunction ( void ) { string lockfile = "/tmp/mpg123.running"; struct stat stat_buf; - FG_LOG( FG_GENERAL, FG_INFO, + SG_LOG( SG_GENERAL, SG_INFO, "Waiting for mpg123 player to finish ..." ); while ( stat(lockfile.c_str(), &stat_buf) == 0 ) { // file exist, wait ... sleep(1); - FG_LOG( FG_GENERAL, FG_INFO, "."); + SG_LOG( SG_GENERAL, SG_INFO, "."); } - FG_LOG( FG_GENERAL, FG_INFO, ""); + SG_LOG( SG_GENERAL, SG_INFO, ""); } #endif // WIN32 @@ -1187,7 +1203,7 @@ static void fgIdleFunction ( void ) { "Sounds/wasp.wav") ); globals->get_soundmgr()->add( s1, "engine loop" ); globals->get_soundmgr()->play_looped( "engine loop" ); - FG_LOG( FG_GENERAL, FG_INFO, + SG_LOG( SG_GENERAL, SG_INFO, "Rate = " << s1->get_sample()->getRate() << " Bps = " << s1->get_sample()->getBps() << " Stereo = " << s1->get_sample()->getStereo() ); @@ -1271,7 +1287,7 @@ int fgGlutInit( int *argc, char **argv ) { // Define Display Parameters glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); - FG_LOG( FG_GENERAL, FG_INFO, "Opening a window: " << + SG_LOG( SG_GENERAL, SG_INFO, "Opening a window: " << fgGetInt("/sim/startup/xsize") << "x" << fgGetInt("/sim/startup/ysize") ); @@ -1292,7 +1308,7 @@ int fgGlutInit( int *argc, char **argv ) { fgGetInt("/sim/startup/ysize"), fgGetInt("/sim/rendering/bits-per-pixel")); - FG_LOG( FG_GENERAL, FG_INFO, + SG_LOG( SG_GENERAL, SG_INFO, "game mode params = " << game_mode_str ); glutGameModeString( game_mode_str ); glutEnterGameMode(); @@ -1305,16 +1321,16 @@ int fgGlutInit( int *argc, char **argv ) { general.set_glVendor( (char *)glGetString ( GL_VENDOR ) ); general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) ); general.set_glVersion( (char *)glGetString ( GL_VERSION ) ); - FG_LOG( FG_GENERAL, FG_INFO, general.get_glRenderer() ); + SG_LOG( SG_GENERAL, SG_INFO, general.get_glRenderer() ); GLint tmp; glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp ); general.set_glMaxTexSize( tmp ); - FG_LOG ( FG_GENERAL, FG_INFO, "Max texture size = " << tmp ); + SG_LOG ( SG_GENERAL, SG_INFO, "Max texture size = " << tmp ); glGetIntegerv( GL_DEPTH_BITS, &tmp ); general.set_glDepthBits( tmp ); - FG_LOG ( FG_GENERAL, FG_INFO, "Depth buffer bits = " << tmp ); + SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp ); return 1; } @@ -1359,7 +1375,7 @@ int main( int argc, char **argv ) { #endif // set default log levels - fglog().setLogLevels( FG_ALL, FG_INFO ); + sglog().setLogLevels( SG_ALL, SG_INFO ); string version; #ifdef FLIGHTGEAR_VERSION @@ -1367,15 +1383,13 @@ int main( int argc, char **argv ) { #else version = "unknown version"; #endif - FG_LOG( FG_GENERAL, FG_INFO, "FlightGear: Version " + SG_LOG( SG_GENERAL, SG_INFO, "FlightGear: Version " << version << endl ); // Allocate global data structures. This needs to happen before // we parse command line options - SGPropertyNode *props = new SGPropertyNode; globals = new FGGlobals; - globals->set_props( props ); // seed the random number generater sg_srandom_time(); @@ -1412,19 +1426,19 @@ int main( int argc, char **argv ) { // Load the configuration parameters if ( !fgInitConfig(argc, argv) ) { - FG_LOG( FG_GENERAL, FG_ALERT, "Config option parsing failed ..." ); + SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." ); exit(-1); } // Initialize the Window/Graphics environment. if( !fgGlutInit(&argc, argv) ) { - FG_LOG( FG_GENERAL, FG_ALERT, "GLUT initialization failed ..." ); + SG_LOG( SG_GENERAL, SG_ALERT, "GLUT initialization failed ..." ); exit(-1); } // Initialize the various GLUT Event Handlers. if( !fgGlutInitEvents() ) { - FG_LOG( FG_GENERAL, FG_ALERT, + SG_LOG( SG_GENERAL, SG_ALERT, "GLUT event handler initialization failed ..." ); exit(-1); } @@ -1438,6 +1452,20 @@ int main( int argc, char **argv ) { // fonts !!! guiInit(); +#ifdef GL_EXT_texture_lod_bias + glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ; +#endif + +#if 0 +#ifdef GL_EXT_texture_filter_anisotropic + float max_anisotropy; + glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy ); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, + max_anisotropy ); + cout << "Max anisotropy = " << max_anisotropy << endl; +#endif +#endif + // set current_options lon/lat if an airport id is specified // cout << "3. airport_id = " << fgGetString("/sim/startup/airport-id") << endl; if ( fgGetString("/sim/startup/airport-id").length() ) { @@ -1447,10 +1475,10 @@ int main( int argc, char **argv ) { } // Initialize time - FGPath zone( globals->get_fg_root() ); + SGPath zone( globals->get_fg_root() ); zone.append( "Timezone" ); - SGTime *t = new SGTime( fgGetDouble("/position/longitude") * DEG_TO_RAD, - fgGetDouble("/position/latitude") * DEG_TO_RAD, + SGTime *t = new SGTime( fgGetDouble("/position/longitude") * SGD_DEGREES_TO_RADIANS, + fgGetDouble("/position/latitude") * SGD_DEGREES_TO_RADIANS, zone.str() ); // Handle potential user specified time offsets @@ -1477,12 +1505,12 @@ int main( int argc, char **argv ) { globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) - cur_time ); } else { - FG_LOG( FG_GENERAL, FG_ALERT, + SG_LOG( SG_GENERAL, SG_ALERT, "Unsupported offset type " << offset_type ); exit( -1 ); } - FG_LOG( FG_GENERAL, FG_INFO, "After time init, warp = " + SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = " << globals->get_warp() ); globals->set_warp_delta( 0 ); @@ -1493,12 +1521,12 @@ int main( int argc, char **argv ) { // Do some quick general initializations if( !fgInitGeneral()) { - FG_LOG( FG_GENERAL, FG_ALERT, + SG_LOG( SG_GENERAL, SG_ALERT, "General initializations failed ..." ); exit(-1); } - FGPath modelpath( globals->get_fg_root() ); + SGPath modelpath( globals->get_fg_root() ); ssgModelPath( (char *)modelpath.c_str() ); // Scene graph root @@ -1509,7 +1537,7 @@ int main( int argc, char **argv ) { lighting->setName( "Lighting" ); // Initialize the sky - FGPath ephem_data_path( globals->get_fg_root() ); + SGPath ephem_data_path( globals->get_fg_root() ); ephem_data_path.append( "Astro" ); SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() ); ephem->update( globals->get_time_params()->getMjd(), @@ -1517,10 +1545,11 @@ int main( int argc, char **argv ) { 0.0 ); globals->set_ephem( ephem ); - FGPath sky_tex_path( globals->get_fg_root() ); + thesky = new SGSky; + + SGPath sky_tex_path( globals->get_fg_root() ); sky_tex_path.append( "Textures" ); sky_tex_path.append( "Sky" ); - thesky = new SGSky; thesky->texture_path( sky_tex_path.str() ); thesky->build( 550.0, 550.0, @@ -1530,14 +1559,14 @@ int main( int argc, char **argv ) { globals->get_ephem()->getStars(), 60000.0 ); if ( fgGetBool("/environment/clouds/status") ) { + // thesky->add_cloud_layer( 2000.0, 200.0, 50.0, 40000.0, + // SG_CLOUD_OVERCAST ); thesky->add_cloud_layer( 2600.0, 200.0, 50.0, 40000.0, - SG_CLOUD_MOSTLY_SUNNY ); + SG_CLOUD_MOSTLY_CLOUDY ); + // thesky->add_cloud_layer( 3000.0, 200.0, 50.0, 40000.0, + // SG_CLOUD_MOSTLY_SUNNY ); thesky->add_cloud_layer( 6000.0, 20.0, 10.0, 40000.0, SG_CLOUD_CIRRUS ); - // thesky->add_cloud_layer( 1000.0, 200.0, 50.0, - // SG_CLOUD_MOSTLY_SUNNY ); - // thesky->add_cloud_layer( 1800.0, 400.0, 100.0, SG_CLOUD_OVERCAST ); - // thesky->add_cloud_layer( 5000.0, 20.0, 10.0, SG_CLOUD_CIRRUS ); } // Initialize MagVar model @@ -1562,18 +1591,29 @@ int main( int argc, char **argv ) { acmodel_selector = new ssgSelector; acmodel_pos = new ssgTransform; + // Get the model location, and load textures from the same + // directory. Use an absolute path for the model to avoid + // incompatibilities in different versions of PLIB. string acmodel_path = fgGetString("/sim/model/path", "Models/Geometry/glider.ac"); + SGPath full_model = globals->get_fg_root(); + full_model.append(acmodel_path); - string full_model = globals->get_fg_root() + "/" - + acmodel_path; - int pos = full_model.rfind("/"); - - FGPath texturepath( full_model.substr(0, pos) ); - cout << "Texture path = " << texturepath.str() << endl; - ssgTexturePath( (char *)texturepath.c_str() ); +#if !defined( PLIB_1_2_X ) + // this should be redundant ... but it breaks for relative paths + // ssgModelPath( (char *)full_model.dir().c_str() ); +#endif - ssgEntity *acmodel_obj = ssgLoad((char *)(acmodel_path.c_str())); + ssgTexturePath( (char *)full_model.dir().c_str() ); + ssgEntity *acmodel_obj = ssgLoad( (char *)full_model.c_str() ); + if( !acmodel_obj ) { + // fall back to default + acmodel_obj = ssgLoad( (char *)"Models/Geometry/glider.ac" ); + if( !acmodel_obj ) { + SG_LOG( SG_GENERAL, SG_ALERT, "FAILED to LOAD an AC model! ..." ); + exit(-1); + } + } // find moving parts (if this is an MDL model) flaps_selector = (ssgSelector*)fgFindNode( acmodel_obj, "FLAPS" ); @@ -1592,7 +1632,7 @@ int main( int argc, char **argv ) { acmodel_proprpms[acmodel_npropsettings][1] = prop_high; acmodel_npropsettings++; - FG_LOG( FG_GENERAL, FG_INFO, "PROPELLER SETTING " << prop_low << + SG_LOG( SG_GENERAL, SG_INFO, "PROPELLER SETTING " << prop_low << " " << prop_high ); } } @@ -1655,73 +1695,74 @@ void fgLoadDCS(void) { // int j=0; char obj_filename[25]; - for (int k=0;k<32;k++) - { + for ( int k = 0; k < 32; k++ ) { ship_pos[k]=NULL; } - FGPath tile_path( globals->get_fg_root()); + SGPath tile_path( globals->get_fg_root()); tile_path.append( "Scenery" ); tile_path.append( "Objects.txt" ); - fg_gzifstream in( tile_path.str() ); + sg_gzifstream in( tile_path.str() ); if ( ! in.is_open() ) { - FG_LOG( FG_TERRAIN, FG_ALERT, "Cannot open file: " << tile_path.str() ); - } + SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << tile_path.str() ); + } else { - FGPath modelpath( globals->get_fg_root() ); - modelpath.append( "Models" ); - modelpath.append( "Geometry" ); + SGPath modelpath( globals->get_fg_root() ); + modelpath.append( "Models" ); + modelpath.append( "Geometry" ); - FGPath texturepath( globals->get_fg_root() ); - texturepath.append( "Models" ); - texturepath.append( "Textures" ); + SGPath texturepath( globals->get_fg_root() ); + texturepath.append( "Models" ); + texturepath.append( "Textures" ); - ssgModelPath( (char *)modelpath.c_str() ); - ssgTexturePath( (char *)texturepath.c_str() ); - - ship_sel = new ssgSelector; - - char c; - while ( ! in.eof() ) - { - in >> ::skipws; - if ( in.get( c ) && c == '#' ) - { - in >> skipeol; - } - else - { - in.putback(c); - in >> obj_filename >> obj_lat[objc] >> obj_lon[objc] >> obj_alt[objc]; -/* cout << endl << obj_filename << " " << obj_lat[objc] << " " << obj_lon[objc] << " " << obj_alt[objc] << endl; - int chj=getchar();*/ + ssgModelPath( (char *)modelpath.c_str() ); + ssgTexturePath( (char *)texturepath.c_str() ); + + ship_sel = new ssgSelector; + + char c; + while ( ! in.eof() ) { + in >> ::skipws; + if ( in.get( c ) && c == '#' ) { + in >> skipeol; + } else { + in.putback(c); + in >> obj_filename >> obj_lat[objc] >> obj_lon[objc] >> obj_alt[objc]; + /* cout << endl << obj_filename << " " << obj_lat[objc] << " " << obj_lon[objc] << " " << obj_alt[objc] << endl; + int chj=getchar();*/ - obj_lon[objc] *=DEG_TO_RAD; - obj_lat[objc] *=DEG_TO_RAD; - - ship_pos[objc] = new ssgTransform; - + obj_lon[objc] *=SGD_DEGREES_TO_RADIANS; + obj_lat[objc] *=SGD_DEGREES_TO_RADIANS; + + ship_pos[objc] = new ssgTransform; - // type "repeat" in objects.txt to load one more instance of the last object. + // type "repeat" in objects.txt to load one more + // instance of the last object. - if ( strcmp(obj_filename,"repeat") != 0) - ship_obj = ssgLoadOBJ( obj_filename ); + if ( strcmp(obj_filename,"repeat") != 0) { + ship_obj = ssgLoadOBJ( obj_filename ); + } - if ( ship_obj != NULL ) - { - ship_pos[objc]->addKid( ship_obj ); // add object to transform node - ship_sel->addKid( ship_pos[objc] ); // add transform node to selector - } - else - FG_LOG( FG_TERRAIN, FG_ALERT, "Cannot open file: " << obj_filename ); + if ( ship_obj != NULL ) { + ship_pos[objc]->addKid( ship_obj ); // add object to transform node + ship_sel->addKid( ship_pos[objc] ); // add transform node to selector + } else { + SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " + << obj_filename ); + } - if (in.eof()) break; - objc++; - } - } // while + objc++; + + if (in.eof()) break; + } + } // while + + SG_LOG ( SG_TERRAIN, SG_ALERT, "Finished object processing." ); + + ship_sel->clrTraversalMaskBits( SSGTRAV_HOT ); + scene->addKid( ship_sel ); //add selector node to root node + } - ship_sel->clrTraversalMaskBits( SSGTRAV_HOT ); - scene->addKid( ship_sel ); //add selector node to root node return; } @@ -1740,16 +1781,14 @@ void fgUpdateDCS (void) { // Deck should be the first object in objects.txt in case of fdm=ada - if (fgGetString("/sim/flight-model") == "ada") - { - obj_lon[0] = fdm->get_aux5()*DEG_TO_RAD; - obj_lat[0] = fdm->get_aux6()*DEG_TO_RAD; - obj_alt[0] = fdm->get_aux7(); + if (fgGetString("/sim/flight-model") == "ada") { + obj_lon[0] = fdm->get_aux5()*SGD_DEGREES_TO_RADIANS; + obj_lat[0] = fdm->get_aux6()*SGD_DEGREES_TO_RADIANS; + obj_alt[0] = fdm->get_aux7(); } - for (int m=0; m<=objc; m++) - { - //cout << endl << obj_lat[m]*RAD_TO_DEG << " " << obj_lon[m]*RAD_TO_DEG << " " << obj_alt[m] << " " << objc << endl; + for ( int m = 0; m < objc; m++ ) { + //cout << endl << obj_lat[m]*SGD_RADIANS_TO_DEGREES << " " << obj_lon[m]*SGD_RADIANS_TO_DEGREES << " " << obj_alt[m] << " " << objc << endl; //int v=getchar(); //Geodetic to Geocentric angles for rotation @@ -1776,8 +1815,8 @@ void fgUpdateDCS (void) { sgSetVec3( ship_up, 0.0, 0.0, 1.0); //north,yaw sgMat4 sgROT_lon, sgROT_lat, sgROT_hdg; - sgMakeRotMat4( sgROT_lon, obj_lon[m]*RAD_TO_DEG, ship_up ); - sgMakeRotMat4( sgROT_lat, 90-obj_latgc*RAD_TO_DEG, ship_rt ); + sgMakeRotMat4( sgROT_lon, obj_lon[m]*SGD_RADIANS_TO_DEGREES, ship_up ); + sgMakeRotMat4( sgROT_lat, 90-obj_latgc*SGD_RADIANS_TO_DEGREES, ship_rt ); sgMakeRotMat4( sgROT_hdg, 180.0, ship_up ); sgMat4 sgTUX; @@ -1790,9 +1829,10 @@ void fgUpdateDCS (void) { sgSetCoord(&shippos, sgTUX ); ship_pos[m]->setTransform( &shippos ); } - if ( ship_sel != NULL ) + if ( ship_sel != NULL ) { ship_sel->select(0xFFFFFFFF); - } + } +} // $$$ end - added VS Renganathan, 15 Oct 2K // added Venky , 12 Nov 2K