From 09ee64ff679611ad5d7a26fab25fd3b91579015f Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 11 Dec 1997 04:43:53 +0000 Subject: [PATCH] Fixed sun vector and lighting problems. I thing the moon is now lit correctly. --- Main/GLUTmain.c | 54 +++++++++++++++++++++++++--------------------- Main/fg_init.c | 18 +++++++++++----- Scenery/astro.c | 13 +++++------ Scenery/astro.h | 9 +++++--- Scenery/moon.h | 9 +++++--- Scenery/sun.h | 9 +++++--- Simulator/make.inc | 6 +++++- Time/fg_time.c | 16 ++++++++------ Time/sunpos.c | 28 +++++++++++++++++------- Weather/weather.c | 12 +++++++---- 10 files changed, 110 insertions(+), 64 deletions(-) diff --git a/Main/GLUTmain.c b/Main/GLUTmain.c index 06f6a16d2..912acfcc1 100644 --- a/Main/GLUTmain.c +++ b/Main/GLUTmain.c @@ -61,9 +61,6 @@ static GLfloat win_ratio = 1.0; /* sun direction */ /* static GLfloat sun_vec[4] = {1.0, 0.0, 0.0, 0.0 }; */ -/* if the 4th field is 0.0, this specifies a direction ... */ -/* clear color (sky) */ -GLfloat fgClearColor[4] = {0.60, 0.60, 0.90, 1.0}; /* fog color */ static GLfloat fgFogColor[4] = {0.65, 0.65, 0.85, 1.0}; @@ -120,8 +117,8 @@ static void fgInitVisuals() { /* glFogf (GL_FOG_DENSITY, w->visibility); */ /* glHint (GL_FOG_HINT, GL_FASTEST); */ - glClearColor(fgClearColor[0], fgClearColor[1], fgClearColor[2], - fgClearColor[3]); + /* initial screen color */ + glClearColor(0.0, 0.0, 0.0, 1.0); } @@ -136,9 +133,11 @@ static void fgUpdateViewParams() { struct fgVIEW *v; double x_2, x_4, x_8, x_10; - double ambient, diffuse, sky; - GLfloat color[4] = { 1.0, 1.0, 0.50, 1.0 }; - /* GLfloat amb[3], diff[3], fog[4], clear[4]; */ + double ambient, diffuse, sky_brightness; + /* if the 4th field is 0.0, this specifies a direction ... */ + /* clear color (sky) */ + GLfloat sky_color[4] = {0.60, 0.60, 0.90, 1.0}; + GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; f = ¤t_aircraft.flight; l = &cur_light_params; @@ -150,7 +149,7 @@ static void fgUpdateViewParams() { /* Tell GL we are about to modify the projection parameters */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(60.0, 1.0/win_ratio, 1.0, 200000.0); + gluPerspective(55.0, 1.0/win_ratio, 1.0, 200000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -185,22 +184,22 @@ static void fgUpdateViewParams() { diffuse = ambient; - sky = 0.85 * pow(1.2, -x_8 / 20.0) + 0.15; + sky_brightness = 0.85 * pow(1.2, -x_8 / 20.0) + 0.15; - /* sky = 0.15; */ /* to force a dark sky (for testing) */ + /* sky_brightness = 0.15; */ /* to force a dark sky (for testing) */ if ( ambient < 0.1 ) { ambient = 0.1; } if ( diffuse < 0.0 ) { diffuse = 0.0; } - if ( sky < 0.0 ) { sky = 0.0; } + if ( sky_brightness < 0.0 ) { sky_brightness = 0.0; } - l->scene_ambient[0] = color[0] * ambient; - l->scene_ambient[1] = color[1] * ambient; - l->scene_ambient[2] = color[2] * ambient; + l->scene_ambient[0] = white[0] * ambient; + l->scene_ambient[1] = white[1] * ambient; + l->scene_ambient[2] = white[2] * ambient; - l->scene_diffuse[0] = color[0] * diffuse; - l->scene_diffuse[1] = color[1] * diffuse; - l->scene_diffuse[2] = color[2] * diffuse; + l->scene_diffuse[0] = white[0] * diffuse; + l->scene_diffuse[1] = white[1] * diffuse; + l->scene_diffuse[2] = white[2] * diffuse; /* set lighting parameters */ glLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_ambient ); @@ -214,10 +213,11 @@ static void fgUpdateViewParams() { glFogfv (GL_FOG_COLOR, l->scene_fog); /* set sky color */ - l->scene_clear[0] = fgClearColor[0] * sky; - l->scene_clear[1] = fgClearColor[1] * sky; - l->scene_clear[2] = fgClearColor[2] * sky; - l->scene_clear[3] = fgClearColor[3]; + l->scene_clear[0] = sky_color[0] * sky_brightness; + l->scene_clear[1] = sky_color[1] * sky_brightness; + l->scene_clear[2] = sky_color[2] * sky_brightness; + l->scene_clear[3] = sky_color[3]; + glClearColor(l->scene_clear[0], l->scene_clear[1], l->scene_clear[2], l->scene_clear[3]); } @@ -573,10 +573,14 @@ int main( int argc, char *argv[] ) { /* $Log$ -/* Revision 1.28 1997/12/10 22:37:45 curt -/* Prepended "fg" on the name of all global structures that didn't have it yet. -/* i.e. "struct WEATHER {}" became "struct fgWEATHER {}" +/* Revision 1.29 1997/12/11 04:43:54 curt +/* Fixed sun vector and lighting problems. I thing the moon is now lit +/* correctly. /* + * Revision 1.28 1997/12/10 22:37:45 curt + * Prepended "fg" on the name of all global structures that didn't have it yet. + * i.e. "struct WEATHER {}" became "struct fgWEATHER {}" + * * Revision 1.27 1997/12/09 05:11:54 curt * Working on tweaking lighting. * diff --git a/Main/fg_init.c b/Main/fg_init.c index ba95f11c3..5ec674cac 100644 --- a/Main/fg_init.c +++ b/Main/fg_init.c @@ -99,11 +99,12 @@ void fgInitSubsystems( void ) { FG_Longitude = ( -398391.28 / 3600.0 ) * DEG_TO_RAD; FG_Latitude = ( 120070.41 / 3600.0 ) * DEG_TO_RAD; FG_Altitude = FG_Runway_altitude + 3.758099; - FG_Altitude = 10000; /* Initial Position north of the city of Globe */ /* FG_Longitude = ( -398673.28 / 3600.0 ) * DEG_TO_RAD; */ /* FG_Latitude = ( 120625.64 / 3600.0 ) * DEG_TO_RAD; */ + FG_Longitude = ( -397867.44 / 3600.0 ) * DEG_TO_RAD; + FG_Latitude = ( 119548.21 / 3600.0 ) * DEG_TO_RAD; /* FG_Altitude = 0.0 + 3.758099; */ /* Initial Position: 10125 Jewell St. NE */ @@ -114,6 +115,8 @@ void fgInitSubsystems( void ) { /* A random test position */ /* FG_Longitude = ( 88128.00 / 3600.0 ) * DEG_TO_RAD; */ /* FG_Latitude = ( 93312.00 / 3600.0 ) * DEG_TO_RAD; */ + FG_Runway_altitude = 4500.0; + FG_Altitude = FG_Runway_altitude + 3.758099; printf("Initial position is: (%.4f, %.4f, %.2f)\n", FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, @@ -127,7 +130,8 @@ void fgInitSubsystems( void ) { /* Initial Orientation */ FG_Phi = -2.658474E-06; FG_Theta = 7.401790E-03; - FG_Psi = 270.0 * DEG_TO_RAD; + /* FG_Psi = 270.0 * DEG_TO_RAD; */ + FG_Psi = 258.0 * DEG_TO_RAD; /* FG_Psi = 0.0 * DEG_TO_RAD; */ /* Initial Angular B rates */ @@ -216,10 +220,14 @@ void fgInitSubsystems( void ) { /* $Log$ -/* Revision 1.14 1997/12/10 22:37:47 curt -/* Prepended "fg" on the name of all global structures that didn't have it yet. -/* i.e. "struct WEATHER {}" became "struct fgWEATHER {}" +/* Revision 1.15 1997/12/11 04:43:55 curt +/* Fixed sun vector and lighting problems. I thing the moon is now lit +/* correctly. /* + * Revision 1.14 1997/12/10 22:37:47 curt + * Prepended "fg" on the name of all global structures that didn't have it yet. + * i.e. "struct WEATHER {}" became "struct fgWEATHER {}" + * * Revision 1.13 1997/11/25 19:25:32 curt * Changes to integrate Durk's moon/sun code updates + clean up. * diff --git a/Scenery/astro.c b/Scenery/astro.c index 6246a7131..a9f10392d 100644 --- a/Scenery/astro.c +++ b/Scenery/astro.c @@ -89,9 +89,6 @@ void fgAstroRender() { /* Disable fog effects */ glDisable( GL_FOG ); - /* reverse light direction so the moon is displayed properly */ - glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv ); - glPushMatrix(); /* Translate to view position */ @@ -121,10 +118,14 @@ void fgAstroRender() { /* $Log$ -/* Revision 1.3 1997/12/10 22:37:49 curt -/* Prepended "fg" on the name of all global structures that didn't have it yet. -/* i.e. "struct WEATHER {}" became "struct fgWEATHER {}" +/* Revision 1.4 1997/12/11 04:43:56 curt +/* Fixed sun vector and lighting problems. I thing the moon is now lit +/* correctly. /* + * Revision 1.3 1997/12/10 22:37:49 curt + * Prepended "fg" on the name of all global structures that didn't have it yet. + * i.e. "struct WEATHER {}" became "struct fgWEATHER {}" + * * Revision 1.2 1997/12/09 04:25:33 curt * Working on adding a global lighting params structure. * diff --git a/Scenery/astro.h b/Scenery/astro.h index c273d1a84..a6b8ff2db 100644 --- a/Scenery/astro.h +++ b/Scenery/astro.h @@ -35,7 +35,6 @@ extern struct CelestialCoord extern float xMoon, yMoon, zMoon, xSun, ySun, zSun; extern GLint moon, sun; extern GLint stars[FG_STAR_LEVELS]; -extern GLfloat fgClearColor[4]; /* Initialize Astronomical Objects */ @@ -49,7 +48,11 @@ void fgAstroRender(); /* $Log$ -/* Revision 1.1 1997/11/25 23:20:23 curt -/* Initial revision. +/* Revision 1.2 1997/12/11 04:43:56 curt +/* Fixed sun vector and lighting problems. I thing the moon is now lit +/* correctly. /* + * Revision 1.1 1997/11/25 23:20:23 curt + * Initial revision. + * */ diff --git a/Scenery/moon.h b/Scenery/moon.h index 8c0ae98bc..a8e903860 100644 --- a/Scenery/moon.h +++ b/Scenery/moon.h @@ -46,15 +46,18 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements Params, struct fgTIME t); extern struct OrbElements pltOrbElements[9]; -extern GLfloat fgClearColor[4]; #endif /* _MOON_H_ */ /* $Log$ -/* Revision 1.3 1997/11/25 19:25:35 curt -/* Changes to integrate Durk's moon/sun code updates + clean up. +/* Revision 1.4 1997/12/11 04:43:56 curt +/* Fixed sun vector and lighting problems. I thing the moon is now lit +/* correctly. /* + * Revision 1.3 1997/11/25 19:25:35 curt + * Changes to integrate Durk's moon/sun code updates + clean up. + * * Revision 1.2 1997/10/25 03:24:23 curt * Incorporated sun, moon, and star positioning code contributed by Durk Talsma. * diff --git a/Scenery/sun.h b/Scenery/sun.h index fe06244f8..9d597d27e 100644 --- a/Scenery/sun.h +++ b/Scenery/sun.h @@ -29,7 +29,6 @@ struct SunPos fgCalcSunPos(struct OrbElements sunParams); extern struct OrbElements pltOrbElements[9]; -extern GLfloat fgClearColor[4]; /* Initialize the Sun */ void fgSunInit(); @@ -42,9 +41,13 @@ void fgSunRender(); /* $Log$ -/* Revision 1.2 1997/11/25 19:25:39 curt -/* Changes to integrate Durk's moon/sun code updates + clean up. +/* Revision 1.3 1997/12/11 04:43:56 curt +/* Fixed sun vector and lighting problems. I thing the moon is now lit +/* correctly. /* + * Revision 1.2 1997/11/25 19:25:39 curt + * Changes to integrate Durk's moon/sun code updates + clean up. + * * Revision 1.1 1997/10/25 03:16:12 curt * Initial revision of code contributed by Durk Talsma. * diff --git a/Simulator/make.inc b/Simulator/make.inc index f78c3904a..4dd17b9a8 100644 --- a/Simulator/make.inc +++ b/Simulator/make.inc @@ -30,7 +30,7 @@ #--------------------------------------------------------------------------- VERSION_MAJOR = 0 -VERSION_MINOR = 16 +VERSION_MINOR = 17 VERSION = $(VERSION_MAJOR).$(VERSION_MINOR) @@ -131,6 +131,10 @@ FG_CFLAGS = $(GLOBAL_CFLAGS) #--------------------------------------------------------------------------- # $Log$ +# Revision 1.22 1997/12/11 04:43:53 curt +# Fixed sun vector and lighting problems. I thing the moon is now lit +# correctly. +# # Revision 1.21 1997/12/10 01:19:42 curt # Tweaks for verion 0.15 release. # diff --git a/Time/fg_time.c b/Time/fg_time.c index 9b0edca47..bb230f978 100644 --- a/Time/fg_time.c +++ b/Time/fg_time.c @@ -231,9 +231,9 @@ void fgTimeUpdate(struct fgFLIGHT *f, struct fgTIME *t) { static long int warp = 0; /* get current Unix calendar time (in seconds) */ - warp += 60; - /* warp = 0; */ - t->cur_time = time(NULL) + (0) * 60 * 60; + warp += 0; + /* warp = 60; */ + t->cur_time = time(NULL) + (12) * 60 * 60; t->cur_time += warp; printf("Current Unix calendar time = %ld warp = %ld\n", t->cur_time, warp); @@ -285,10 +285,14 @@ void fgTimeUpdate(struct fgFLIGHT *f, struct fgTIME *t) { /* $Log$ -/* Revision 1.15 1997/12/10 22:37:54 curt -/* Prepended "fg" on the name of all global structures that didn't have it yet. -/* i.e. "struct WEATHER {}" became "struct fgWEATHER {}" +/* Revision 1.16 1997/12/11 04:43:57 curt +/* Fixed sun vector and lighting problems. I thing the moon is now lit +/* correctly. /* + * Revision 1.15 1997/12/10 22:37:54 curt + * Prepended "fg" on the name of all global structures that didn't have it yet. + * i.e. "struct WEATHER {}" became "struct fgWEATHER {}" + * * Revision 1.14 1997/12/10 01:19:52 curt * Tweaks for verion 0.15 release. * diff --git a/Time/sunpos.c b/Time/sunpos.c index e5b554db5..5d4c31db2 100644 --- a/Time/sunpos.c +++ b/Time/sunpos.c @@ -283,11 +283,19 @@ void fgUpdateSunPos(struct fgCartesianPoint scenery_center) { /* printf("Geodetic lat = %.5f Geocentric lat = %.5f\n", sun_gd_lat, t->sun_gc_lat); */ - /* the sun position has to be translated just like everything else */ - l->sun_vec_inv[0] = l->fg_sunpos.x - scenery_center.x; - l->sun_vec_inv[1] = l->fg_sunpos.y - scenery_center.y; - l->sun_vec_inv[2] = l->fg_sunpos.z - scenery_center.z; - MAT3_SCALE_VEC(l->sun_vec, l->sun_vec_inv, -1.0); + /* FALSE! (?> the sun position has to be translated just like + * everything else */ + /* l->sun_vec_inv[0] = l->fg_sunpos.x - scenery_center.x; */ + /* l->sun_vec_inv[1] = l->fg_sunpos.y - scenery_center.y; */ + /* l->sun_vec_inv[2] = l->fg_sunpos.z - scenery_center.z; */ + /* MAT3_SCALE_VEC(l->sun_vec, l->sun_vec_inv, -1.0); */ + + /* I think this will work better for generating the sun light vector */ + l->sun_vec[0] = l->fg_sunpos.x; + l->sun_vec[1] = l->fg_sunpos.y; + l->sun_vec[2] = l->fg_sunpos.z; + MAT3_NORMALIZE_VEC(l->sun_vec, temp); + MAT3_SCALE_VEC(l->sun_vec_inv, l->sun_vec, -1.0); /* make these are directional light sources only */ l->sun_vec[3] = 0.0; @@ -308,10 +316,14 @@ void fgUpdateSunPos(struct fgCartesianPoint scenery_center) { /* $Log$ -/* Revision 1.15 1997/12/10 22:37:55 curt -/* Prepended "fg" on the name of all global structures that didn't have it yet. -/* i.e. "struct WEATHER {}" became "struct fgWEATHER {}" +/* Revision 1.16 1997/12/11 04:43:57 curt +/* Fixed sun vector and lighting problems. I thing the moon is now lit +/* correctly. /* + * Revision 1.15 1997/12/10 22:37:55 curt + * Prepended "fg" on the name of all global structures that didn't have it yet. + * i.e. "struct WEATHER {}" became "struct fgWEATHER {}" + * * Revision 1.14 1997/12/09 04:25:39 curt * Working on adding a global lighting params structure. * diff --git a/Weather/weather.c b/Weather/weather.c index f96107179..70e0eb09d 100644 --- a/Weather/weather.c +++ b/Weather/weather.c @@ -42,7 +42,7 @@ void fgWeatherInit(void) { /* Configure some wind */ /* FG_V_north_airmass = 15; */ /* ft/s =~ 10mph */ - w->visibility = 60000.0; /* meters = 60km */ + w->visibility = 45000.0; /* in meters */ } @@ -62,10 +62,14 @@ void fgWeatherUpdate(double lon, double lat, double alt) { /* $Log$ -/* Revision 1.7 1997/12/10 22:37:56 curt -/* Prepended "fg" on the name of all global structures that didn't have it yet. -/* i.e. "struct WEATHER {}" became "struct fgWEATHER {}" +/* Revision 1.8 1997/12/11 04:43:58 curt +/* Fixed sun vector and lighting problems. I thing the moon is now lit +/* correctly. /* + * Revision 1.7 1997/12/10 22:37:56 curt + * Prepended "fg" on the name of all global structures that didn't have it yet. + * i.e. "struct WEATHER {}" became "struct fgWEATHER {}" + * * Revision 1.6 1997/08/27 03:30:38 curt * Changed naming scheme of basic shared structures. * -- 2.39.2