]> git.mxchange.org Git - flightgear.git/blobdiff - src/Time/moonpos.cxx
Get rid of the double comma's for the file section of the generic protocol also.
[flightgear.git] / src / Time / moonpos.cxx
index f63a32bdd0e719c03d7ec2058bfa872d8d99ef91..516048ddb92523e1e18d963089198dbefeb8f540 100644 (file)
 #include <simgear/math/polar3d.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/math/vector.hxx>
+#include <simgear/timing/sg_time.hxx>
 
 #include <Main/globals.hxx>
+#include <Main/viewer.hxx>
 #include <Scenery/scenery.hxx>
 #include <Time/light.hxx>
 
@@ -200,7 +202,7 @@ static double julian_date(int y, int m, int d) {
 
     /* lazy test to ensure gregorian calendar */
     if (y < 1583) {
-       FG_LOG( FG_EVENT, FG_ALERT, 
+       SG_LOG( SG_EVENT, SG_ALERT, 
                "WHOOPS! Julian dates only valid for 1582 oct 15 or later" );
     }
 
@@ -334,10 +336,8 @@ static void fgMoonPositionGST(double gst, double *lon, double *lat) {
 
 // update the cur_time_params structure with the current moon position
 void fgUpdateMoonPos( void ) {
-    fgLIGHT *l;
-    FGViewerRPH *v;
     sgVec3 nup, nmoon;
-    Point3D p, rel_moonpos;
+    Point3D rel_moonpos;
     double dot, east_dot;
     double moon_gd_lat, sl_radius;
 
@@ -348,41 +348,43 @@ void fgUpdateMoonPos( void ) {
     // surface direction to go to head towards moon
     sgVec3 surface_to_moon;
 
-    l = &cur_light_params;
+    FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
     SGTime *t = globals->get_time_params();
-    v = (FGViewerRPH *)globals->get_current_view();
+    FGViewer *v = globals->get_current_view();
 
-    FG_LOG( FG_EVENT, FG_INFO, "  Updating Moon position" );
+    SG_LOG( SG_EVENT, SG_INFO, "  Updating Moon position" );
 
-    // (not sure why there was two)
-    // fgMoonPosition(t->cur_time, &l->moon_lon, &moon_gd_lat);
-    fgMoonPositionGST(t->getGst(), &l->moon_lon, &moon_gd_lat);
+    double moon_l;
+    fgMoonPositionGST(t->getGst(), &moon_l, &moon_gd_lat);
+    l->set_moon_lon(moon_l);
 
-    sgGeodToGeoc(moon_gd_lat, 0.0, &sl_radius, &l->moon_gc_lat);
+    sgGeodToGeoc(moon_gd_lat, 0.0, &sl_radius, &moon_l);
+    l->set_moon_gc_lat(moon_l);
 
-    p = Point3D( l->moon_lon, l->moon_gc_lat, sl_radius );
-    l->fg_moonpos = sgPolarToCart3d(p);
+    Point3D p = Point3D( l->get_moon_lon(), l->get_moon_gc_lat(), sl_radius );
+    l->set_moonpos( sgPolarToCart3d(p) );
 
-    FG_LOG( FG_EVENT, FG_INFO, "    t->cur_time = " << t->get_cur_time() );
-    FG_LOG( FG_EVENT, FG_INFO, 
+    SG_LOG( SG_EVENT, SG_INFO, "    t->cur_time = " << t->get_cur_time() );
+    SG_LOG( SG_EVENT, SG_INFO, 
            "    Moon Geodetic lat = " << moon_gd_lat
-           << " Geocentric lat = " << l->moon_gc_lat );
+           << " Geocentric lat = " << l->get_moon_gc_lat() );
 
     // update the sun light vector
-    sgSetVec4( l->moon_vec,
-              l->fg_moonpos.x(), l->fg_moonpos.y(), l->fg_moonpos.z(), 0.0 );
-    sgNormalizeVec4( l->moon_vec );
-    sgCopyVec4( l->moon_vec_inv, l->moon_vec );
-    sgNegateVec4( l->moon_vec_inv );
+    sgSetVec4( l->moon_vec(), l->get_moonpos().x(),
+              l->get_moonpos().y(), l->get_moonpos().z(), 0.0 );
+    sgNormalizeVec4( l->moon_vec() );
+    sgCopyVec4( l->moon_vec_inv(), l->moon_vec() );
+    sgNegateVec4( l->moon_vec_inv() );
 
     // make sure these are directional light sources only
-    l->moon_vec[3] = l->moon_vec_inv[3] = 0.0;
+    l->moon_vec()[3] = l->moon_vec_inv()[3] = 0.0;
     // cout << "  l->moon_vec = " << l->moon_vec[0] << "," << l->moon_vec[1]
     //      << ","<< l->moon_vec[2] << endl;
 
     // calculate the moon's relative angle to local up
     sgCopyVec3( nup, v->get_world_up() );
-    sgSetVec3( nmoon, l->fg_moonpos.x(), l->fg_moonpos.y(), l->fg_moonpos.z() );
+    sgSetVec3( nmoon, l->get_moonpos().x(),
+               l->get_moonpos().y(), l->get_moonpos().z() );
     sgNormalizeVec3(nup);
     sgNormalizeVec3(nmoon);
     // cout << "nup = " << nup[0] << "," << nup[1] << "," 
@@ -390,15 +392,15 @@ void fgUpdateMoonPos( void ) {
     // cout << "nmoon = " << nmoon[0] << "," << nmoon[1] << "," 
     //      << nmoon[2] << endl;
 
-    l->moon_angle = acos( sgScalarProductVec3( nup, nmoon ) );
-    FG_LOG( FG_EVENT, FG_INFO, "moon angle relative to current location = " 
-           << l->moon_angle );
+    l->set_moon_angle( acos( sgScalarProductVec3( nup, nmoon ) ) );
+    SG_LOG( SG_EVENT, SG_INFO, "moon angle relative to current location = " 
+           << l->get_moon_angle() );
     
     // calculate vector to moon's position on the earth's surface
     Point3D vp( v->get_view_pos()[0],
                v->get_view_pos()[1],
                v->get_view_pos()[2] );
-    rel_moonpos = l->fg_moonpos - ( vp + scenery.center );
+    rel_moonpos = l->get_moonpos()-(vp + globals->get_scenery()->get_center());
     sgSetVec3( to_moon, rel_moonpos.x(), rel_moonpos.y(), rel_moonpos.z() );
     // printf( "Vector to moon = %.2f %.2f %.2f\n",
     //         to_moon[0], to_moon[1], to_moon[2]);
@@ -430,12 +432,12 @@ void fgUpdateMoonPos( void ) {
     // cout << "  Dot product = " << dot << endl;
 
     if ( east_dot >= 0 ) {
-       l->moon_rotation = acos(dot);
+       l->set_moon_rotation( acos(dot) );
     } else {
-       l->moon_rotation = -acos(dot);
+       l->set_moon_rotation( -acos(dot) );
     }
     // cout << "  Sky needs to rotate = " << angle << " rads = "
-    //      << angle * RAD_TO_DEG << " degrees." << endl;
+    //      << angle * SGD_RADIANS_TO_DEGREES << " degrees." << endl;
 }