]> git.mxchange.org Git - flightgear.git/commitdiff
Working on star alignment and time issues.
authorcurt <curt>
Tue, 16 Sep 1997 15:50:29 +0000 (15:50 +0000)
committercurt <curt>
Tue, 16 Sep 1997 15:50:29 +0000 (15:50 +0000)
Main/GLUTmain.c
Main/fg_init.c
Scenery/stars.c
Time/fg_time.c
Time/fg_time.h

index 01271d9f11052b94feb9b5737ae3a6c016a3d7c1..ea734584fd2287ddbbaa46279a7126b1e28ca9e0 100644 (file)
@@ -141,6 +141,7 @@ static void fgUpdateViewParams() {
     struct FLIGHT *f;
     struct fgTIME *t;
     struct VIEW *v;
+    double x_2, x_4, x_8;
     double ambient, diffuse, sky;
     GLfloat color[4] = { 1.0, 1.0, 0.50, 1.0 };
     GLfloat amb[3], diff[3], fog[4], clear[4];
@@ -172,12 +173,15 @@ static void fgUpdateViewParams() {
     /* calculate lighting parameters based on sun's relative angle to
      * local up */
     /* ya kind'a have to plot this to see the magic */
-    ambient = 0.4 * 
-       pow(2.4, -t->sun_angle*t->sun_angle*t->sun_angle*t->sun_angle / 3.0);
-    diffuse = 0.4 * cos(0.6 * t->sun_angle * t->sun_angle);
-    sky = 0.85 * 
-       pow(1.6, -t->sun_angle*t->sun_angle*t->sun_angle*t->sun_angle/2.0) 
-       + 0.15;
+
+    /* x = t->sun_angle^8 */
+    x_2 = t->sun_angle * t->sun_angle;
+    x_4 = x_2 * x_2;
+    x_8 = x_4 * x_4;
+
+    ambient = 0.4 * pow(1.5, -x_8 / 20.0);
+    diffuse = 0.4 * cos(0.55 * x_2);
+    sky = 0.85 * pow(1.6, -x_4 / 2.0) + 0.15;
 
     if ( ambient < 0.1 ) { ambient = 0.1; }
     if ( diffuse < 0.0 ) { diffuse = 0.0; }
@@ -562,10 +566,13 @@ int main( int argc, char *argv[] ) {
 
 
 /* $Log$
-/* Revision 1.16  1997/09/13 02:00:06  curt
-/* Mostly working on stars and generating sidereal time for accurate star
-/* placement.
+/* Revision 1.17  1997/09/16 15:50:29  curt
+/* Working on star alignment and time issues.
 /*
+ * 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.
  *
index 7e0c2146bd55f7781a19fd458877d0c008fae264..2604bd29d6375587ed6b4303a83f4ad2224f1068 100644 (file)
@@ -40,6 +40,7 @@
 #include "../Scenery/mesh.h"
 #include "../Scenery/scenery.h"
 #include "../Scenery/stars.h"
+#include "../Time/fg_time.h"
 #include "../Time/sunpos.h"
 #include "../Weather/weather.h"
 
@@ -75,9 +76,11 @@ void fgInitSubsystems( void ) {
     double cur_elev;
 
     struct FLIGHT *f;
+    struct TIME *t;
     struct VIEW *v;
 
     f = &current_aircraft.flight;
+    t = &cur_time_params;
     v = &current_view;
 
 
@@ -147,6 +150,10 @@ void fgInitSubsystems( void ) {
     /* fgSlewInit(-335340,162540, 15, 4.38); */
     /* fgSlewInit(-398673.28,120625.64, 53, 4.38); */
 
+    /* Initialize "time" */
+    fgTimeInit(t);
+    fgTimeUpdate(f, t);
+
     /* Initialize shared sun position and sun_vec */
     fgUpdateSunPos(scenery.center);
 
@@ -205,9 +212,12 @@ void fgInitSubsystems( void ) {
 
 
 /* $Log$
-/* Revision 1.6  1997/09/05 14:17:30  curt
-/* More tweaking with stars.
+/* Revision 1.7  1997/09/16 15:50:30  curt
+/* Working on star alignment and time issues.
 /*
+ * Revision 1.6  1997/09/05 14:17:30  curt
+ * More tweaking with stars.
+ *
  * Revision 1.5  1997/09/04 02:17:36  curt
  * Shufflin' stuff.
  *
index 0b6ddc6e1828037f5dbb307d3c1982c7c9fd5fa3..ceb16324628587a1623c9e9d53d666ad42b11d94 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "../GLUT/views.h"
 #include "../Aircraft/aircraft.h"
+#include "../Time/fg_time.h"
 
 
 #define EpochStart           (631065600)
@@ -117,13 +118,13 @@ void fgStarsInit() {
            sscanf(front, "%lf,%lf,%lf\n", 
                   &right_ascension, &declination, &magnitude);
 
-           if ( strcmp(name, "Merak") == 0 ) {
+           if ( strcmp(name, "Hamal") == 0 ) {
                printf("\n*** Marking %s\n\n", name);
                ra_save = right_ascension;
                decl_save = declination;
            }
 
-           if ( strcmp(name, "Rastaban") == 0 ) {
+           if ( strcmp(name, "Algenib") == 0 ) {
                printf("\n*** Marking %s\n\n", name);
                ra_save1 = right_ascension;
                decl_save1 = declination;
@@ -135,10 +136,10 @@ void fgStarsInit() {
            /* scale magnitudes again so they look ok */
            if ( magnitude > 1.0 ) { magnitude = 1.0; }
            if ( magnitude < 0.0 ) { magnitude = 0.0; }
-           magnitude = magnitude * 0.8 + 0.2;
+           magnitude = magnitude * 0.7 + 0.3;
 
-           printf("Found star: %d %s, %.3f %.3f %.3f\n", count,
-              name, right_ascension, declination, magnitude);
+           /* printf("Found star: %d %s, %.3f %.3f %.3f\n", count,
+              name, right_ascension, declination, magnitude); */
 
            glColor3f( magnitude, magnitude, magnitude );
            glVertex3f( 190000.0 * sin(right_ascension) * cos(declination),
@@ -194,10 +195,12 @@ void fgStarsInit() {
 void fgStarsRender() {
     struct FLIGHT *f;
     struct VIEW *v;
+    struct fgTIME *t;
     double angle;
     static double warp = 0;
 
     f = &current_aircraft.flight;
+    t = &cur_time_params;
     v = &current_view;
 
     printf("RENDERING STARS\n");
@@ -208,12 +211,12 @@ void fgStarsRender() {
 
     glTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z );
 
-    angle = FG_2PI * fmod(DaysSinceEpoch(time(NULL)), 1.0);
-    warp += 0.5 * DEG_TO_RAD;
-    warp = 240.0 * DEG_TO_RAD;
+    angle = FG_2PI * t->lst / 24.0;
+    /* warp += 1.0 * DEG_TO_RAD; */
+    warp = 15.0 * DEG_TO_RAD;
     glRotatef( -(angle+warp) * RAD_TO_DEG, 0.0, 0.0, 1.0 );
     printf("Rotating stars by %.2f + %.2f\n", -angle * RAD_TO_DEG,
-       warp * RAD_TO_DEG);
+       -warp * RAD_TO_DEG);
 
     glCallList(stars);
 
@@ -224,9 +227,12 @@ void fgStarsRender() {
 
 
 /* $Log$
-/* Revision 1.6  1997/09/05 14:17:31  curt
-/* More tweaking with stars.
+/* Revision 1.7  1997/09/16 15:50:31  curt
+/* Working on star alignment and time issues.
 /*
+ * Revision 1.6  1997/09/05 14:17:31  curt
+ * More tweaking with stars.
+ *
  * Revision 1.5  1997/09/05 01:35:59  curt
  * Working on getting stars right.
  *
index ea0b5a51f3e922089f33f4276041564b8271c6e3..3b9721943b8c035212cd4f13d98ee5f8e011cd68 100644 (file)
@@ -32,6 +32,7 @@
 #include "fg_time.h"
 #include "../constants.h"
 #include "../Flight/flight.h"
+#include "../Time/fg_time.h"
 
 
 #define DEGHR(x)        ((x)/15.)
 struct fgTIME cur_time_params;
 
 
+/* Initialize the time dependent variables */
+
+void fgTimeInit(struct fgTIME *t) {
+    t->lst_diff = -9999.0;
+}
+
+
 /* 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.  */
@@ -114,12 +122,12 @@ double utc_gst (double mjd) {
  * Provided courtesy of ecdowney@noao.edu (Elwood Downey) 
  */
 
-double sidereal (double mjd, double lng) {
+double sidereal_precise (double mjd, double lng) {
     double gst;
     double lst;
 
-    printf ("Current Lst on JD %13.5f at %8.4f degrees West: ", 
-           mjd + MJD0, lng);
+    /* printf ("Current Lst on JD %13.5f at %8.4f degrees West: ", 
+       mjd + MJD0, lng); */
 
     /* convert to required internal units */
     lng *= DEG_TO_RAD;
@@ -135,9 +143,65 @@ double sidereal (double mjd, double lng) {
 }
 
 
+/* return a courser but cheaper estimate of sidereal time */
+double sidereal_course(struct tm *gmt, time_t now, double lng) {
+    time_t start, start_gmt;
+    struct tm mt;
+    long int offset;
+    double diff, part, days, hours, lst;
+    int i;
+
+    printf("COURSE: GMT = %d/%d/%2d %d:%02d:%02d\n", 
+           gmt->tm_mon, gmt->tm_mday, gmt->tm_year,
+           gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
+
+    mt.tm_mon = 2;
+    mt.tm_mday = 21;
+    mt.tm_year = gmt->tm_year;
+    mt.tm_hour = 12;
+    mt.tm_min = 0;
+    mt.tm_sec = 0;
+
+    start = mktime(&mt);
+
+    offset = -(timezone / 3600 - daylight);
+
+    printf("Raw time zone offset = %ld\n", timezone);
+    printf("Daylight Savings = %d\n", daylight);
+
+    printf("Local hours from GMT = %ld\n", offset);
+
+    start_gmt = start - timezone + (daylight * 3600);
+
+    printf("March 21 noon (CST) = %ld\n", start);
+    printf("March 21 noon (GMT) = %ld\n", start_gmt);
+
+    diff = (now - start_gmt) / (3600.0 * 24.0);
+
+    printf("Time since 3/21/%2d GMT = %.2f\n", gmt->tm_year, diff);
+
+    part = fmod(diff, 1.0);
+    days = diff - part;
+    hours = gmt->tm_hour + gmt->tm_min/60.0 + gmt->tm_sec/3600.0;
+
+    lst = (days - lng)/15.0 + hours - 12;
+
+    while ( lst < 0.0 ) {
+       lst += 24.0;
+    }
+
+    printf("days = %.1f  hours = %.2f  lon = %.2f  lst = %.2f\n", 
+          days, hours, lng, lst);
+
+    return(lst);
+}
+
+
 /* Update the time dependent variables */
 
 void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t) {
+    double lst_precise, lst_course;
+
     /* get current Unix calendar time (in seconds) */
     t->cur_time = time(NULL);
     printf("Current Unix calendar time = %ld\n", t->cur_time);
@@ -160,17 +224,38 @@ void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t) {
     t->jd = t->mjd + MJD0;
     printf("Current Julian Date = %.5f\n", t->jd);
 
+    printf("Current Longitude = %.3f\n", FG_Longitude * RAD_TO_DEG);
+
     /* Calculate local side real time */
-    t->lst = sidereal(t->mjd, -(FG_Longitude * RAD_TO_DEG));
-    printf("Current Sidereal Time = %.3f\n", t->lst);
+    if ( t->lst_diff < -100.0 ) {
+       /* first time through do the expensive calculation & cheap
+           calculation to get the difference. */
+       printf("First time, doing precise lst\n");
+       t->lst = lst_precise = 
+           sidereal_precise(t->mjd, -(FG_Longitude * RAD_TO_DEG));
+       lst_course = 
+           sidereal_course(t->gmt, t->cur_time, -(FG_Longitude * RAD_TO_DEG));
+       t->lst_diff = lst_precise - lst_course;
+    } else {
+       /* course + difference should drift off very slowly */
+       t->lst = 
+           sidereal_course(t->gmt, t->cur_time, -(FG_Longitude * RAD_TO_DEG))
+           + t->lst_diff;
+    }
+    printf("Current Sidereal Time = %.3f (%.3f) (diff = %.3f)\n", t->lst,
+          sidereal_precise(t->mjd, -(FG_Longitude * RAD_TO_DEG)),
+          t->lst_diff);
 }
 
 
 /* $Log$
-/* Revision 1.3  1997/09/13 02:00:08  curt
-/* Mostly working on stars and generating sidereal time for accurate star
-/* placement.
+/* Revision 1.4  1997/09/16 15:50:31  curt
+/* Working on star alignment and time issues.
 /*
+ * 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.
  *
index df1f10fc46cb9f45e9bca4922c6946cc8681ccc1..19f589066d981593fbc7002efe078e0e29a6ab83 100644 (file)
 /* Define a structure containing global time parameters */
 struct fgTIME {
     /* the date/time in various forms */
-    time_t cur_time;                    /* Unix "calendar" time in seconds */
-    struct tm *gmt;                     /* Break down of GMT time */
+    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 jd;           /* Julian date */
+    double mjd;          /* modified Julian date */
 
-    double lst;                         /* local side real time */
+    double lst;          /* local side real time */
+
+    double lst_diff;     /* the difference between the precise
+                           sidereal time algorithm result and the
+                           course result.  course + diff has good
+                           accuracy for the short term */
 
     /* position of the sun in various forms */
     double sun_lon, sun_gc_lat;         /* in geocentric coordinates */
@@ -61,6 +66,9 @@ struct fgTIME {
 extern struct fgTIME cur_time_params;
 
 
+/* Initialize the time dependent variables */
+void fgTimeInit(struct fgTIME *t);
+
 /* Update the time dependent variables */
 void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t);
 
@@ -69,10 +77,13 @@ void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t);
 
 
 /* $Log$
-/* Revision 1.4  1997/09/13 02:00:08  curt
-/* Mostly working on stars and generating sidereal time for accurate star
-/* placement.
+/* Revision 1.5  1997/09/16 15:50:31  curt
+/* Working on star alignment and time issues.
 /*
+ * 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.
  *