Working on star alignment and time issues.
This commit is contained in:
parent
45d02e3e68
commit
1ba17de9ba
5 changed files with 157 additions and 38 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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 = ¤t_aircraft.flight;
|
||||
t = &cur_time_params;
|
||||
v = ¤t_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.
|
||||
*
|
||||
|
|
|
@ -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 = ¤t_aircraft.flight;
|
||||
t = &cur_time_params;
|
||||
v = ¤t_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.
|
||||
*
|
||||
|
|
101
Time/fg_time.c
101
Time/fg_time.c
|
@ -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.)
|
||||
|
@ -41,6 +42,13 @@
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -42,13 +42,18 @@
|
|||
/* 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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue