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];
/* 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; }
/* $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.
*
#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"
double cur_elev;
struct FLIGHT *f;
+ struct TIME *t;
struct VIEW *v;
f = ¤t_aircraft.flight;
+ t = &cur_time_params;
v = ¤t_view;
/* 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);
/* $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.
*
#include "../GLUT/views.h"
#include "../Aircraft/aircraft.h"
+#include "../Time/fg_time.h"
#define EpochStart (631065600)
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;
/* 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),
void fgStarsRender() {
struct FLIGHT *f;
struct VIEW *v;
+ struct fgTIME *t;
double angle;
static double warp = 0;
f = ¤t_aircraft.flight;
+ t = &cur_time_params;
v = ¤t_view;
printf("RENDERING STARS\n");
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);
/* $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.
*
#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. */
* 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;
}
+/* 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);
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.
*
/* 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 */
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);
/* $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.
*