]> git.mxchange.org Git - flightgear.git/commitdiff
Mostly working on stars and generating sidereal time for accurate star
authorcurt <curt>
Sat, 13 Sep 1997 01:59:45 +0000 (01:59 +0000)
committercurt <curt>
Sat, 13 Sep 1997 01:59:45 +0000 (01:59 +0000)
placement.

Aircraft/aircraft.c
Aircraft/aircraft.h
Main/GLUTmain.c
Simulator/constants.h
Time/depend
Time/fg_time.c
Time/fg_time.h
Time/sunpos.c

index 4aa51e0b44b2219d8f33062d0856c8308accfcec..cb8f27e781b2039669b4a266d84b84e1bfca3e4a 100644 (file)
 
 
 /* Display various parameters to stdout */
-void aircraft_debug(int type) {
+void fgAircraftOutputCurrent(struct AIRCRAFT *a) {
     struct FLIGHT *f;
     struct CONTROLS *c;
 
-    f = &current_aircraft.flight;
-    c = &current_aircraft.controls;
+    f = &a->flight;
+    c = &a->controls;
 
     printf("Pos = (%.2f,%.2f,%.2f)  (Phi,Theta,Psi)=(%.2f,%.2f,%.2f)\n",
           FG_Longitude * 3600.0 * RAD_TO_DEG, 
@@ -48,9 +48,13 @@ void aircraft_debug(int type) {
 
 
 /* $Log$
-/* Revision 1.10  1997/08/27 03:29:56  curt
-/* Changed naming scheme of basic shared structures.
+/* Revision 1.11  1997/09/13 02:00:05  curt
+/* Mostly working on stars and generating sidereal time for accurate star
+/* placement.
 /*
+ * Revision 1.10  1997/08/27 03:29:56  curt
+ * Changed naming scheme of basic shared structures.
+ *
  * Revision 1.9  1997/07/19 22:39:08  curt
  * Moved PI to ../constants.h
  *
index 1f1f788191e959ac0c83c361d4de691113a463d5..459483d5c329e843b98e12ec55d9d63bdb208c8e 100644 (file)
@@ -44,16 +44,20 @@ extern struct AIRCRAFT current_aircraft;
 
 
 /* Display various parameters to stdout */
-void aircraft_debug(int type);
+void fgAircraftOutputCurrent(struct AIRCRAFT *a);
 
 
 #endif /* AIRCRAFT_H */
 
 
 /* $Log$
-/* Revision 1.5  1997/08/27 03:29:58  curt
-/* Changed naming scheme of basic shared structures.
+/* Revision 1.6  1997/09/13 02:00:06  curt
+/* Mostly working on stars and generating sidereal time for accurate star
+/* placement.
 /*
+ * Revision 1.5  1997/08/27 03:29:58  curt
+ * Changed naming scheme of basic shared structures.
+ *
  * Revision 1.4  1997/07/23 21:52:17  curt
  * Put comments around the text after an #endif for increased portability.
  *
index 45c2671e0879cc12cb7a3630db45beb93d2024ab..01271d9f11052b94feb9b5737ae3a6c016a3d7c1 100644 (file)
@@ -396,9 +396,16 @@ static void fgMainLoop( void ) {
     double cur_elev;
     double joy_x, joy_y;
     int joy_b1, joy_b2;
+    struct AIRCRAFT *a;
     struct FLIGHT *f;
+    struct fgTIME *t;
 
-    f = &current_aircraft.flight;
+    a = &current_aircraft;
+    f = &a->flight;
+    t = &cur_time_params;
+
+    /* update "time" */
+    fgTimeUpdate(f, t);
 
     /* Read joystick */
     /* fgJoystickRead( &joy_x, &joy_y, &joy_b1, &joy_b2 );
@@ -447,7 +454,7 @@ static void fgMainLoop( void ) {
               FG_Altitude * FEET_TO_METER);
     }
 
-    aircraft_debug(1);
+    fgAircraftOutputCurrent(a);
 
     /* redraw display */
     fgUpdateVisuals();
@@ -555,9 +562,13 @@ int main( int argc, char *argv[] ) {
 
 
 /* $Log$
-/* Revision 1.15  1997/09/05 14:17:27  curt
-/* More tweaking with stars.
+/* Revision 1.16  1997/09/13 02:00:06  curt
+/* Mostly working on stars and generating sidereal time for accurate star
+/* placement.
 /*
+ * Revision 1.15  1997/09/05 14:17:27  curt
+ * More tweaking with stars.
+ *
  * Revision 1.14  1997/09/05 01:35:53  curt
  * Working on getting stars right.
  *
index 625217378fdd2b77190f4c262fa44475b9fe95ce..9604c07e2960d4b1e0a5b71a444a06a688b7e29e 100644 (file)
 #define INVG  0.031080997
 
 
+/* Time Related Parameters */
+
+#define MJD0  2415020.0
+#define J2000 (2451545.0 - MJD0)
+#define SIDRATE         .9972695677
+
+
 /* Conversions */
 
 /* Degrees to Radians */
 
 
 /* $Log$
-/* Revision 1.9  1997/08/22 21:34:32  curt
-/* Doing a bit of reorganizing and house cleaning.
+/* Revision 1.10  1997/09/13 01:59:45  curt
+/* Mostly working on stars and generating sidereal time for accurate star
+/* placement.
 /*
+ * Revision 1.9  1997/08/22 21:34:32  curt
+ * Doing a bit of reorganizing and house cleaning.
+ *
  * Revision 1.8  1997/07/31 22:52:22  curt
  * Working on redoing internal coordinate systems & scenery transformations.
  *
index 66b8d5dd7fab0371d23aa54ce761864d6be9db45..2ba06afddcdf825319f15b69117ce2d02aa8cee8 100644 (file)
@@ -1,5 +1,6 @@
 fg_time.o: fg_time.c fg_time.h ../types.h
 fg_timer.o: fg_timer.c fg_timer.h
+sidereal.o: sidereal.c
 sunpos.o: sunpos.c sunpos.h ../types.h fg_time.h ../constants.h \
  ../GLUT/views.h ../GLUT/../types.h ../GLUT/../Flight/flight.h \
  ../GLUT/../Flight/Slew/slew.h \
@@ -7,3 +8,4 @@ sunpos.o: sunpos.c sunpos.h ../types.h fg_time.h ../constants.h \
  ../GLUT/../Flight/LaRCsim/../flight.h ../GLUT/../Math/mat3.h \
  ../Math/fg_geodesy.h ../Math/mat3.h ../Math/polar.h \
  ../Math/../types.h
+ttest.o: ttest.c
index 064a75c2c5128fabe998f72082e23353cbacea51..ea0b5a51f3e922089f33f4276041564b8271c6e3 100644 (file)
  **************************************************************************/
 
 
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
 #include "fg_time.h"
+#include "../constants.h"
+#include "../Flight/flight.h"
+
+
+#define DEGHR(x)        ((x)/15.)
+#define RADHR(x)        DEGHR(x*RAD_TO_DEG)
 
 
 struct fgTIME cur_time_params;
 
 
+/* given a date in months, mn, days, dy, years, yr, return the
+ * modified Julian date (number of days elapsed since 1900 jan 0.5),
+ * mjd.  Adapted from Xephem.  */
+
+double cal_mjd (int mn, double dy, int yr) {
+    static double last_mjd, last_dy;
+    double mjd;
+    static int last_mn, last_yr;
+    int b, d, m, y;
+    long c;
+
+    if (mn == last_mn && yr == last_yr && dy == last_dy) {
+       mjd = last_mjd;
+       return(mjd);
+    }
+
+    m = mn;
+    y = (yr < 0) ? yr + 1 : yr;
+    if (mn < 3) {
+       m += 12;
+       y -= 1;
+    }
+
+    if (yr < 1582 || (yr == 1582 && (mn < 10 || (mn == 10 && dy < 15)))) {
+       b = 0;
+    } else {
+       int a;
+       a = y/100;
+       b = 2 - a + a/4;
+    }
+
+    if (y < 0) {
+       c = (long)((365.25*y) - 0.75) - 694025L;
+    } else {
+       c = (long)(365.25*y) - 694025L;
+    }
+    
+    d = 30.6001*(m+1);
+
+    mjd = b + c + d + dy - 0.5;
+
+    last_mn = mn;
+    last_dy = dy;
+    last_yr = yr;
+    last_mjd = mjd;
+
+    return(mjd);
+}
+
+
+/* given an mjd, return greenwich mean siderial time, gst */
+
+double utc_gst (double mjd) {
+    double gst;
+    double day = floor(mjd-0.5)+0.5;
+    double hr = (mjd-day)*24.0;
+    double T, x;
+
+    T = ((int)(mjd - 0.5) + 0.5 - J2000)/36525.0;
+    x = 24110.54841 + (8640184.812866 + (0.093104 - 6.2e-6 * T) * T) * T;
+    x /= 3600.0;
+    gst = (1.0/SIDRATE)*hr + x;
+
+    return(gst);
+}
+
+
+/* given Julian Date and Longitude (decimal degrees West) compute and
+ * return Local Sidereal Time, in decimal hours.
+ *
+ * Provided courtesy of ecdowney@noao.edu (Elwood Downey) 
+ */
+
+double sidereal (double mjd, double lng) {
+    double gst;
+    double lst;
+
+    printf ("Current Lst on JD %13.5f at %8.4f degrees West: ", 
+           mjd + MJD0, lng);
+
+    /* convert to required internal units */
+    lng *= DEG_TO_RAD;
+
+    /* compute LST and print */
+    gst = utc_gst (mjd);
+    lst = gst - RADHR (lng);
+    lst -= 24.0*floor(lst/24.0);
+    printf ("%7.4f\n", lst);
+
+    /* that's all */
+    return (lst);
+}
+
+
+/* Update the time dependent variables */
+
+void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t) {
+    /* get current Unix calendar time (in seconds) */
+    t->cur_time = time(NULL);
+    printf("Current Unix calendar time = %ld\n", t->cur_time);
+
+    /* get GMT break down for current time */
+    t->gmt = gmtime(&t->cur_time);
+    printf("Current GMT = %d/%d/%2d %d:%02d:%02d\n", 
+           t->gmt->tm_mon+1, t->gmt->tm_mday, t->gmt->tm_year,
+           t->gmt->tm_hour, t->gmt->tm_min, t->gmt->tm_sec);
+
+    /* calculate modified Julian date */
+    t->mjd = cal_mjd ((int)(t->gmt->tm_mon+1), (double)t->gmt->tm_mday, 
+            (int)(t->gmt->tm_year + 1900));
+
+    /* add in partial day */
+    t->mjd += (t->gmt->tm_hour / 24.0) + (t->gmt->tm_min / (24.0 * 60.0)) +
+          (t->gmt->tm_sec / (24.0 * 60.0 * 60.0));
+
+    /* convert "back" to Julian date + partial day (as a fraction of one) */
+    t->jd = t->mjd + MJD0;
+    printf("Current Julian Date = %.5f\n", t->jd);
+
+    /* Calculate local side real time */
+    t->lst = sidereal(t->mjd, -(FG_Longitude * RAD_TO_DEG));
+    printf("Current Sidereal Time = %.3f\n", t->lst);
+}
+
+
 /* $Log$
-/* Revision 1.2  1997/08/27 03:30:35  curt
-/* Changed naming scheme of basic shared structures.
+/* Revision 1.3  1997/09/13 02:00:08  curt
+/* Mostly working on stars and generating sidereal time for accurate star
+/* placement.
 /*
+ * Revision 1.2  1997/08/27 03:30:35  curt
+ * Changed naming scheme of basic shared structures.
+ *
  * Revision 1.1  1997/08/13 21:55:59  curt
  * Initial revision.
  *
index 6f028b2eb60f62ab6213beca48ab1142959a7df9..df1f10fc46cb9f45e9bca4922c6946cc8681ccc1 100644 (file)
 #endif
 
 #include <GL/glut.h>
+#include <time.h>
 
 #include "../types.h"
+#include "../Flight/flight.h"
 
 
 /* Define a structure containing global time parameters */
 struct fgTIME {
-    /* the point on the earth's surface above which the sun is directly 
-     * overhead */
+    /* the date/time in various forms */
+    time_t cur_time;                    /* Unix "calendar" time in seconds */
+    struct tm *gmt;                     /* Break down of GMT time */
+
+    double jd;                          /* Julian date */
+    double mjd;                         /* modified Julian date */
+
+    double lst;                         /* local side real time */
+
+    /* position of the sun in various forms */
     double sun_lon, sun_gc_lat;         /* in geocentric coordinates */
     struct fgCartesianPoint fg_sunpos;  /* in cartesian coordiantes */
     GLfloat sun_vec[4];                 /* in view coordinates */
@@ -51,13 +61,21 @@ struct fgTIME {
 extern struct fgTIME cur_time_params;
 
 
+/* Update the time dependent variables */
+void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t);
+
+
 #endif /* FG_TIME_H */
 
 
 /* $Log$
-/* Revision 1.3  1997/09/04 02:17:39  curt
-/* Shufflin' stuff.
+/* Revision 1.4  1997/09/13 02:00:08  curt
+/* Mostly working on stars and generating sidereal time for accurate star
+/* placement.
 /*
+ * Revision 1.3  1997/09/04 02:17:39  curt
+ * Shufflin' stuff.
+ *
  * Revision 1.2  1997/08/27 03:30:36  curt
  * Changed naming scheme of basic shared structures.
  *
index ab0ab1498715bf87d316eb4f1c5a94f65984c151..1e593bc02a44097edf8c966990088e56b2aa26dd 100644 (file)
@@ -272,7 +272,7 @@ void fgUpdateSunPos(struct fgCartesianPoint scenery_center) {
 
     time_warp += 0; /* increase this to make the world spin real fast */
 
-    fgSunPosition(time(NULL) + time_warp, &t->sun_lon, &sun_gd_lat);
+    fgSunPosition(t->cur_time + time_warp, &t->sun_lon, &sun_gd_lat);
 
     fgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &t->sun_gc_lat);
 
@@ -303,9 +303,13 @@ void fgUpdateSunPos(struct fgCartesianPoint scenery_center) {
 
 
 /* $Log$
-/* Revision 1.9  1997/09/05 14:17:31  curt
-/* More tweaking with stars.
+/* Revision 1.10  1997/09/13 02:00:09  curt
+/* Mostly working on stars and generating sidereal time for accurate star
+/* placement.
 /*
+ * Revision 1.9  1997/09/05 14:17:31  curt
+ * More tweaking with stars.
+ *
  * Revision 1.8  1997/09/05 01:36:04  curt
  * Working on getting stars right.
  *