From: curt Date: Mon, 22 Dec 1997 04:14:28 +0000 (+0000) Subject: Aligned sky with sun so dusk/dawn effects can be correct relative to the sun. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=45ed7c79f8a9d6ba7f9251285180d9276ba7c3eb;p=flightgear.git Aligned sky with sun so dusk/dawn effects can be correct relative to the sun. --- diff --git a/Main/GLUTmain.c b/Main/GLUTmain.c index dce600f3e..87848c258 100644 --- a/Main/GLUTmain.c +++ b/Main/GLUTmain.c @@ -124,8 +124,7 @@ static void fgUpdateViewParams() { /* base sky color */ GLfloat base_sky_color[4] = {0.60, 0.60, 0.90, 1.0}; /* base fog color */ - /* GLfloat base_fog_color[4] = {0.70, 0.70, 0.70, 1.0}; */ - GLfloat base_fog_color[4] = {1.00, 0.00, 0.00, 1.0}; + GLfloat base_fog_color[4] = {0.70, 0.70, 0.70, 1.0}; GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; @@ -134,7 +133,7 @@ static void fgUpdateViewParams() { t = &cur_time_params; v = ¤t_view; - fgViewUpdate(f, v); + fgViewUpdate(f, v, l); /* Tell GL we are about to modify the projection parameters */ xglMatrixMode(GL_PROJECTION); @@ -144,13 +143,27 @@ static void fgUpdateViewParams() { xglMatrixMode(GL_MODELVIEW); xglLoadIdentity(); - /* set up our view volume */ + /* set up our view volume (default) */ gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z, v->view_pos.x + v->view_forward[0], v->view_pos.y + v->view_forward[1], v->view_pos.z + v->view_forward[2], v->view_up[0], v->view_up[1], v->view_up[2]); + /* lock view horizontally towards sun (testing) */ + /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z, + v->view_pos.x + v->surface_to_sun[0], + v->view_pos.y + v->surface_to_sun[1], + v->view_pos.z + v->surface_to_sun[2], + v->view_up[0], v->view_up[1], v->view_up[2]); */ + + /* lock view horizontally towards south (testing) */ + /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z, + v->view_pos.x + v->surface_south[0], + v->view_pos.y + v->surface_south[1], + v->view_pos.z + v->surface_south[2], + v->view_up[0], v->view_up[1], v->view_up[2]); */ + /* set the sun position */ xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec ); @@ -203,7 +216,7 @@ static void fgUpdateViewParams() { * Update all Visuals (redraws anything graphics related) **************************************************************************/ -static void fgUpdateVisuals( void ) { +static void fgRenderFrame( void ) { struct fgLIGHT *l; struct fgTIME *t; struct fgVIEW *v; @@ -502,7 +515,7 @@ static void fgMainLoop( void ) { fgAircraftOutputCurrent(a); /* redraw display */ - fgUpdateVisuals(); + fgRenderFrame(); } @@ -589,7 +602,7 @@ int main( int argc, char *argv[] ) { xglutIdleFunc( fgMainLoop ); /* draw the scene */ - xglutDisplayFunc( fgUpdateVisuals ); + xglutDisplayFunc( fgRenderFrame ); /* pass control off to the GLUT event handler */ glutMainLoop(); @@ -607,9 +620,12 @@ int main( int argc, char *argv[] ) { /* $Log$ -/* Revision 1.37 1997/12/19 23:34:03 curt -/* Lot's of tweaking with sky rendering and lighting. +/* Revision 1.38 1997/12/22 04:14:28 curt +/* Aligned sky with sun so dusk/dawn effects can be correct relative to the sun. /* + * Revision 1.37 1997/12/19 23:34:03 curt + * Lot's of tweaking with sky rendering and lighting. + * * Revision 1.36 1997/12/19 16:44:57 curt * Working on scene rendering order and options. * diff --git a/Main/depend b/Main/depend index 01b1374e7..3ac3e76c5 100644 --- a/Main/depend +++ b/Main/depend @@ -1,44 +1,46 @@ GLUTkey.o: GLUTkey.c ../XGL/xgl.h GLUTkey.h views.h ../Include/types.h \ ../Flight/flight.h ../Flight/Slew/slew.h \ ../Flight/LaRCsim/ls_interface.h ../Flight/LaRCsim/../flight.h \ - ../Math/mat3.h ../Include/constants.h ../Aircraft/aircraft.h \ - ../Aircraft/../Flight/flight.h ../Aircraft/../Controls/controls.h \ + ../Math/mat3.h ../Time/fg_time.h ../Time/../Include/types.h \ + ../Time/../Flight/flight.h ../Include/constants.h \ + ../Aircraft/aircraft.h ../Aircraft/../Flight/flight.h \ + ../Aircraft/../Controls/controls.h \ ../Aircraft/../Controls/../Include/limits.h ../Weather/weather.h GLUTmain.o: GLUTmain.c ../XGL/xgl.h GLUTkey.h fg_init.h views.h \ ../Include/types.h ../Flight/flight.h ../Flight/Slew/slew.h \ ../Flight/LaRCsim/ls_interface.h ../Flight/LaRCsim/../flight.h \ - ../Math/mat3.h ../Include/constants.h ../Include/general.h \ - ../Aircraft/aircraft.h ../Aircraft/../Flight/flight.h \ - ../Aircraft/../Controls/controls.h \ + ../Math/mat3.h ../Time/fg_time.h ../Time/../Include/types.h \ + ../Time/../Flight/flight.h ../Include/constants.h \ + ../Include/general.h ../Aircraft/aircraft.h \ + ../Aircraft/../Flight/flight.h ../Aircraft/../Controls/controls.h \ ../Aircraft/../Controls/../Include/limits.h ../Cockpit/cockpit.h \ ../Cockpit/hud.h ../Cockpit/../Aircraft/aircraft.h \ ../Cockpit/../Flight/flight.h ../Cockpit/../Controls/controls.h \ ../Joystick/joystick.h ../Math/fg_geodesy.h ../Math/polar.h \ ../Math/../Include/types.h ../Scenery/mesh.h ../Scenery/moon.h \ - ../Scenery/orbits.h ../Scenery/../Time/fg_time.h \ - ../Scenery/../Time/../Include/types.h \ - ../Scenery/../Time/../Flight/flight.h ../Scenery/scenery.h \ + ../Scenery/orbits.h ../Scenery/../Time/fg_time.h ../Scenery/scenery.h \ ../Scenery/../Include/types.h ../Scenery/sky.h ../Scenery/stars.h \ - ../Scenery/sun.h ../Time/fg_time.h ../Time/fg_timer.h \ - ../Time/sunpos.h ../Time/../Include/types.h ../Weather/weather.h + ../Scenery/sun.h ../Time/fg_timer.h ../Time/sunpos.h \ + ../Weather/weather.h fg_init.o: fg_init.c fg_init.h views.h ../Include/types.h \ ../Flight/flight.h ../Flight/Slew/slew.h \ ../Flight/LaRCsim/ls_interface.h ../Flight/LaRCsim/../flight.h \ - ../Math/mat3.h ../Include/constants.h ../Include/general.h \ - ../Aircraft/aircraft.h ../Aircraft/../Flight/flight.h \ - ../Aircraft/../Controls/controls.h \ + ../Math/mat3.h ../Time/fg_time.h ../Time/../Include/types.h \ + ../Time/../Flight/flight.h ../Include/constants.h \ + ../Include/general.h ../Aircraft/aircraft.h \ + ../Aircraft/../Flight/flight.h ../Aircraft/../Controls/controls.h \ ../Aircraft/../Controls/../Include/limits.h ../Cockpit/cockpit.h \ ../Cockpit/hud.h ../Cockpit/../Aircraft/aircraft.h \ ../Cockpit/../Flight/flight.h ../Cockpit/../Controls/controls.h \ ../Joystick/joystick.h ../Math/fg_random.h ../Scenery/mesh.h \ ../Scenery/moon.h ../Scenery/orbits.h ../Scenery/../Time/fg_time.h \ - ../Scenery/../Time/../Include/types.h \ - ../Scenery/../Time/../Flight/flight.h ../Scenery/scenery.h \ - ../Scenery/../Include/types.h ../Scenery/sky.h ../Scenery/stars.h \ - ../Scenery/sun.h ../Time/fg_time.h ../Time/sunpos.h \ - ../Time/../Include/types.h ../Weather/weather.h + ../Scenery/scenery.h ../Scenery/../Include/types.h ../Scenery/sky.h \ + ../Scenery/stars.h ../Scenery/sun.h ../Time/sunpos.h \ + ../Weather/weather.h views.o: views.c views.h ../Include/types.h ../Flight/flight.h \ ../Flight/Slew/slew.h ../Flight/LaRCsim/ls_interface.h \ - ../Flight/LaRCsim/../flight.h ../Math/mat3.h ../Include/constants.h \ - ../Math/polar.h ../Math/../Include/types.h ../Scenery/scenery.h \ + ../Flight/LaRCsim/../flight.h ../Math/mat3.h ../Time/fg_time.h \ + ../Time/../Include/types.h ../Time/../Flight/flight.h \ + ../Include/constants.h ../Math/polar.h ../Math/../Include/types.h \ + ../Math/vector.h ../Math/../Math/mat3.h ../Scenery/scenery.h \ ../Scenery/../Include/types.h diff --git a/Main/views.c b/Main/views.c index c71764856..30fd8a80d 100644 --- a/Main/views.c +++ b/Main/views.c @@ -31,7 +31,9 @@ #include "../Flight/flight.h" #include "../Math/mat3.h" #include "../Math/polar.h" +#include "../Math/vector.h" #include "../Scenery/scenery.h" +#include "../Time/fg_time.h" /* This is a record containing current view parameters */ @@ -46,9 +48,10 @@ void fgViewInit(struct fgVIEW *v) { /* Update the view parameters */ -void fgViewUpdate(struct fgFLIGHT *f, struct fgVIEW *v) { - MAT3vec vec, forward; +void fgViewUpdate(struct fgFLIGHT *f, struct fgVIEW *v, struct fgLIGHT *l) { + MAT3vec vec, forward, v0, minus_z; MAT3mat R, TMP, UP, LOCAL, VIEW; + double ntmp; /* calculate the cartesion coords of the current lat/lon/0 elev */ v->cur_zero_elev = fgPolarToCart(FG_Longitude, FG_Lat_geocentric, @@ -67,6 +70,16 @@ void fgViewUpdate(struct fgFLIGHT *f, struct fgVIEW *v) { printf("View pos = %.4f, %.4f, %.4f\n", v->view_pos.x, v->view_pos.y, v->view_pos.z); + /* make a vector to the current view position */ + MAT3_SET_VEC(v0, v->view_pos.x, v->view_pos.y, v->view_pos.z); + + /* calculate vector to sun's position on the earth's surface */ + v->to_sun[0] = l->fg_sunpos.x - (v->view_pos.x + scenery.center.x); + v->to_sun[1] = l->fg_sunpos.y - (v->view_pos.y + scenery.center.y); + v->to_sun[2] = l->fg_sunpos.z - (v->view_pos.z + scenery.center.z); + printf("Vector to sun = %.2f %.2f %.2f\n", + v->to_sun[0], v->to_sun[1], v->to_sun[2]); + /* Derive the LOCAL aircraft rotation matrix (roll, pitch, yaw) */ MAT3_SET_VEC(vec, 0.0, 0.0, 1.0); MAT3rotate(R, vec, FG_Phi); @@ -136,13 +149,44 @@ void fgViewUpdate(struct fgFLIGHT *f, struct fgVIEW *v) { MAT3rotate(TMP, v->view_up, v->view_offset); MAT3mult_vec(v->view_forward, forward, TMP); + /* Given a vector from the view position to the point on the + * earth's surface the sun is directly over, map into onto the + * local plane representing "horizontal". */ + map_vec_onto_cur_surface_plane(v->local_up, v0, v->to_sun, + v->surface_to_sun); + MAT3_NORMALIZE_VEC(v->surface_to_sun, ntmp); + printf("Surface direction to sun is %.2f %.2f %.2f\n", + v->surface_to_sun[0], v->surface_to_sun[1], v->surface_to_sun[2]); + + /* printf("Should be close to zero = %.2f\n", + MAT3_DOT_PRODUCT(v->local_up, v->surface_to_sun)); */ + + /* Given a vector pointing straight down (-Z), map into onto the + * local plane representing "horizontal". This should give us the + * local direction for moving "south". */ + MAT3_SET_VEC(minus_z, 0.0, 0.0, -1.0); + map_vec_onto_cur_surface_plane(v->local_up, v0, minus_z, v->surface_south); + MAT3_NORMALIZE_VEC(v->surface_south, ntmp); + /* printf("Surface direction directly south %.2f %.2f %.2f\n", + v->surface_south[0], v->surface_south[1], v->surface_south[2]); */ + + /* now calculate the surface east vector */ + MAT3rotate(TMP, v->view_up, FG_PI_2); + MAT3mult_vec(v->surface_east, v->surface_south, TMP); + /* printf("Surface direction directly east %.2f %.2f %.2f\n", + v->surface_east[0], v->surface_east[1], v->surface_east[2]); */ + /* printf("Should be close to zero = %.2f\n", + MAT3_DOT_PRODUCT(v->surface_south, v->surface_east)); */ } /* $Log$ -/* Revision 1.5 1997/12/18 04:07:02 curt -/* Worked on properly translating and positioning the sky dome. +/* Revision 1.6 1997/12/22 04:14:32 curt +/* Aligned sky with sun so dusk/dawn effects can be correct relative to the sun. /* + * Revision 1.5 1997/12/18 04:07:02 curt + * Worked on properly translating and positioning the sky dome. + * * Revision 1.4 1997/12/17 23:13:36 curt * Began working on rendering a sky. * diff --git a/Main/views.h b/Main/views.h index 9e5d6a053..dd9bca168 100644 --- a/Main/views.h +++ b/Main/views.h @@ -31,14 +31,47 @@ #include "../Include/types.h" #include "../Flight/flight.h" #include "../Math/mat3.h" +#include "../Time/fg_time.h" /* Define a structure containing view information */ struct fgVIEW { + /* view position translated to scenery.center */ struct fgCartesianPoint view_pos; + + /* cartesion coordinates of current lon/lat if at sea level + * translated to scenery.center*/ struct fgCartesianPoint cur_zero_elev; - MAT3vec local_up, view_up, view_forward; - double view_offset, goal_view_offset; + + /* vector in cartesian coordinates from current position to the + * postion on the earth's surface the sun is directly over */ + MAT3vec to_sun; + + /* surface direction to go to head towards sun */ + MAT3vec surface_to_sun; + + /* surface vector heading south */ + MAT3vec surface_south; + + /* surface vector heading east (used to unambiguously align sky with sun) */ + MAT3vec surface_east; + + /* local up vector (normal to the plane tangent to the earth's + * surface at the spot we are directly above */ + MAT3vec local_up; + + /* up vector for the view (usually point straight up through the + * top of the aircraft */ + MAT3vec view_up; + + /* the vector pointing straight out the nose of the aircraft */ + MAT3vec view_forward; + + /* the current offset from forward for viewing */ + double view_offset; + + /* the goal view offset for viewing (used for smooth view changes) */ + double goal_view_offset; }; @@ -49,16 +82,19 @@ extern struct fgVIEW current_view; void fgViewInit(struct fgVIEW *v); /* Update the view parameters */ -void fgViewUpdate(struct fgFLIGHT *f, struct fgVIEW *v); +void fgViewUpdate(struct fgFLIGHT *f, struct fgVIEW *v, struct fgLIGHT *l); #endif /* VIEWS_H */ /* $Log$ -/* Revision 1.4 1997/12/17 23:13:36 curt -/* Began working on rendering a sky. +/* Revision 1.5 1997/12/22 04:14:32 curt +/* Aligned sky with sun so dusk/dawn effects can be correct relative to the sun. /* + * Revision 1.4 1997/12/17 23:13:36 curt + * Began working on rendering a sky. + * * Revision 1.3 1997/12/15 23:54:51 curt * Add xgl wrappers for debugging. * Generate terrain normals on the fly. diff --git a/Scenery/depend b/Scenery/depend index 5c3cceec6..aac38e422 100644 --- a/Scenery/depend +++ b/Scenery/depend @@ -5,8 +5,9 @@ astro.o: astro.c ../XGL/xgl.h astro.h stars.h moon.h orbits.h \ ../Time/../Flight/LaRCsim/../flight.h planets.h sun.h \ ../Include/constants.h ../Include/general.h ../Main/views.h \ ../Main/../Include/types.h ../Main/../Flight/flight.h \ - ../Main/../Math/mat3.h ../Aircraft/aircraft.h \ - ../Aircraft/../Flight/flight.h ../Aircraft/../Controls/controls.h \ + ../Main/../Math/mat3.h ../Main/../Time/fg_time.h \ + ../Aircraft/aircraft.h ../Aircraft/../Flight/flight.h \ + ../Aircraft/../Controls/controls.h \ ../Aircraft/../Controls/../Include/limits.h common.o: common.c common.h geometry.o: geometry.c geometry.h mesh.h @@ -19,7 +20,7 @@ moon.o: moon.c ../XGL/xgl.h orbits.h ../Time/fg_time.h \ ../Time/../Flight/LaRCsim/ls_interface.h \ ../Time/../Flight/LaRCsim/../flight.h moon.h ../Include/general.h \ ../Main/views.h ../Main/../Include/types.h ../Main/../Flight/flight.h \ - ../Main/../Math/mat3.h + ../Main/../Math/mat3.h ../Main/../Time/fg_time.h obj.o: obj.c ../XGL/xgl.h obj.h scenery.h ../Include/types.h \ ../Math/mat3.h orbits.o: orbits.c orbits.h ../Time/fg_time.h \ @@ -41,7 +42,8 @@ sky.o: sky.c ../XGL/xgl.h sky.h ../Time/fg_time.h \ ../Aircraft/../Flight/flight.h ../Aircraft/../Controls/controls.h \ ../Aircraft/../Controls/../Include/limits.h ../Flight/flight.h \ ../Include/constants.h ../Main/views.h ../Main/../Include/types.h \ - ../Main/../Flight/flight.h ../Main/../Math/mat3.h ../Math/fg_random.h + ../Main/../Flight/flight.h ../Main/../Math/mat3.h \ + ../Main/../Time/fg_time.h ../Math/fg_random.h stars.o: stars.c ../XGL/xgl.h orbits.h ../Time/fg_time.h \ ../Time/../Include/types.h ../Time/../Flight/flight.h \ ../Time/../Flight/Slew/slew.h \ @@ -51,10 +53,10 @@ stars.o: stars.c ../XGL/xgl.h orbits.h ../Time/fg_time.h \ ../Aircraft/../Flight/flight.h ../Aircraft/../Controls/controls.h \ ../Aircraft/../Controls/../Include/limits.h ../Main/views.h \ ../Main/../Include/types.h ../Main/../Flight/flight.h \ - ../Main/../Math/mat3.h + ../Main/../Math/mat3.h ../Main/../Time/fg_time.h sun.o: sun.c ../XGL/xgl.h ../Time/fg_time.h ../Time/../Include/types.h \ ../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \ ../Time/../Flight/LaRCsim/ls_interface.h \ ../Time/../Flight/LaRCsim/../flight.h ../Main/views.h \ ../Main/../Include/types.h ../Main/../Flight/flight.h \ - ../Main/../Math/mat3.h orbits.h sun.h + ../Main/../Math/mat3.h ../Main/../Time/fg_time.h orbits.h sun.h diff --git a/Scenery/sky.c b/Scenery/sky.c index a3844c0b7..662a33444 100644 --- a/Scenery/sky.c +++ b/Scenery/sky.c @@ -99,7 +99,7 @@ void fgSkyRender() { struct fgFLIGHT *f; struct fgLIGHT *l; struct fgVIEW *v; - float inner_color[4], middle_color[4], diff; + float inner_color[4], middle_color[4], diff, east_dot, dot, angle; int i; f = ¤t_aircraft.flight; @@ -125,6 +125,25 @@ void fgSkyRender() { xglPushMatrix(); + /* calculate the angle between v->surface_to_sun and + * v->surface_east. We do this so we can sort out the acos() + * ambiguity. I wish I could think of a more efficient way ... :-( */ + east_dot = MAT3_DOT_PRODUCT(v->surface_to_sun, v->surface_east); + printf(" East dot product = %.2f\n", east_dot); + + /* calculate the angle between v->surface_to_sun and + * v->surface_south. this is how much we have to rotate the sky + * for it to align with the sun */ + dot = MAT3_DOT_PRODUCT(v->surface_to_sun, v->surface_south); + printf(" Dot product = %.2f\n", dot); + if ( east_dot >= 0 ) { + angle = acos(dot); + } else { + angle = -acos(dot); + } + printf(" Sky needs to rotate = %.3f rads = %.1f degrees.\n", + angle, angle * RAD_TO_DEG); + /* Translate to view position */ xglTranslatef( v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z ); /* printf(" Translated to %.2f %.2f %.2f\n", @@ -135,6 +154,7 @@ void fgSkyRender() { FG_Latitude * RAD_TO_DEG); xglRotatef( FG_Longitude * RAD_TO_DEG, 0.0, 0.0, 1.0 ); xglRotatef( 90.0 - FG_Latitude * RAD_TO_DEG, 0.0, 1.0, 0.0 ); + xglRotatef( angle * RAD_TO_DEG, 0.0, 0.0, 1.0 ); /* Draw inner/center section of sky*/ xglBegin( GL_TRIANGLE_FAN ); @@ -156,8 +176,10 @@ void fgSkyRender() { xglVertex3fv( sky_inner[i] ); } xglColor4fv( middle_color ); + xglColor4f(1.0, 0.0, 0.0, 1.0); xglVertex3fv( sky_middle[0] ); xglColor4fv( inner_color ); + xglColor4f(1.0, 0.0, 0.0, 1.0); xglVertex3fv( sky_inner[0] ); xglEnd(); @@ -180,9 +202,12 @@ void fgSkyRender() { /* $Log$ -/* Revision 1.5 1997/12/19 23:34:59 curt -/* Lot's of tweaking with sky rendering and lighting. +/* Revision 1.6 1997/12/22 04:14:34 curt +/* Aligned sky with sun so dusk/dawn effects can be correct relative to the sun. /* + * Revision 1.5 1997/12/19 23:34:59 curt + * Lot's of tweaking with sky rendering and lighting. + * * Revision 1.4 1997/12/19 16:45:02 curt * Working on scene rendering order and options. * diff --git a/Time/depend b/Time/depend index 20661a2b4..c51e503d2 100644 --- a/Time/depend +++ b/Time/depend @@ -9,6 +9,6 @@ sunpos.o: sunpos.c sunpos.h ../Include/types.h fg_time.h \ ../Flight/LaRCsim/ls_interface.h ../Flight/LaRCsim/../flight.h \ ../Include/constants.h ../Main/views.h ../Main/../Include/types.h \ ../Main/../Flight/flight.h ../Main/../Math/mat3.h \ - ../Math/fg_geodesy.h ../Math/mat3.h ../Math/polar.h \ - ../Math/../Include/types.h + ../Main/../Time/fg_time.h ../Math/fg_geodesy.h ../Math/mat3.h \ + ../Math/polar.h ../Math/../Include/types.h ttest.o: ttest.c