]> git.mxchange.org Git - flightgear.git/blobdiff - Astro/celestialBody.cxx
Changes contributed by Durk Talsma:
[flightgear.git] / Astro / celestialBody.cxx
index ede620fe1ac0fd88e32e88785dcbb773965a5135..8af66d78b6cd7aaedc847d6fda7e6990fac5cbd5 100644 (file)
 
 #include "celestialBody.hxx"
 #include "star.hxx"
-#include <Debug/fg_debug.h>
+#include <Debug/logstream.hxx>
+
+#ifdef FG_MATH_EXCEPTION_CLASH
+#  define exception c_exception
+#endif
+#include <math.h>
 
 /**************************************************************************
  * void CelestialBody::updatePosition(fgTIME *t, Star *ourSun)
@@ -72,20 +77,35 @@ void CelestialBody::updatePosition(fgTIME *t, Star *ourSun)
   xg = xh + ourSun->getxs();
   yg = yh + ourSun->getys();
   zg = zh;
-  
+
+  lonEcl = atan2(yh, xh);
+  latEcl = atan2(zh, sqrt(xh*xh+yh*yh));
+
   xe = xg;
   ye = yg * cos(ecl) - zg * sin(ecl);
   ze = yg * sin(ecl) + zg * cos(ecl);
   rightAscension = atan2(ye, xe);
   declination = atan2(ze, sqrt(xe*xe + ye*ye));
-  fgPrintf(FG_GENERAL, FG_INFO, "Planet found at : %f (ra), %f (dec)\n", 
-          rightAscension, declination);
+  FG_LOG(FG_GENERAL, FG_INFO, "Planet found at : " 
+        << rightAscension << " (ra), " << declination << " (dec)" );
 
   //calculate some variables specific to calculating the magnitude 
   //of the planet
   R = sqrt (xg*xg + yg*yg + zg*zg);
   s = ourSun->getDistance();
-  FV = RAD_TO_DEG * acos( (r*r + R*R - s*s) / (2*r*R));
+
+  // It is possible from these calculations for the argument to acos
+  // to exceed the valid range for acos(). So we do a little extra
+  // checking.
+
+  double tmp = (r*r + R*R - s*s) / (2*r*R);
+  if ( tmp > 1.0) { 
+      tmp = 1.0;
+  } else if ( tmp < -1.0) {
+      tmp = -1.0;
+  }
+
+  FV = RAD_TO_DEG * acos( tmp );
 };
 
 /****************************************************************************
@@ -150,3 +170,8 @@ double CelestialBody::fgCalcEccAnom(double M, double e)
 
 
 
+
+
+
+
+