remove some ugly while loops
This commit is contained in:
parent
d91a617423
commit
3abf0b5df1
2 changed files with 11 additions and 13 deletions
|
@ -401,8 +401,6 @@ void FGLight::update_adj_fog_color () {
|
|||
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() );
|
||||
|
||||
|
@ -421,10 +419,11 @@ void FGLight::updateSunPos()
|
|||
<< " 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());
|
||||
|
|
|
@ -65,13 +65,9 @@ void fgSunPositionGST(double gst, double *lon, double *lat) {
|
|||
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;
|
||||
|
@ -100,10 +96,13 @@ static double sun_angle( const SGTime &t, const SGVec3d& world_up,
|
|||
// << 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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue