- double beta = globals->get_ephem()->get_sun()->getLat();
- double r = globals->get_ephem()->get_sun()->getDistance();
- double xs = globals->get_ephem()->get_sun()->getxs();
- double ys = globals->get_ephem()->get_sun()->getys();
- double ye = globals->get_ephem()->get_sun()->getye();
- double ze = globals->get_ephem()->get_sun()->getze();
- alpha = atan2(ys - tan(beta)*ze/ys, xs);
- delta = asin(sin(beta)*ye/ys + cos(beta)*ze);
-
- tmp = alpha - (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);
- }
+ SGPropertyNode* sun = fgGetNode("/ephemeris/sun");
+ assert(sun);
+ double xs = sun->getDoubleValue("xs");
+ //double ys = sun->getDoubleValue("ys");
+ double ye = sun->getDoubleValue("ye");
+ double ze = sun->getDoubleValue("ze");
+ double ra = atan2(ye, xs);
+ double dec = atan2(ze, sqrt(xs * xs + ye * ye));
+
+ tmp = ra - (SGD_2PI/24)*gst;
+
+ double signedPI = (tmp < 0.0) ? -SGD_PI : SGD_PI;
+ tmp = fmod(tmp+signedPI, SGD_2PI) - signedPI;