]> git.mxchange.org Git - flightgear.git/commitdiff
Minor API changes to support the new sg_geodesy implementation. A few
authorandy <andy>
Fri, 19 Dec 2003 02:42:32 +0000 (02:42 +0000)
committerandy <andy>
Fri, 19 Dec 2003 02:42:32 +0000 (02:42 +0000)
places now use sgCartToGeod() instead of rolling their own
approximation.  And YASim is now using exactly the same 3D coordinate
system as the rest of FlightGear is.

src/ATC/AIEntity.cxx
src/ATC/ATC.hxx
src/ATC/approach.cxx
src/FDM/YASim/Glue.cpp
src/FDM/YASim/Glue.hpp
src/FDM/YASim/YASim.cxx
src/Instrumentation/gps.cxx
src/Main/main.cxx
src/Navaids/ils.hxx
src/Scenery/hitlist.cxx
src/Time/sunsolver.cxx

index 88945a1efbe1381c50b1e4a48f9f46bfc2f208ba..2b333cfdbae1593c33c6a8c3be373ab003d8cdad 100644 (file)
@@ -32,7 +32,7 @@
 
 #include <Main/globals.hxx>
 #include <Scenery/scenery.hxx>
-//#include <simgear/constants.h>
+#include <simgear/constants.h>
 #include <simgear/math/point3d.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/sg_path.hxx>
index 8c7210dc236a7a6aff2ee21df5588879634de1e8..adc5f2d8ef49cde3240aeffe6d7de656080791c1 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef _FG_ATC_HXX
 #define _FG_ATC_HXX
 
+#include <simgear/constants.h>
 #include <simgear/compiler.h>
 #include <simgear/misc/sgstream.hxx>
 #include <simgear/math/sg_geodesy.hxx>
index 2f291779755493443dc84b0854baf5ff2b278a73..09b639c965da2e37c3c36b7f4b1ae8222dbef1c2 100644 (file)
@@ -25,6 +25,7 @@
 #include "ATCDialog.hxx"
 
 #include <Airports/runways.hxx>
+#include <simgear/math/polar3d.hxx>
 #include <simgear/misc/sg_path.hxx>
 
 #ifdef FG_WEATHERCM
index 3715bf6a3dc606a6245708e7d0132e5e8ce79d1e..8922363da0a83720b596bfc0b8a3753ea91d6795 100644 (file)
@@ -2,15 +2,6 @@
 #include "Glue.hpp"
 namespace yasim {
 
-// WGS84 numbers
-static const double EQURAD = 6378137;         // equatorial radius
-static const double STRETCH = 1.003352810665; // equ./polar radius
-
-// Derived from the above
-static const double SQUASH = 0.99665839311;      // 1/STRETCH
-static const double POLRAD = 6356823.77346;      // EQURAD*SQUASH
-static const double iPOLRAD = 1.57311266701e-07; // 1/POLRAD
-
 void Glue::calcAlphaBeta(State* s, float* alpha, float* beta)
 {
     // Convert the velocity to the aircraft frame.
@@ -47,78 +38,6 @@ void Glue::calcEulerRates(State* s, float* roll, float* pitch, float* hdg)
     *pitch = Math::dot3(pitchAxis, s->rot);
 }
 
-void Glue::xyz2geoc(double* xyz, double* lat, double* lon, double* alt)
-{
-    double x=xyz[0], y=xyz[1], z=xyz[2];
-
-    // Cylindrical radius from the polar axis
-    double rcyl = Math::sqrt(x*x + y*y);
-
-    // In geocentric coordinates, these are just the angles in
-    // cartesian space.
-    *lon = Math::atan2(y, x);
-    *lat = Math::atan2(z, rcyl);
-
-    // To get XYZ coordinate of "ground", we "squash" the cylindric
-    // radius into a coordinate system where the earth is a sphere,
-    // find the fraction of the xyz vector that is above ground.
-    double rsquash = SQUASH * rcyl;
-    double frac = POLRAD/Math::sqrt(rsquash*rsquash + z*z);
-    double len = Math::sqrt(x*x + y*y + z*z);
-
-    *alt = len * (1-frac);
-}
-
-void Glue::geoc2xyz(double lat, double lon, double alt, double* out)
-{
-    // Generate a unit vector
-    double rcyl = Math::cos(lat);
-    double x = rcyl*Math::cos(lon);
-    double y = rcyl*Math::sin(lon);
-    double z = Math::sin(lat);
-
-    // Convert to "squashed" space, renormalize the unit vector,
-    // multiply by the polar radius, and back convert to get us the
-    // point of intersection of the unit vector with the surface.
-    // Then just add the altitude.
-    double rtmp = rcyl*SQUASH;
-    double renorm = POLRAD/Math::sqrt(rtmp*rtmp + z*z);
-    double ztmp = z*renorm;
-    rtmp *= renorm*STRETCH;
-    double len = Math::sqrt(rtmp*rtmp + ztmp*ztmp);
-    len += alt;
-    
-    out[0] = x*len;
-    out[1] = y*len;
-    out[2] = z*len;
-}
-
-double Glue::geod2geocLat(double lat)
-{
-    double r = Math::cos(lat)*STRETCH*STRETCH;
-    double z = Math::sin(lat);
-    return Math::atan2(z, r);    
-}
-
-double Glue::geoc2geodLat(double lat)
-{
-    double r = Math::cos(lat)*SQUASH*SQUASH;
-    double z = Math::sin(lat);
-    return Math::atan2(z, r);
-}
-
-void Glue::xyz2geod(double* xyz, double* lat, double* lon, double* alt)
-{
-    xyz2geoc(xyz, lat, lon, alt);
-    *lat = geoc2geodLat(*lat);
-}
-
-void Glue::geod2xyz(double lat, double lon, double alt, double* out)
-{
-    lat = geod2geocLat(lat);
-    geoc2xyz(lat, lon, alt, out);
-}
-
 void Glue::xyz2nedMat(double lat, double lon, float* out)
 {
     // Shorthand for our output vectors:
@@ -228,18 +147,26 @@ void Glue::orient2euler(float* o, float* roll, float* pitch, float* hdg)
     *roll = Math::atan2(pz, py);
 }
 
-void Glue::geodUp(double* pos, float* out)
+void Glue::geodUp(double lat, double lon, float* up)
 {
-    double lat, lon, alt;
-    xyz2geod(pos, &lat, &lon, &alt);
-       
-    float slat = (float)Math::sin(lat);
-    float clat = (float)Math::cos(lat);
-    float slon = (float)Math::sin(lon);
-    float clon = (float)Math::cos(lon);
-    out[0] = clon * clat;
-    out[1] = slon * clat;
-    out[2] = slat;    
+    double coslat = Math::cos(lat);
+    up[0] = (float)(Math::cos(lon) * coslat);
+    up[1] = (float)(Math::sin(lon) * coslat);
+    up[2] = (float)(Math::sin(lat));
+}
+
+// FIXME: Hardcoded WGS84 numbers...
+void Glue::geodUp(double* pos, float* up)
+{
+    const double SQUASH  = 0.9966471893352525192801545;
+    const double STRETCH = 1.0033640898209764189003079;
+    float x = (float)(pos[0] * SQUASH);
+    float y = (float)(pos[1] * SQUASH);
+    float z = (float)(pos[2] * STRETCH);
+    float norm = 1/Math::sqrt(x*x + y*y + z*z);
+    up[0] = x * norm;
+    up[1] = y * norm;
+    up[2] = z * norm;
 }
 
 }; // namespace yasim
index 081bcf5a4024c994e9caf7265b59060b21c3bebc..dd621e12db50158b91cea2bbdf8613db54a9839c 100644 (file)
@@ -17,18 +17,6 @@ public:
     static void calcEulerRates(State* s,
                               float* roll, float* pitch, float* hdg);
 
-    static void xyz2geoc(double* xyz,
-                         double* lat, double* lon, double* alt);
-    static void geoc2xyz(double lat, double lon, double alt,
-                         double* out);
-    static void xyz2geod(double* xyz,
-                         double* lat, double* lon, double* alt);
-    static void geod2xyz(double lat, double lon, double alt,
-                         double* out);
-
-    static double geod2geocLat(double lat);
-    static double geoc2geodLat(double lat);
-
     // Returns a global to "local" (north, east, down) matrix.  Note
     // that the latitude passed in is geoDETic.
     static void xyz2nedMat(double lat, double lon, float* out);
@@ -40,9 +28,8 @@ public:
     static void orient2euler(float* o,
                              float* roll, float* pitch, float* hdg);
 
-    // Returns a geodetic (i.e. gravitational, "level", etc...) "up"
-    // vector for the specified xyz position.
-    static void geodUp(double* pos, float* out);
+    static void geodUp(double lat, double lon, float* up);
+    static void geodUp(double* pos, float* up);
 };
 
 }; // namespace yasim
index 98bf6e78f3d2c6cd05e927fa068a763851517a0c..91de304e836916abf693da52054099047a915269 100644 (file)
@@ -1,4 +1,5 @@
 #include <simgear/debug/logstream.hxx>
+#include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/scene/model/location.hxx>
 #include <simgear/scene/model/placement.hxx>
@@ -268,7 +269,7 @@ void YASim::copyToYASim(bool copyState)
     Glue::xyz2nedMat(lat, lon, xyz2ned);
 
     // position
-    Glue::geod2xyz(lat, lon, alt, s.pos);
+    sgGeodToCart(lat, lon, alt, s.pos);
 
     // orientation
     Glue::euler2orient(roll, pitch, hdg, s.orient);
@@ -326,8 +327,8 @@ void YASim::copyToYASim(bool copyState)
     // us, find the (geodetic) up vector normal to the ground, then
     // use that to find the final (radius) term of the plane equation.
     double xyz[3], gplane[3]; float up[3];
-    Glue::geod2xyz(lat, lon, ground, xyz);
-    Glue::geodUp(xyz, up); // FIXME, needless reverse computation...
+    sgGeodToCart(lat, lon, ground, xyz);
+    Glue::geodUp(lat, lon, up); // FIXME, needless reverse computation...
     int i;
     for(i=0; i<3; i++) gplane[i] = up[i];
     double rad = gplane[0]*xyz[0] + gplane[1]*xyz[1] + gplane[2]*xyz[2];
@@ -390,7 +391,7 @@ void YASim::copyFromYASim()
 
     // position
     double lat, lon, alt;
-    Glue::xyz2geod(s->pos, &lat, &lon, &alt);
+    sgCartToGeod(s->pos, &lat, &lon, &alt);
     _set_Geodetic_Position(lat, lon, alt*M2FT);
 
     // UNUSED
index cbb0d92c9bbbf7d0caf439b0d7408489b07781f0..e5c040bb386427a0b087bd74a3be61eadd2ed0e0 100644 (file)
@@ -4,6 +4,7 @@
 // This file is in the Public Domain and comes with no warranty.
 
 #include <simgear/compiler.h>
+#include <simgear/constants.h>
 #include <simgear/math/sg_geodesy.hxx>
 
 #include <Main/fg_props.hxx>
index c021b109644408597761dd0796364f8903e91bb4..db7205d82d1d5ad4241014de1e11ad92a253bea9 100644 (file)
@@ -970,6 +970,10 @@ static void fgMainLoop( void ) {
     globals->inc_sim_time_sec( delta_time_sec );
     SGAnimation::set_sim_time_sec( globals->get_sim_time_sec() );
 
+    // These are useful, especially for Nasal scripts.
+    fgSetDouble("/sim/time/delta-realtime-sec", real_delta_time_sec);
+    fgSetDouble("/sim/time/delta-sec", delta_time_sec);
+
     static long remainder = 0;
     long elapsed;
 #ifdef FANCY_FRAME_COUNTER
index a9b7da167d1294f3b718468bf2038e070f154046..95b37cf34528f4752c0a0cdb0f71c8af6e9aa14c 100644 (file)
@@ -26,6 +26,7 @@
 
 
 #include <simgear/compiler.h>
+#include <simgear/constants.h>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/sgstream.hxx>
 
index aa0e3b546c44e01761fbac95efe6bab3e91b3726..0c2e00fa610a634822ebf72f5eeadac97ecdf209 100644 (file)
@@ -537,10 +537,11 @@ bool fgCurrentElev( sgdVec3 abs_view_pos, double max_alt_m,
     int hitcount = hit_list->num_hits();
     // cout << "hits = " << hitcount << endl;
     for ( int i = 0; i < hitcount; ++i ) {
-        geoc = sgCartToPolar3d( sc + hit_list->get_point(i) );
-        double lat_geod, alt, sea_level_r;
-        sgGeocToGeod(geoc.lat(), geoc.radius(), &lat_geod,
-                     &alt, &sea_level_r);
+        // FIXME: sgCartToGeod is slow.  Call it just once for the
+        // "sc" point, and then handle the rest with a geodetic "up"
+        // vector approximation.  Across one tile, this will be
+        // acceptable.
+        double alt = sgCartToGeod( sc + hit_list->get_point(i) ).elev();
         // cout << "hit " << i << " lon = " << geoc.lon() << " lat = "
         //      << lat_geod << " alt = " << alt << "  max alt = " << max_alt_m
         //      << endl;
@@ -629,10 +630,11 @@ bool fgCurrentElev( sgdVec3 abs_view_pos, double max_alt_m,
     int hitcount = hit_list->num_hits();
     // cout << "hits = " << hitcount << endl;
     for ( int i = 0; i < hitcount; ++i ) {
-        geoc = sgCartToPolar3d( sc + hit_list->get_point(i) );
-        double lat_geod, alt, sea_level_r;
-        sgGeocToGeod(geoc.lat(), geoc.radius(), &lat_geod,
-                     &alt, &sea_level_r);
+        // FIXME: sgCartToGeod is slow.  Call it just once for the
+        // "sc" point, and then handle the rest with a geodetic "up"
+        // vector approximation.  Across one tile, this will be
+        // acceptable.
+        double alt = sgCartToGeod( sc + hit_list->get_point(i) ).elev();
         // cout << "hit " << i << " lon = " << geoc.lon() << " lat = "
         //      << lat_geod << " alt = " << alt << "  max alt = " << max_alt_m
         //      << endl;
index b0d0d5c4f57fe187a440d73bd1626c7d52fd27ff..0b16f2de777a1bec6abbf7b279e29655a906f155 100644 (file)
@@ -47,18 +47,13 @@ static double sun_angle( const SGTime &t, sgVec3 world_up,
     SG_LOG( SG_EVENT, SG_DEBUG, "  Updating Sun position" );
     SG_LOG( SG_EVENT, SG_DEBUG, "  Gst = " << t.getGst() );
 
-    double sun_lon, sun_gd_lat, sun_gc_lat, sl_radius;
+    double sun_lon, sun_gd_lat;
     fgSunPositionGST( t.getGst(), &sun_lon, &sun_gd_lat );
-
-    sgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &sun_gc_lat);
-
-    p = Point3D( sun_lon, sun_gc_lat, sl_radius );
-    Point3D sunpos = sgPolarToCart3d(p);
+    Point3D sunpos = sgGeodToCart(Point3D(sun_lon, sun_gd_lat, 0));
 
     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 = " << sun_gc_lat );
+           "    Sun Geodetic lat = " << sun_gd_lat );
 
     // calculate the sun's relative angle to local up
     sgCopyVec3( nup, world_up );