1
0
Fork 0

Fix horizon sunrise/sunset effect position.

Fix sun position in default renderer. (Committing fix
provided after discussion on IRC + forum, no bug ID)
This commit is contained in:
James Turner 2013-08-07 16:30:20 +01:00
parent cff6b2034d
commit df4f574951

View file

@ -361,7 +361,10 @@ void FGLight::update_adj_fog_color () {
sif = 1e-4; sif = 1e-4;
// determine horizontal angle between current view direction and sun // determine horizontal angle between current view direction and sun
double hor_rotation = -_sun_rotation - SGD_PI_2 - heading + heading_offset; // since _sun_rotation is relative to South, and heading is in the local frame
// we need to account for the 180 degrees offset and differing signs
// hence the negation and SGD_PI adjustment.
double hor_rotation = -_sun_rotation - SGD_PI - heading + heading_offset;
if (hor_rotation < 0 ) if (hor_rotation < 0 )
hor_rotation = fmod(hor_rotation, SGD_2PI) + SGD_2PI; hor_rotation = fmod(hor_rotation, SGD_2PI) + SGD_2PI;
else else
@ -430,8 +433,14 @@ void FGLight::updateSunPos()
// Get direction to the sun in the local frame. // Get direction to the sun in the local frame.
SGVec3d local_sun_vec = hlOr.transform(nsun); SGVec3d local_sun_vec = hlOr.transform(nsun);
// Angle from south. // Angle from South.
_sun_rotation = 2.0 * atan2(local_sun_vec.x(), -local_sun_vec.y()); // atan2(y,x) returns the angle between the positive X-axis
// and the vector with the origin at 0, going through (x,y)
// Since the local frame coordinates have x-positive pointing Nord and
// y-positive pointing East we need to negate local_sun_vec.x()
// _sun_rotation is positive counterclockwise from South (sun in the East)
// and negative clockwise from South (sun in the West)
_sun_rotation = atan2(local_sun_vec.y(), -local_sun_vec.x());
// cout << " Sky needs to rotate = " << _sun_rotation << " rads = " // cout << " Sky needs to rotate = " << _sun_rotation << " rads = "
// << _sun_rotation * SGD_RADIANS_TO_DEGREES << " degrees." << endl; // << _sun_rotation * SGD_RADIANS_TO_DEGREES << " degrees." << endl;