]> git.mxchange.org Git - flightgear.git/commitdiff
Modified Files:
authorfrohlich <frohlich>
Tue, 30 Jan 2007 20:14:25 +0000 (20:14 +0000)
committerfrohlich <frohlich>
Tue, 30 Jan 2007 20:14:25 +0000 (20:14 +0000)
  light.cxx light.hxx sunsolver.cxx tmp.cxx: kick out sg.h

src/Time/light.cxx
src/Time/light.hxx
src/Time/sunsolver.cxx
src/Time/tmp.cxx

index 748584a5752a55ceb8a0deab9098a2a0ed5bd312..debccf586e70f4b49a145aba269f500523b24c07 100644 (file)
@@ -47,7 +47,6 @@
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/interpolater.hxx>
-#include <simgear/math/polar3d.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/scene/sky/sky.hxx>
 #include <simgear/screen/colors.hxx>
@@ -69,7 +68,7 @@ FGLight::FGLight ()
       _specular_tbl( NULL ),
       _sky_tbl( NULL ),
       _sun_lon(0),
-      _sun_gc_lat(0),
+      _sun_lat(0),
       _moon_lon(0),
       _moon_gc_lat(0),
       _sunpos(0, 0, 0),
index 9517adb8191da47fe353f2385e8eae153bbbb2f8..84c32aa90d591f0699514abd96e50cb60111eb7f 100644 (file)
 
 #include <simgear/compiler.h>
 
-#include SG_GL_H
-
-#include <plib/sg.h>                   // plib include
-
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/math/interpolater.hxx>
 #include <simgear/math/point3d.hxx>
@@ -66,7 +62,7 @@ private:
      */
 
     // in geocentric coordinates
-    double _sun_lon, _sun_gc_lat;
+    double _sun_lon, _sun_lat;
     double _moon_lon, _moon_gc_lat;
 
     // in cartesian coordiantes
@@ -146,8 +142,8 @@ public:
     inline double get_sun_lon () const { return _sun_lon; }
     inline void set_sun_lon (double l) { _sun_lon = l; }
 
-    inline double get_sun_gc_lat () const { return _sun_gc_lat; }
-    inline void set_sun_gc_lat (double l) { _sun_gc_lat = l; }
+    inline double get_sun_lat () const { return _sun_lat; }
+    inline void set_sun_lat (double l) { _sun_lat = l; }
 
     inline const SGVec3d& get_sunpos () const { return _sunpos; }
     inline void set_sunpos (const SGVec3d& p) { _sunpos = p; }
index 8a1a78e586df1b9d76bb805f1c286ffc74db0db9..643fbb83a37277d2b89ed9409a971868257fc6a2 100644 (file)
 
 #ifdef SG_HAVE_STD_INCLUDES
 #  include <cmath>
-// #  include <cstdio>
 #  include <ctime>
 #  ifdef macintosh
      SG_USING_STD(time_t);
 #  endif
 #else
 #  include <math.h>
-// #  include <stdio.h>
 #  include <time.h>
 #endif
 
-#include <simgear/math/point3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
+#include <simgear/math/SGMath.hxx>
 #include <simgear/ephemeris/ephemeris.hxx>
 #include <simgear/timing/sg_time.hxx>
 
@@ -64,7 +61,6 @@ void fgSunPositionGST(double gst, double *lon, double *lat) {
     /* double *lat;            (return) latitude        */
     /* double *lon;            (return) longitude       */
 
-    /* double lambda; */
     double alpha, delta;
     double tmp;
 
@@ -77,7 +73,6 @@ void fgSunPositionGST(double gst, double *lon, double *lat) {
     alpha = atan2(ys - tan(beta)*ze/ys, xs);
     delta = asin(sin(beta)*ye/ys + cos(beta)*ze);
 
-    // tmp = alpha - (SGD_2PI/24)*GST(ssue);
     tmp = alpha - (SGD_2PI/24)*gst;
     if (tmp < -SGD_PI) {
         do tmp += SGD_2PI;
@@ -91,33 +86,28 @@ void fgSunPositionGST(double gst, double *lon, double *lat) {
     *lat = delta;
 }
 
-static double sun_angle( const SGTime &t, sgVec3 world_up,
+static double sun_angle( const SGTime &t, const SGVec3d& world_up,
                          double lon_rad, double lat_rad ) {
-    sgVec3 nup, nsun;
-    Point3D p, rel_sunpos;
-
     SG_LOG( SG_EVENT, SG_DEBUG, "  Updating Sun position" );
     SG_LOG( SG_EVENT, SG_DEBUG, "  Gst = " << t.getGst() );
 
     double sun_lon, sun_gd_lat;
     fgSunPositionGST( t.getGst(), &sun_lon, &sun_gd_lat );
-    Point3D sunpos = sgGeodToCart(Point3D(sun_lon, sun_gd_lat, 0));
+    SGVec3d sunpos = SGVec3d::fromGeod(SGGeod::fromRad(sun_lon, sun_gd_lat));
 
     SG_LOG( SG_EVENT, SG_DEBUG, "    t.cur_time = " << t.get_cur_time() );
     SG_LOG( SG_EVENT, SG_DEBUG, 
            "    Sun Geodetic lat = " << sun_gd_lat );
 
     // calculate the sun's relative angle to local up
-    sgCopyVec3( nup, world_up );
-    sgSetVec3( nsun, sunpos.x(), sunpos.y(), sunpos.z() );
-    sgNormalizeVec3(nup);
-    sgNormalizeVec3(nsun);
+    SGVec3f nup = normalize(toVec3f(world_up));
+    SGVec3f nsun = normalize(toVec3f(sunpos));
     // cout << "nup = " << nup[0] << "," << nup[1] << "," 
     //      << nup[2] << endl;
     // cout << "nsun = " << nsun[0] << "," << nsun[1] << "," 
     //      << nsun[2] << endl;
 
-    double sun_angle = acos( sgScalarProductVec3 ( nup, nsun ) );
+    double sun_angle = acos( dot( nup, nsun ) );
     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 = "
@@ -143,10 +133,7 @@ time_t fgTimeSecondsUntilSunAngle( time_t cur_time,
 {
     // cout << "location = " << lon_rad * SG_RADIANS_TO_DEGREES << ", "
     //      << lat_rad * SG_RADIANS_TO_DEGREES << endl;
-    Point3D geod( lon_rad, lat_rad, 0 );
-    Point3D tmp = sgGeodToCart( geod );
-    sgVec3 world_up;
-    sgSetVec3( world_up, tmp.x(), tmp.y(), tmp.z() );
+    SGVec3d world_up = SGVec3d::fromGeod(SGGeod::fromRad(lon_rad, lat_rad));
     SGTime t = SGTime( lon_rad, lat_rad, "", 0 );
 
     double best_diff = 180.0;
index 1533d1eb1f3413beee08778098d86a99503cdd71..9c743e5a3626422f05ab1733160447093f65da08 100644 (file)
 #  include <config.h>
 #endif
 
+#include <simgear/math/SGMath.hxx>
 #include <simgear/math/vector.hxx>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/sg_path.hxx>
-#include <simgear/magvar/magvar.hxx>
 #include <simgear/timing/sg_time.hxx>
 
-#include <FDM/flight.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 #include <Main/viewer.hxx>
@@ -68,17 +65,6 @@ void fgUpdateLocalTime() {
 
 // update the cur_time_params structure with the current sun position
 void fgUpdateSunPos( void ) {
-    sgVec3 nup, nsun;
-    double dot, east_dot;
-    double sun_gd_lat, sl_radius;
-
-    // vector in cartesian coordinates from current position to the
-    // postion on the earth's surface the sun is directly over
-    sgVec3 to_sun;
-
-    // surface direction to go to head towards sun
-    sgVec3 surface_to_sun;
-
     FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
     SGTime *t = globals->get_time_params();
     FGViewer *v = globals->get_current_view();
@@ -87,53 +73,39 @@ void fgUpdateSunPos( void ) {
     SG_LOG( SG_EVENT, SG_DEBUG, "  Gst = " << t->getGst() );
 
     double sun_l;
+    double sun_gd_lat;
     fgSunPositionGST(t->getGst(), &sun_l, &sun_gd_lat);
     l->set_sun_lon(sun_l);
-
-    sgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &sun_l);
-    l->set_sun_gc_lat(sun_l);
-
-    SGGeoc geocSun = SGGeoc::fromRadM( l->get_sun_lon(), l->get_sun_gc_lat(),
-                                       sl_radius );
-    l->set_sunpos( SGVec3d::fromGeoc(geocSun) );
+    l->set_sun_lat(sun_gd_lat);
+    l->set_sunpos(SGVec3d::fromGeod(SGGeod::fromRad(sun_l, sun_gd_lat)));
 
     SG_LOG( SG_EVENT, SG_DEBUG, "    t->cur_time = " << t->get_cur_time() );
     SG_LOG( SG_EVENT, SG_DEBUG,
            "    Sun Geodetic lat = " << sun_gd_lat
-           << " Geocentric lat = " << l->get_sun_gc_lat() );
+           << " Geodetic lat = " << sun_gd_lat );
 
     // update the sun light vector
-    sgSetVec4( l->sun_vec().data(), l->get_sunpos().x(),
-              l->get_sunpos().y(), l->get_sunpos().z(), 0.0 );
-    sgNormalizeVec4( l->sun_vec().data() );
-    sgCopyVec4( l->sun_vec_inv().data(), l->sun_vec().data() );
-    sgNegateVec4( l->sun_vec_inv().data() );
-
-    // make sure these are directional light sources only
-    l->sun_vec()[3] = l->sun_vec_inv()[3] = 0.0;
-    // cout << "  l->sun_vec = " << l->sun_vec[0] << "," << l->sun_vec[1]
-    //      << ","<< l->sun_vec[2] << endl;
+    l->sun_vec() = SGVec4f(toVec3f(normalize(l->get_sunpos())), 0);
+    l->sun_vec_inv() = - l->sun_vec();
 
     // calculate the sun's relative angle to local up
-    sgCopyVec3( nup, v->get_world_up().data() );
-    sgSetVec3( nsun, l->get_sunpos().x(),
-               l->get_sunpos().y(), l->get_sunpos().z() );
-    sgNormalizeVec3(nup);
-    sgNormalizeVec3(nsun);
+    SGVec3f nup(normalize(v->get_world_up()));
+    SGVec3f nsun(toVec3f(normalize(l->get_sunpos())));
     // cout << "nup = " << nup[0] << "," << nup[1] << "," 
     //      << nup[2] << endl;
     // cout << "nsun = " << nsun[0] << "," << nsun[1] << "," 
     //      << nsun[2] << endl;
 
-    l->set_sun_angle( acos( sgScalarProductVec3 ( nup, nsun ) ) );
+    l->set_sun_angle( acos( dot ( nup, nsun ) ) );
     SG_LOG( SG_EVENT, SG_DEBUG, "sun angle relative to current location = "
            << l->get_sun_angle() );
     
     // calculate vector to sun's position on the earth's surface
     SGVec3d rel_sunpos = globals->get_scenery()->get_center();
-    SGVec3f vp( v->get_view_pos() );
-    rel_sunpos += l->get_sunpos() - toVec3d(vp);
-    sgSetVec3( to_sun, rel_sunpos.x(), rel_sunpos.y(), rel_sunpos.z() );
+    rel_sunpos += l->get_sunpos() - toVec3d(v->get_view_pos());
+    // vector in cartesian coordinates from current position to the
+    // postion on the earth's surface the sun is directly over
+    SGVec3f to_sun = toVec3f(rel_sunpos);
     // printf( "Vector to sun = %.2f %.2f %.2f\n",
     //         v->to_sun[0], v->to_sun[1], v->to_sun[2]);
 
@@ -143,9 +115,11 @@ void fgUpdateSunPos( void ) {
 
     SGVec3f world_up = v->get_world_up();
     SGVec3f view_pos = v->get_view_pos();
+    // surface direction to go to head towards sun
+    SGVec3f surface_to_sun;
     sgmap_vec_onto_cur_surface_plane( world_up.data(), view_pos.data(),
-                                     to_sun, surface_to_sun );
-    sgNormalizeVec3(surface_to_sun);
+                                     to_sun.data(), surface_to_sun.data() );
+    surface_to_sun = normalize(surface_to_sun);
     // cout << "(sg) Surface direction to sun is "
     //   << surface_to_sun[0] << "," 
     //   << surface_to_sun[1] << ","
@@ -157,30 +131,30 @@ void fgUpdateSunPos( void ) {
     // v->get_surface_east().  We do this so we can sort out the
     // acos() ambiguity.  I wish I could think of a more efficient
     // way. :-(
-    east_dot = sgScalarProductVec3( surface_to_sun, v->get_surface_east().data() );
+    float east_dot = dot( surface_to_sun, v->get_surface_east() );
     // cout << "  East dot product = " << east_dot << endl;
 
     // calculate the angle between v->surface_to_sun and
     // v->surface_south.  this is how much we have to rotate the sky
     // for it to align with the sun
-    dot = sgScalarProductVec3( surface_to_sun, v->get_surface_south().data() );
+    float dot_ = dot( surface_to_sun, v->get_surface_south() );
     // cout << "  Dot product = " << dot << endl;
 
-    if (dot > 1.0) {
+    if (dot_ > 1.0) {
         SG_LOG( SG_ASTRO, SG_INFO,
-                "Dot product  = " << dot << " is greater than 1.0" );
-        dot = 1.0;
+                "Dot product  = " << dot_ << " is greater than 1.0" );
+        dot_ = 1.0;
     }
-    else if (dot < -1.0) {
+    else if (dot_ < -1.0) {
          SG_LOG( SG_ASTRO, SG_INFO,
-                 "Dot product  = " << dot << " is less than -1.0" );
-         dot = -1.0;
+                 "Dot product  = " << dot_ << " is less than -1.0" );
+         dot_ = -1.0;
      }
 
     if ( east_dot >= 0 ) {
-       l->set_sun_rotation( acos(dot) );
+       l->set_sun_rotation( acos(dot_) );
     } else {
-       l->set_sun_rotation( -acos(dot) );
+       l->set_sun_rotation( -acos(dot_) );
     }
     // cout << "  Sky needs to rotate = " << angle << " rads = "
     //      << angle * SGD_RADIANS_TO_DEGREES << " degrees." << endl;