At dusk/dawn add/remove stars in stages.
This commit is contained in:
parent
3b5f599f73
commit
e17c832c36
3 changed files with 112 additions and 83 deletions
|
@ -180,7 +180,7 @@ static void fgUpdateViewParams() {
|
||||||
x_8 = x_4 * x_4;
|
x_8 = x_4 * x_4;
|
||||||
x_10 = x_8 * x_2;
|
x_10 = x_8 * x_2;
|
||||||
|
|
||||||
ambient = 0.4 * pow(1.2, -x_10 / 30.0);
|
ambient = 0.4 * pow(1.1, -x_10 / 30.0);
|
||||||
|
|
||||||
/* diffuse = 0.4 * cos(0.3 * x_2);
|
/* diffuse = 0.4 * cos(0.3 * x_2);
|
||||||
if ( t->sun_angle > FG_PI_2 + 0.05 ) {
|
if ( t->sun_angle > FG_PI_2 + 0.05 ) {
|
||||||
|
@ -575,9 +575,12 @@ int main( int argc, char *argv[] ) {
|
||||||
|
|
||||||
|
|
||||||
/* $Log$
|
/* $Log$
|
||||||
/* Revision 1.18 1997/09/16 22:14:51 curt
|
/* Revision 1.19 1997/09/18 16:20:08 curt
|
||||||
/* Tweaked time of day lighting equations. Don't draw stars during the day.
|
/* At dusk/dawn add/remove stars in stages.
|
||||||
/*
|
/*
|
||||||
|
* Revision 1.18 1997/09/16 22:14:51 curt
|
||||||
|
* Tweaked time of day lighting equations. Don't draw stars during the day.
|
||||||
|
*
|
||||||
* Revision 1.17 1997/09/16 15:50:29 curt
|
* Revision 1.17 1997/09/16 15:50:29 curt
|
||||||
* Working on star alignment and time issues.
|
* Working on star alignment and time issues.
|
||||||
*
|
*
|
||||||
|
|
178
Scenery/stars.c
178
Scenery/stars.c
|
@ -49,7 +49,8 @@
|
||||||
#define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
|
#define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
|
||||||
|
|
||||||
|
|
||||||
static GLint stars;
|
/* Define four structures, each with varying amounts of stars */
|
||||||
|
static GLint stars[FG_STAR_LEVELS];
|
||||||
|
|
||||||
|
|
||||||
/* Initialize the Star Management Subsystem */
|
/* Initialize the Star Management Subsystem */
|
||||||
|
@ -62,8 +63,7 @@ void fgStarsInit() {
|
||||||
double right_ascension, declination, magnitude;
|
double right_ascension, declination, magnitude;
|
||||||
double ra_save, decl_save;
|
double ra_save, decl_save;
|
||||||
double ra_save1, decl_save1;
|
double ra_save1, decl_save1;
|
||||||
double ra_save2, decl_save2;
|
int count, i, max_stars;
|
||||||
int count;
|
|
||||||
|
|
||||||
g = &general;
|
g = &general;
|
||||||
|
|
||||||
|
@ -73,89 +73,93 @@ void fgStarsInit() {
|
||||||
strcat(path, "/Scenery/");
|
strcat(path, "/Scenery/");
|
||||||
strcat(path, "Stars.dat");
|
strcat(path, "Stars.dat");
|
||||||
|
|
||||||
printf("Loading Stars: %s\n", path);
|
max_stars = FG_MAX_STARS;
|
||||||
|
|
||||||
if ( (fd = fopen(path, "r")) == NULL ) {
|
for ( i = 0; i < FG_STAR_LEVELS; i++ ) {
|
||||||
printf("Cannot open star file: '%s'\n", path);
|
printf("Loading %d Stars: %s\n", max_stars, path);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
stars = glGenLists(1);
|
if ( (fd = fopen(path, "r")) == NULL ) {
|
||||||
glNewList( stars, GL_COMPILE );
|
printf("Cannot open star file: '%s'\n", path);
|
||||||
glBegin( GL_POINTS );
|
return;
|
||||||
|
|
||||||
/* read in each line of the file */
|
|
||||||
count = 0;
|
|
||||||
while ( (fgets(line, 256, fd) != NULL) && (count < FG_MAX_STARS) ) {
|
|
||||||
front = line;
|
|
||||||
|
|
||||||
/* printf("Read line = %s", front); */
|
|
||||||
|
|
||||||
/* advance to first non-whitespace character */
|
|
||||||
while ( (front[0] == ' ') || (front[0] == '\t') ) {
|
|
||||||
front++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stars[i] = glGenLists(1);
|
||||||
|
glNewList( stars[i], GL_COMPILE );
|
||||||
|
glBegin( GL_POINTS );
|
||||||
|
|
||||||
/* printf("Line length (after trimming) = %d\n", strlen(front)); */
|
/* read in each line of the file */
|
||||||
|
count = 0;
|
||||||
|
while ( (fgets(line, 256, fd) != NULL) && (count < max_stars) ) {
|
||||||
|
front = line;
|
||||||
|
|
||||||
if ( front[0] == '#' ) {
|
/* printf("Read line = %s", front); */
|
||||||
/* comment */
|
|
||||||
} else if ( strlen(front) <= 1 ) {
|
|
||||||
/* blank line */
|
|
||||||
} else {
|
|
||||||
/* star data line */
|
|
||||||
|
|
||||||
/* get name */
|
/* advance to first non-whitespace character */
|
||||||
end = front;
|
while ( (front[0] == ' ') || (front[0] == '\t') ) {
|
||||||
while ( end[0] != ',' ) {
|
front++;
|
||||||
end++;
|
|
||||||
}
|
|
||||||
end[0] = '\0';
|
|
||||||
strcpy(name, front);
|
|
||||||
front = end;
|
|
||||||
front++;
|
|
||||||
|
|
||||||
sscanf(front, "%lf,%lf,%lf\n",
|
|
||||||
&right_ascension, &declination, &magnitude);
|
|
||||||
|
|
||||||
if ( strcmp(name, "Hamal") == 0 ) {
|
|
||||||
printf("\n*** Marking %s\n\n", name);
|
|
||||||
ra_save = right_ascension;
|
|
||||||
decl_save = declination;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( strcmp(name, "Algenib") == 0 ) {
|
/* printf("Line length (after trimming) = %d\n", strlen(front)); */
|
||||||
printf("\n*** Marking %s\n\n", name);
|
|
||||||
ra_save1 = right_ascension;
|
|
||||||
decl_save1 = declination;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* scale magnitudes to (0.0 - 1.0) */
|
if ( front[0] == '#' ) {
|
||||||
magnitude = (0.0 - magnitude) / 5.0 + 1.0;
|
/* comment */
|
||||||
|
} else if ( strlen(front) <= 1 ) {
|
||||||
|
/* blank line */
|
||||||
|
} else {
|
||||||
|
/* star data line */
|
||||||
|
|
||||||
|
/* get name */
|
||||||
|
end = front;
|
||||||
|
while ( end[0] != ',' ) {
|
||||||
|
end++;
|
||||||
|
}
|
||||||
|
end[0] = '\0';
|
||||||
|
strcpy(name, front);
|
||||||
|
front = end;
|
||||||
|
front++;
|
||||||
|
|
||||||
/* scale magnitudes again so they look ok */
|
sscanf(front, "%lf,%lf,%lf\n",
|
||||||
if ( magnitude > 1.0 ) { magnitude = 1.0; }
|
&right_ascension, &declination, &magnitude);
|
||||||
if ( magnitude < 0.0 ) { magnitude = 0.0; }
|
|
||||||
magnitude = magnitude * 0.7 + 0.3;
|
|
||||||
|
|
||||||
/* printf("Found star: %d %s, %.3f %.3f %.3f\n", count,
|
if ( strcmp(name, "Hamal") == 0 ) {
|
||||||
name, right_ascension, declination, magnitude); */
|
printf(" *** Marking %s\n", name);
|
||||||
|
ra_save = right_ascension;
|
||||||
|
decl_save = declination;
|
||||||
|
}
|
||||||
|
|
||||||
glColor3f( magnitude, magnitude, magnitude );
|
if ( strcmp(name, "Algenib") == 0 ) {
|
||||||
glVertex3f( 190000.0 * sin(right_ascension) * cos(declination),
|
printf(" *** Marking %s\n", name);
|
||||||
-190000.0 * cos(right_ascension) * cos(declination),
|
ra_save1 = right_ascension;
|
||||||
190000.0 * sin(declination) );
|
decl_save1 = declination;
|
||||||
|
}
|
||||||
|
|
||||||
count++;
|
/* scale magnitudes to (0.0 - 1.0) */
|
||||||
} /* if valid line */
|
magnitude = (0.0 - magnitude) / 5.0 + 1.0;
|
||||||
|
|
||||||
} /* while */
|
/* scale magnitudes again so they look ok */
|
||||||
|
if ( magnitude > 1.0 ) { magnitude = 1.0; }
|
||||||
|
if ( magnitude < 0.0 ) { magnitude = 0.0; }
|
||||||
|
magnitude =
|
||||||
|
magnitude * 0.7 + (((FG_STAR_LEVELS - 1) - i) * 0.1);
|
||||||
|
printf("Found star: %d %s, %.3f %.3f %.3f\n", count,
|
||||||
|
name, right_ascension, declination, magnitude);
|
||||||
|
|
||||||
fclose(fd);
|
glColor3f( magnitude, magnitude, magnitude );
|
||||||
|
glVertex3f( 190000.0 * sin(right_ascension) * cos(declination),
|
||||||
|
-190000.0 * cos(right_ascension) * cos(declination),
|
||||||
|
190000.0 * sin(declination) );
|
||||||
|
|
||||||
glEnd();
|
count++;
|
||||||
|
} /* if valid line */
|
||||||
|
|
||||||
glBegin(GL_LINE_LOOP);
|
} /* while */
|
||||||
|
|
||||||
|
fclose(fd);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
|
||||||
|
glBegin(GL_LINE_LOOP);
|
||||||
glColor3f(1.0, 0.0, 0.0);
|
glColor3f(1.0, 0.0, 0.0);
|
||||||
glVertex3f( 190000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
|
glVertex3f( 190000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
|
||||||
-190000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
|
-190000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
|
||||||
|
@ -169,9 +173,9 @@ void fgStarsInit() {
|
||||||
glVertex3f( 190000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
|
glVertex3f( 190000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
|
||||||
-190000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
|
-190000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
|
||||||
190000.0 * sin(decl_save+0.2) );
|
190000.0 * sin(decl_save+0.2) );
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glBegin(GL_LINE_LOOP);
|
glBegin(GL_LINE_LOOP);
|
||||||
glColor3f(0.0, 1.0, 0.0);
|
glColor3f(0.0, 1.0, 0.0);
|
||||||
glVertex3f( 190000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
|
glVertex3f( 190000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
|
||||||
-190000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
|
-190000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
|
||||||
|
@ -185,9 +189,12 @@ void fgStarsInit() {
|
||||||
glVertex3f( 190000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
|
glVertex3f( 190000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
|
||||||
-190000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
|
-190000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
|
||||||
190000.0 * sin(decl_save1+0.2) );
|
190000.0 * sin(decl_save1+0.2) );
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glEndList();
|
glEndList();
|
||||||
|
|
||||||
|
max_stars /= 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -198,6 +205,7 @@ void fgStarsRender() {
|
||||||
struct fgTIME *t;
|
struct fgTIME *t;
|
||||||
double angle;
|
double angle;
|
||||||
static double warp = 0;
|
static double warp = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
f = ¤t_aircraft.flight;
|
f = ¤t_aircraft.flight;
|
||||||
t = &cur_time_params;
|
t = &cur_time_params;
|
||||||
|
@ -205,8 +213,19 @@ void fgStarsRender() {
|
||||||
|
|
||||||
/* FG_PI_2 + 0.1 is about 6 degrees after sundown and before sunrise */
|
/* FG_PI_2 + 0.1 is about 6 degrees after sundown and before sunrise */
|
||||||
|
|
||||||
if ( t->sun_angle > (FG_PI_2 + 0.1 ) ) {
|
if ( t->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) {
|
||||||
printf("RENDERING STARS (night)\n");
|
/* determine which star structure to draw */
|
||||||
|
if ( t->sun_angle > (FG_PI_2 + 7.25 * DEG_TO_RAD ) ) {
|
||||||
|
i = 0;
|
||||||
|
} else if ( t->sun_angle > (FG_PI_2 + 6.50 * DEG_TO_RAD ) ) {
|
||||||
|
i = 1;
|
||||||
|
} else if ( t->sun_angle > (FG_PI_2 + 5.75 * DEG_TO_RAD ) ) {
|
||||||
|
i = 2;
|
||||||
|
} else {
|
||||||
|
i = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("RENDERING STARS = %d (night)\n", i);
|
||||||
|
|
||||||
glDisable( GL_FOG );
|
glDisable( GL_FOG );
|
||||||
glDisable( GL_LIGHTING );
|
glDisable( GL_LIGHTING );
|
||||||
|
@ -221,7 +240,7 @@ void fgStarsRender() {
|
||||||
printf("Rotating stars by %.2f + %.2f\n", -angle * RAD_TO_DEG,
|
printf("Rotating stars by %.2f + %.2f\n", -angle * RAD_TO_DEG,
|
||||||
-warp * RAD_TO_DEG);
|
-warp * RAD_TO_DEG);
|
||||||
|
|
||||||
glCallList(stars);
|
glCallList(stars[i]);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glEnable( GL_LIGHTING );
|
glEnable( GL_LIGHTING );
|
||||||
|
@ -233,9 +252,12 @@ void fgStarsRender() {
|
||||||
|
|
||||||
|
|
||||||
/* $Log$
|
/* $Log$
|
||||||
/* Revision 1.8 1997/09/16 22:14:52 curt
|
/* Revision 1.9 1997/09/18 16:20:09 curt
|
||||||
/* Tweaked time of day lighting equations. Don't draw stars during the day.
|
/* At dusk/dawn add/remove stars in stages.
|
||||||
/*
|
/*
|
||||||
|
* Revision 1.8 1997/09/16 22:14:52 curt
|
||||||
|
* Tweaked time of day lighting equations. Don't draw stars during the day.
|
||||||
|
*
|
||||||
* Revision 1.7 1997/09/16 15:50:31 curt
|
* Revision 1.7 1997/09/16 15:50:31 curt
|
||||||
* Working on star alignment and time issues.
|
* Working on star alignment and time issues.
|
||||||
*
|
*
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
|
|
||||||
#define FG_MAX_STARS 500
|
#define FG_MAX_STARS 500
|
||||||
|
#define FG_STAR_LEVELS 4 /* how many star transitions */
|
||||||
#define FG_MIN_STAR_MAG 0.738750 /* magnitude of weakest star we'll display */
|
#define FG_MIN_STAR_MAG 0.738750 /* magnitude of weakest star we'll display */
|
||||||
|
|
||||||
/* Initialize the Star Management Subsystem */
|
/* Initialize the Star Management Subsystem */
|
||||||
|
@ -42,9 +43,12 @@ void fgStarsRender();
|
||||||
|
|
||||||
|
|
||||||
/* $Log$
|
/* $Log$
|
||||||
/* Revision 1.4 1997/09/05 01:36:00 curt
|
/* Revision 1.5 1997/09/18 16:20:09 curt
|
||||||
/* Working on getting stars right.
|
/* At dusk/dawn add/remove stars in stages.
|
||||||
/*
|
/*
|
||||||
|
* Revision 1.4 1997/09/05 01:36:00 curt
|
||||||
|
* Working on getting stars right.
|
||||||
|
*
|
||||||
* Revision 1.3 1997/08/29 17:55:28 curt
|
* Revision 1.3 1997/08/29 17:55:28 curt
|
||||||
* Worked on properly aligning the stars.
|
* Worked on properly aligning the stars.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue