1
0
Fork 0

fg_time.cxx: Removed call to ctime() in a printf() which should be harmless

but seems to be triggering a bug.
light.cxx: Added code to adjust fog color based on sunrise/sunset effects
  and view orientation.  This is an attempt to match the fog color to the
  sky color in the center of the screen.  You see discrepancies at the
  edges, but what else can be done?
sunpos.cxx: Caculate local direction to sun here.  (what compass direction
  do we need to face to point directly at sun)
This commit is contained in:
curt 1998-07-22 21:45:37 +00:00
parent f8356621c1
commit ffa2a0feb3
4 changed files with 152 additions and 12 deletions

View file

@ -268,7 +268,9 @@ time_t get_start_gmt(int year) {
long int start = mktime(&mt);
fgPrintf( FG_EVENT, FG_DEBUG, "start1 = %ld\n", start);
fgPrintf( FG_EVENT, FG_DEBUG, "start2 = %s", ctime(&start));
// the ctime() call can screw up time progression on some versions
// of Linux
// fgPrintf( FG_EVENT, FG_DEBUG, "start2 = %s", ctime(&start));
fgPrintf( FG_EVENT, FG_DEBUG, "(tm_isdst = %d)\n", mt.tm_isdst);
timezone = fix_up_timezone( timezone );
@ -407,6 +409,16 @@ void fgTimeUpdate(fgFLIGHT *f, fgTIME *t) {
// $Log$
// Revision 1.11 1998/07/22 21:45:37 curt
// fg_time.cxx: Removed call to ctime() in a printf() which should be harmless
// but seems to be triggering a bug.
// light.cxx: Added code to adjust fog color based on sunrise/sunset effects
// and view orientation. This is an attempt to match the fog color to the
// sky color in the center of the screen. You see discrepancies at the
// edges, but what else can be done?
// sunpos.cxx: Caculate local direction to sun here. (what compass direction
// do we need to face to point directly at sun)
//
// Revision 1.10 1998/07/13 21:02:07 curt
// Wrote access functions for current fgOPTIONS.
//

View file

@ -35,6 +35,7 @@
#include <string.h>
#include <Aircraft/aircraft.h>
#include <Debug/fg_debug.h>
#include <Include/fg_constants.h>
#include <Main/options.hxx>
@ -89,6 +90,7 @@ void fgLIGHT::Init( void ) {
// update lighting parameters based on current sun position
void fgLIGHT::Update( void ) {
fgFLIGHT *f;
fgTIME *t;
fgVIEW *v;
// if the 4th field is 0.0, this specifies a direction ...
@ -99,6 +101,7 @@ void fgLIGHT::Update( void ) {
GLfloat base_fog_color[4] = {0.90, 0.90, 1.00, 1.0};
double deg, ambient, diffuse, sky_brightness;
f = current_aircraft.flight;
t = &cur_time_params;
v = &current_view;
@ -132,17 +135,80 @@ void fgLIGHT::Update( void ) {
scene_diffuse[1] = white[1] * diffuse;
scene_diffuse[2] = white[2] * diffuse;
// set fog color
fog_color[0] = base_fog_color[0] * sky_brightness;
fog_color[1] = base_fog_color[1] * sky_brightness;
fog_color[2] = base_fog_color[2] * sky_brightness;
fog_color[3] = base_fog_color[3];
// set sky color
sky_color[0] = base_sky_color[0] * sky_brightness;
sky_color[1] = base_sky_color[1] * sky_brightness;
sky_color[2] = base_sky_color[2] * sky_brightness;
sky_color[3] = base_sky_color[3];
// set fog color
fog_color[0] = base_fog_color[0] * sky_brightness;
fog_color[1] = base_fog_color[1] * sky_brightness;
fog_color[2] = base_fog_color[2] * sky_brightness;
fog_color[3] = base_fog_color[3];
}
// calculate fog color adjusted for sunrise/sunset effects
void fgLIGHT::UpdateAdjFog( void ) {
fgFLIGHT *f;
fgVIEW *v;
double sun_angle_deg, rotation, param1[3], param2[3];
f = current_aircraft.flight;
v = &current_view;
fgPrintf( FG_EVENT, FG_DEBUG, "Updating adjusted fog parameters.\n" );
// set fog color (we'll try to match the sunset color in the
// direction we are looking
// first determine the difference between our view angle and local
// direction to the sun
rotation = -(sun_rotation + FG_PI) - (FG_Psi - v->view_offset) ;
while ( rotation < 0 ) {
rotation += FG_2PI;
}
while ( rotation > FG_2PI ) {
rotation -= FG_2PI;
}
rotation *= RAD_TO_DEG;
fgPrintf( FG_EVENT, FG_INFO,
" View to sun difference in degrees = %.2f\n", rotation);
// next check if we are in a sunset/sunrise situation
sun_angle_deg = sun_angle * RAD_TO_DEG;
if ( (sun_angle_deg > 80.0) && (sun_angle_deg < 100.0) ) {
/* 0.0 - 0.4 */
param1[0] = (10.0 - fabs(90.0 - sun_angle_deg)) / 25.0;
param1[1] = (10.0 - fabs(90.0 - sun_angle_deg)) / 35.0;
param1[2] = 0.0;
} else {
param1[0] = param1[1] = param1[2] = 0.0;
}
if ( rotation - 180.0 <= 0.0 ) {
param2[0] = param1[0] * (180.0 - rotation) / 180.0;
param2[1] = param1[1] * (180.0 - rotation) / 180.0;
param2[2] = param1[2] * (180.0 - rotation) / 180.0;
printf("param1[0] = %.2f param2[0] = %.2f\n", param1[0], param2[0]);
} else {
param2[0] = param1[0] * (rotation - 180.0) / 180.0;
param2[1] = param1[1] * (rotation - 180.0) / 180.0;
param2[2] = param1[2] * (rotation - 180.0) / 180.0;
printf("param1[0] = %.2f param2[0] = %.2f\n", param1[0], param2[0]);
}
adj_fog_color[0] = fog_color[0] + param2[0];
if ( adj_fog_color[0] > 1.0 ) { adj_fog_color[0] = 1.0; }
adj_fog_color[1] = fog_color[1] + param2[1];
if ( adj_fog_color[1] > 1.0 ) { adj_fog_color[1] = 1.0; }
adj_fog_color[2] = fog_color[2] + param2[2];
if ( adj_fog_color[2] > 1.0 ) { adj_fog_color[2] = 1.0; }
adj_fog_color[3] = fog_color[3];
}
@ -161,6 +227,16 @@ void fgLightUpdate ( void ) {
// $Log$
// Revision 1.12 1998/07/22 21:45:38 curt
// fg_time.cxx: Removed call to ctime() in a printf() which should be harmless
// but seems to be triggering a bug.
// light.cxx: Added code to adjust fog color based on sunrise/sunset effects
// and view orientation. This is an attempt to match the fog color to the
// sky color in the center of the screen. You see discrepancies at the
// edges, but what else can be done?
// sunpos.cxx: Caculate local direction to sun here. (what compass direction
// do we need to face to point directly at sun)
//
// Revision 1.11 1998/07/13 21:02:08 curt
// Wrote access functions for current fgOPTIONS.
//

View file

@ -70,9 +70,15 @@ public:
// inverse (in view coordinates)
GLfloat sun_vec_inv[4];
// the angle between the sun and the local horizontal
// the angle between the sun and the local horizontal (in radians)
double sun_angle;
// the rotation around our vertical axis of the sun (relative to
// due south with positive numbers going in the counter clockwise
// direction.) This is the direction we'd need to face if we
// wanted to travel towards the sun.
double sun_rotation;
///////////////////////////////////////////////////////////
// Derived lighting values
@ -85,6 +91,9 @@ public:
// fog color
GLfloat fog_color[4];
// fog color adjusted for sunset effects
GLfloat adj_fog_color[4];
// clear screen color
GLfloat sky_color[4];
@ -97,6 +106,9 @@ public:
// update lighting parameters based on current sun position
void Update( void);
// calculate fog color adjusted for sunrise/sunset effects
void UpdateAdjFog( void );
// Destructor
~fgLIGHT( void );
};
@ -114,6 +126,16 @@ void fgLightUpdate ( void );
// $Log$
// Revision 1.6 1998/07/22 21:45:39 curt
// fg_time.cxx: Removed call to ctime() in a printf() which should be harmless
// but seems to be triggering a bug.
// light.cxx: Added code to adjust fog color based on sunrise/sunset effects
// and view orientation. This is an attempt to match the fog color to the
// sky color in the center of the screen. You see discrepancies at the
// edges, but what else can be done?
// sunpos.cxx: Caculate local direction to sun here. (what compass direction
// do we need to face to point directly at sun)
//
// Revision 1.5 1998/07/08 14:48:39 curt
// polar3d.h renamed to polar3d.hxx
//

View file

@ -277,6 +277,7 @@ void fgUpdateSunPos( void ) {
fgVIEW *v;
MAT3vec nup, nsun, v0;
fgPoint3d p;
double dot, east_dot;
double sun_gd_lat, sl_radius;
double ntmp;
@ -311,8 +312,8 @@ void fgUpdateSunPos( void ) {
l->sun_vec[3] = 0.0;
l->sun_vec_inv[3] = 0.0;
printf(" l->sun_vec = %.2f %.2f %.2f\n", l->sun_vec[0], l->sun_vec[1],
l->sun_vec[2]);
// printf(" l->sun_vec = %.2f %.2f %.2f\n", l->sun_vec[0], l->sun_vec[1],
// l->sun_vec[2]);
// calculate the sun's relative angle to local up
MAT3_COPY_VEC(nup, v->local_up);
@ -323,8 +324,8 @@ void fgUpdateSunPos( void ) {
MAT3_NORMALIZE_VEC(nsun, ntmp);
l->sun_angle = acos(MAT3_DOT_PRODUCT(nup, nsun));
printf(" SUN ANGLE relative to current location = %.3f rads.\n",
l->sun_angle);
// printf(" SUN ANGLE relative to current location = %.3f rads.\n",
// l->sun_angle);
// 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);
@ -346,10 +347,39 @@ void fgUpdateSunPos( void ) {
// 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));
// 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 ) {
l->sun_rotation = acos(dot);
} else {
l->sun_rotation = -acos(dot);
}
// printf(" Sky needs to rotate = %.3f rads = %.1f degrees.\n",
// angle, angle * RAD_TO_DEG); */
}
// $Log$
// Revision 1.10 1998/07/22 21:45:39 curt
// fg_time.cxx: Removed call to ctime() in a printf() which should be harmless
// but seems to be triggering a bug.
// light.cxx: Added code to adjust fog color based on sunrise/sunset effects
// and view orientation. This is an attempt to match the fog color to the
// sky color in the center of the screen. You see discrepancies at the
// edges, but what else can be done?
// sunpos.cxx: Caculate local direction to sun here. (what compass direction
// do we need to face to point directly at sun)
//
// Revision 1.9 1998/07/08 14:48:39 curt
// polar3d.h renamed to polar3d.hxx
//