From d3fdf74e4f1c52eae72a299dec39ce51d57e07f5 Mon Sep 17 00:00:00 2001 From: frohlich Date: Tue, 30 Jan 2007 20:14:25 +0000 Subject: [PATCH] Modified Files: light.cxx light.hxx sunsolver.cxx tmp.cxx: kick out sg.h --- src/Time/light.cxx | 3 +- src/Time/light.hxx | 10 ++---- src/Time/sunsolver.cxx | 27 ++++---------- src/Time/tmp.cxx | 82 +++++++++++++++--------------------------- 4 files changed, 39 insertions(+), 83 deletions(-) diff --git a/src/Time/light.cxx b/src/Time/light.cxx index 748584a57..debccf586 100644 --- a/src/Time/light.cxx +++ b/src/Time/light.cxx @@ -47,7 +47,6 @@ #include #include #include -#include #include #include #include @@ -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), diff --git a/src/Time/light.hxx b/src/Time/light.hxx index 9517adb81..84c32aa90 100644 --- a/src/Time/light.hxx +++ b/src/Time/light.hxx @@ -40,10 +40,6 @@ #include -#include SG_GL_H - -#include // plib include - #include #include #include @@ -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; } diff --git a/src/Time/sunsolver.cxx b/src/Time/sunsolver.cxx index 8a1a78e58..643fbb83a 100644 --- a/src/Time/sunsolver.cxx +++ b/src/Time/sunsolver.cxx @@ -29,19 +29,16 @@ #ifdef SG_HAVE_STD_INCLUDES # include -// # include # include # ifdef macintosh SG_USING_STD(time_t); # endif #else # include -// # include # include #endif -#include -#include +#include #include #include @@ -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; diff --git a/src/Time/tmp.cxx b/src/Time/tmp.cxx index 1533d1eb1..9c743e5a3 100644 --- a/src/Time/tmp.cxx +++ b/src/Time/tmp.cxx @@ -25,14 +25,11 @@ # include #endif +#include #include -#include -#include #include -#include #include -#include #include
#include
#include
@@ -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; -- 2.39.5