void FGLight::updateSunPos()
{
SGTime *t = globals->get_time_params();
- FGViewer *v = globals->get_current_view();
-
SG_LOG( SG_EVENT, SG_DEBUG, " Updating Sun position" );
SG_LOG( SG_EVENT, SG_DEBUG, " Gst = " << t->getGst() );
<< " Geodcentric lat = " << _sun_lat );
// update the sun light vector
- sun_vec() = SGVec4f(toVec3f(normalize(sunpos)), 0);
- sun_vec_inv() = - sun_vec();
+ _sun_vec = SGVec4f(toVec3f(normalize(sunpos)), 0);
+ _sun_vec_inv = - _sun_vec;
// calculate the sun's relative angle to local up
+ FGViewer *v = globals->get_current_view();
SGVec3d viewPos = v->get_view_pos();
SGQuatd hlOr = SGQuatd::fromLonLat(SGGeod::fromCart(viewPos));
SGVec3d world_up = hlOr.backTransform(-SGVec3d::e3());
double dec = atan2(ze, sqrt(xs * xs + ye * ye));
tmp = ra - (SGD_2PI/24)*gst;
- if (tmp < -SGD_PI) {
- do tmp += SGD_2PI;
- while (tmp < -SGD_PI);
- } else if (tmp > SGD_PI) {
- do tmp -= SGD_2PI;
- while (tmp < -SGD_PI);
- }
+
+ double signnedPI = (tmp < 0.0) ? -SGD_PI : SGD_PI;
+ tmp = fmod(tmp+signnedPI, SGD_2PI) - signnedPI;
*lon = tmp;
*lat = dec;
// << nsun[2] << endl;
double sun_angle = acos( dot( nup, nsun ) );
+
+ double signnedPI = (sun_angle < 0.0) ? -SGD_PI : SGD_PI;
+ sun_angle = fmod(sun_angle+signnedPI, SGD_2PI) - signnedPI;
+
double sun_angle_deg = sun_angle * SG_RADIANS_TO_DEGREES;
- while ( sun_angle_deg < -180 ) { sun_angle += 360; }
SG_LOG( SG_EVENT, SG_DEBUG, "sun angle relative to current location = "
- << sun_angle_deg );
+ << sun_anglei_deg );
return sun_angle_deg;
}