Rewrote star loading and rendering to:
1. significantly improve load speed 2. transition from no stars to stars through eight stages.
This commit is contained in:
parent
5e9a45af0c
commit
9568e79ac5
1 changed files with 99 additions and 89 deletions
110
Astro/stars.cxx
110
Astro/stars.cxx
|
@ -43,6 +43,7 @@
|
|||
#include <Aircraft/aircraft.h>
|
||||
#include <Debug/fg_debug.h>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Include/fg_types.h>
|
||||
#include <Include/fg_zlib.h>
|
||||
#include <Main/options.hxx>
|
||||
#include <Main/views.hxx>
|
||||
|
@ -55,14 +56,15 @@
|
|||
|
||||
#define EpochStart (631065600)
|
||||
#define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
|
||||
|
||||
#define FG_MAX_STARS 3500
|
||||
|
||||
/* Define four structures, each with varying amounts of stars */
|
||||
/* static */ GLint stars[FG_STAR_LEVELS];
|
||||
static GLint stars[FG_STAR_LEVELS];
|
||||
|
||||
|
||||
/* Initialize the Star Management Subsystem */
|
||||
int fgStarsInit( void ) {
|
||||
fgPoint3d starlist[FG_MAX_STARS];
|
||||
fgFile fd;
|
||||
/* struct CelestialCoord pltPos; */
|
||||
char path[256], gzpath[256];
|
||||
|
@ -72,7 +74,7 @@ int fgStarsInit( void ) {
|
|||
double min_magnitude[FG_STAR_LEVELS];
|
||||
/* double ra_save, decl_save; */
|
||||
/* double ra_save1, decl_save1; */
|
||||
int i;
|
||||
int i, j, starcount, count;
|
||||
|
||||
fgPrintf( FG_ASTRO, FG_INFO, "Initializing stars\n");
|
||||
|
||||
|
@ -85,21 +87,9 @@ int fgStarsInit( void ) {
|
|||
fgPrintf( FG_ASTRO, FG_EXIT, "Big whups in stars.cxx\n");
|
||||
}
|
||||
|
||||
min_magnitude[0] = 4.2;
|
||||
min_magnitude[1] = 3.6;
|
||||
min_magnitude[2] = 3.0;
|
||||
min_magnitude[3] = 2.4;
|
||||
min_magnitude[4] = 1.8;
|
||||
min_magnitude[5] = 1.2;
|
||||
min_magnitude[6] = 0.6;
|
||||
min_magnitude[7] = 0.0;
|
||||
|
||||
|
||||
for ( i = 0; i < FG_STAR_LEVELS; i++ ) {
|
||||
fgPrintf( FG_ASTRO, FG_INFO,
|
||||
" Loading stars brighter than %.2f from %2\n",
|
||||
min_magnitude[i], path);
|
||||
fgPrintf( FG_ASTRO, FG_INFO, " Loading stars from %s\n", path);
|
||||
|
||||
// load star data file
|
||||
if ( (fd = fgopen(path, "rb")) == NULL ) {
|
||||
strcpy(gzpath, path);
|
||||
strcat(gzpath, ".gz");
|
||||
|
@ -110,31 +100,29 @@ int fgStarsInit( void ) {
|
|||
}
|
||||
}
|
||||
|
||||
stars[i] = xglGenLists(1);
|
||||
xglNewList( stars[i], GL_COMPILE );
|
||||
xglBegin( GL_POINTS );
|
||||
starcount = 0;
|
||||
|
||||
/* read in each line of the file */
|
||||
while ( fggets(fd, line, 256) != NULL ) {
|
||||
// read in each line of the file
|
||||
while ( (fggets(fd, line, 256) != NULL) && (starcount < FG_MAX_STARS) ) {
|
||||
front = line;
|
||||
|
||||
/* printf(" Read line = %s", front); */
|
||||
// printf(" Read line = %s", front);
|
||||
|
||||
/* advance to first non-whitespace character */
|
||||
// advance to first non-whitespace character
|
||||
while ( (front[0] == ' ') || (front[0] == '\t') ) {
|
||||
front++;
|
||||
}
|
||||
|
||||
/* printf(" Line length (after trimming) = %d\n", strlen(front));*/
|
||||
// printf(" Line length (after trimming) = %d\n", strlen(front));
|
||||
|
||||
if ( front[0] == '#' ) {
|
||||
/* comment */
|
||||
// comment
|
||||
} else if ( strlen(front) <= 1 ) {
|
||||
/* blank line */
|
||||
// blank line
|
||||
} else {
|
||||
/* star data line */
|
||||
// star data line
|
||||
|
||||
/* get name */
|
||||
// get name
|
||||
end = front;
|
||||
while ( end[0] != ',' ) {
|
||||
end++;
|
||||
|
@ -146,24 +134,41 @@ int fgStarsInit( void ) {
|
|||
|
||||
sscanf(front, "%lf,%lf,%lf\n",
|
||||
&right_ascension, &declination, &magnitude);
|
||||
|
||||
/*
|
||||
if ( strcmp(name, "Betelgeuse") == 0 ) {
|
||||
printf(" *** Marking %s\n", name);
|
||||
ra_save = right_ascension;
|
||||
decl_save = declination;
|
||||
starlist[starcount].x = right_ascension;
|
||||
starlist[starcount].y = declination;
|
||||
starlist[starcount].z = magnitude;
|
||||
starcount++;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
if ( strcmp(name, "Alnilam") == 0 ) {
|
||||
printf(" *** Marking %s\n", name);
|
||||
ra_save1 = right_ascension;
|
||||
decl_save1 = declination;
|
||||
}
|
||||
*/
|
||||
|
||||
min_magnitude[0] = 4.2;
|
||||
min_magnitude[1] = 3.6;
|
||||
min_magnitude[2] = 3.0;
|
||||
min_magnitude[3] = 2.4;
|
||||
min_magnitude[4] = 1.8;
|
||||
min_magnitude[5] = 1.2;
|
||||
min_magnitude[6] = 0.6;
|
||||
min_magnitude[7] = 0.0;
|
||||
|
||||
// build the various star display lists
|
||||
for ( i = 0; i < FG_STAR_LEVELS; i++ ) {
|
||||
|
||||
stars[i] = xglGenLists(1);
|
||||
xglNewList( stars[i], GL_COMPILE );
|
||||
xglBegin( GL_POINTS );
|
||||
|
||||
count = 0;
|
||||
|
||||
for ( j = 0; j < starcount; j++ ) {
|
||||
magnitude = starlist[j].z;
|
||||
// printf("magnitude = %.2f\n", magnitude);
|
||||
|
||||
if ( magnitude < min_magnitude[i] ) {
|
||||
right_ascension = starlist[j].x;
|
||||
declination = starlist[j].y;
|
||||
|
||||
count++;
|
||||
|
||||
/* scale magnitudes to (0.0 - 1.0) */
|
||||
magnitude = (0.0 - magnitude) / 5.0 + 1.0;
|
||||
|
||||
|
@ -184,12 +189,8 @@ int fgStarsInit( void ) {
|
|||
50000.0*sin(right_ascension)*cos(declination),
|
||||
50000.0*sin(declination) );
|
||||
}
|
||||
} // valid line
|
||||
|
||||
} /* while */
|
||||
|
||||
fgclose(fd);
|
||||
|
||||
xglEnd();
|
||||
|
||||
/*
|
||||
|
@ -229,6 +230,10 @@ int fgStarsInit( void ) {
|
|||
*/
|
||||
|
||||
xglEndList();
|
||||
|
||||
fgPrintf( FG_ASTRO, FG_INFO,
|
||||
" Loading %d stars brighter than %.2f\n",
|
||||
count, min_magnitude[i]);
|
||||
}
|
||||
|
||||
return 1; // OK, we got here because initialization worked.
|
||||
|
@ -283,10 +288,15 @@ void fgStarsRender( void ) {
|
|||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.9 1998/08/06 12:45:20 curt
|
||||
/* Modified to bring in stars in 8 increments based on magnitude, not number
|
||||
/* of stars.
|
||||
/* Revision 1.10 1998/08/10 20:33:09 curt
|
||||
/* Rewrote star loading and rendering to:
|
||||
/* 1. significantly improve load speed
|
||||
/* 2. transition from no stars to stars through eight stages.
|
||||
/*
|
||||
* Revision 1.9 1998/08/06 12:45:20 curt
|
||||
* Modified to bring in stars in 8 increments based on magnitude, not number
|
||||
* of stars.
|
||||
*
|
||||
* Revision 1.8 1998/07/13 21:00:10 curt
|
||||
* Wrote access functions for current fgOPTIONS.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue