1998-09-24 15:36:19 +00:00
|
|
|
// stars.cxx -- data structures and routines for managing and rendering stars.
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started August 1997.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
//*************************************************************************/
|
1998-01-07 03:16:15 +00:00
|
|
|
|
|
|
|
|
1998-04-24 00:45:00 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
1998-04-03 21:50:53 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_WINDOWS_H
|
1998-01-07 03:16:15 +00:00
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
1999-02-02 20:13:29 +00:00
|
|
|
#include "Include/compiler.h"
|
|
|
|
#ifdef FG_HAVE_STD_INCLUDES
|
|
|
|
# include <cmath>
|
|
|
|
# include <cstdio>
|
|
|
|
# include <cstring>
|
|
|
|
# include <ctime>
|
|
|
|
#else
|
|
|
|
# include <math.h>
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <string.h>
|
|
|
|
# include <time.h>
|
|
|
|
#endif
|
1998-11-23 21:48:09 +00:00
|
|
|
|
1998-08-27 17:01:55 +00:00
|
|
|
#include <string>
|
1998-01-07 03:16:15 +00:00
|
|
|
|
|
|
|
#include <GL/glut.h>
|
1998-01-19 19:26:51 +00:00
|
|
|
#include <XGL/xgl.h>
|
1998-01-07 03:16:15 +00:00
|
|
|
|
1998-10-16 23:26:44 +00:00
|
|
|
#include <Aircraft/aircraft.hxx>
|
1998-11-06 21:17:31 +00:00
|
|
|
#include <Debug/logstream.hxx>
|
1998-01-27 00:47:41 +00:00
|
|
|
#include <Include/fg_constants.h>
|
1998-09-24 15:36:19 +00:00
|
|
|
#include <Misc/fgstream.hxx>
|
1998-05-13 18:25:34 +00:00
|
|
|
#include <Main/options.hxx>
|
1998-04-22 13:21:26 +00:00
|
|
|
#include <Main/views.hxx>
|
1998-09-01 19:02:53 +00:00
|
|
|
#include <Misc/stopwatch.hxx>
|
1998-04-24 00:45:00 +00:00
|
|
|
#include <Time/fg_time.hxx>
|
1999-02-02 20:13:29 +00:00
|
|
|
#include "Misc/stopwatch.hxx"
|
1998-01-07 03:16:15 +00:00
|
|
|
|
1998-04-22 13:21:26 +00:00
|
|
|
#include "stars.hxx"
|
|
|
|
|
1999-02-02 20:13:29 +00:00
|
|
|
FG_USING_STD(getline);
|
1998-04-22 13:21:26 +00:00
|
|
|
|
1998-01-07 03:16:15 +00:00
|
|
|
#define EpochStart (631065600)
|
|
|
|
#define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
|
1998-08-10 20:33:09 +00:00
|
|
|
#define FG_MAX_STARS 3500
|
1998-01-07 03:16:15 +00:00
|
|
|
|
1998-09-24 15:36:19 +00:00
|
|
|
// Define four structures, each with varying amounts of stars
|
1998-08-10 20:33:09 +00:00
|
|
|
static GLint stars[FG_STAR_LEVELS];
|
1998-01-07 03:16:15 +00:00
|
|
|
|
|
|
|
|
1998-09-24 15:36:19 +00:00
|
|
|
// Initialize the Star Management Subsystem
|
1998-02-12 21:58:27 +00:00
|
|
|
int fgStarsInit( void ) {
|
1998-10-16 00:51:46 +00:00
|
|
|
Point3D starlist[FG_MAX_STARS];
|
1998-09-24 15:36:19 +00:00
|
|
|
// struct CelestialCoord pltPos;
|
1998-01-07 03:16:15 +00:00
|
|
|
double right_ascension, declination, magnitude;
|
1998-08-06 12:45:20 +00:00
|
|
|
double min_magnitude[FG_STAR_LEVELS];
|
1998-09-24 15:36:19 +00:00
|
|
|
// double ra_save, decl_save;
|
|
|
|
// double ra_save1, decl_save1;
|
1998-08-10 20:33:09 +00:00
|
|
|
int i, j, starcount, count;
|
1998-01-07 03:16:15 +00:00
|
|
|
|
1998-11-06 21:17:31 +00:00
|
|
|
FG_LOG( FG_ASTRO, FG_INFO, "Initializing stars" );
|
1998-01-07 03:16:15 +00:00
|
|
|
|
1998-08-06 12:45:20 +00:00
|
|
|
if ( FG_STAR_LEVELS < 4 ) {
|
1998-11-06 21:17:31 +00:00
|
|
|
FG_LOG( FG_ASTRO, FG_ALERT, "Big whups in stars.cxx" );
|
|
|
|
exit(-1);
|
1998-08-06 12:45:20 +00:00
|
|
|
}
|
|
|
|
|
1998-09-01 19:02:53 +00:00
|
|
|
// build the full path name to the stars data base file
|
|
|
|
string path = current_options.get_fg_root() + "/Astro/stars" + ".gz";
|
|
|
|
|
1998-11-06 21:17:31 +00:00
|
|
|
FG_LOG( FG_ASTRO, FG_INFO, " Loading stars from " << path );
|
1998-08-10 20:33:09 +00:00
|
|
|
|
1998-09-01 19:02:53 +00:00
|
|
|
fg_gzifstream in( path );
|
1998-11-06 21:17:31 +00:00
|
|
|
if ( ! in ) {
|
|
|
|
FG_LOG( FG_ASTRO, FG_ALERT, "Cannot open star file: " << path );
|
|
|
|
exit(-1);
|
|
|
|
}
|
1998-08-10 20:33:09 +00:00
|
|
|
|
|
|
|
starcount = 0;
|
|
|
|
|
1998-09-01 19:02:53 +00:00
|
|
|
StopWatch timer;
|
|
|
|
timer.start();
|
1998-08-10 20:33:09 +00:00
|
|
|
|
1998-09-01 19:02:53 +00:00
|
|
|
// read in each line of the file
|
|
|
|
while ( ! in.eof() && starcount < FG_MAX_STARS )
|
|
|
|
{
|
1998-11-06 14:46:59 +00:00
|
|
|
in >> skipcomment;
|
1998-09-01 19:02:53 +00:00
|
|
|
string name;
|
1998-11-06 14:46:59 +00:00
|
|
|
getline( in, name, ',' );
|
|
|
|
in >> starlist[starcount];
|
1998-09-01 19:02:53 +00:00
|
|
|
++starcount;
|
1998-08-10 20:33:09 +00:00
|
|
|
}
|
|
|
|
|
1998-09-01 19:02:53 +00:00
|
|
|
timer.stop();
|
1998-11-07 19:07:06 +00:00
|
|
|
FG_LOG( FG_ASTRO, FG_INFO,
|
|
|
|
"Loaded " << starcount << " stars in "
|
|
|
|
<< timer.elapsedSeconds() << " seconds" );
|
1998-09-01 19:02:53 +00:00
|
|
|
|
1998-08-06 12:45:20 +00:00
|
|
|
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;
|
|
|
|
|
1998-08-10 20:33:09 +00:00
|
|
|
// build the various star display lists
|
1998-01-07 03:16:15 +00:00
|
|
|
for ( i = 0; i < FG_STAR_LEVELS; i++ ) {
|
1998-02-12 21:58:27 +00:00
|
|
|
|
1998-01-07 03:16:15 +00:00
|
|
|
stars[i] = xglGenLists(1);
|
|
|
|
xglNewList( stars[i], GL_COMPILE );
|
|
|
|
xglBegin( GL_POINTS );
|
|
|
|
|
1998-08-10 20:33:09 +00:00
|
|
|
count = 0;
|
|
|
|
|
|
|
|
for ( j = 0; j < starcount; j++ ) {
|
1998-10-16 00:51:46 +00:00
|
|
|
magnitude = starlist[j].z();
|
1998-08-10 20:33:09 +00:00
|
|
|
// printf("magnitude = %.2f\n", magnitude);
|
|
|
|
|
|
|
|
if ( magnitude < min_magnitude[i] ) {
|
1998-10-16 00:51:46 +00:00
|
|
|
right_ascension = starlist[j].x();
|
|
|
|
declination = starlist[j].y();
|
1998-08-10 20:33:09 +00:00
|
|
|
|
|
|
|
count++;
|
|
|
|
|
1998-09-24 15:36:19 +00:00
|
|
|
// scale magnitudes to (0.0 - 1.0)
|
1998-08-10 20:33:09 +00:00
|
|
|
magnitude = (0.0 - magnitude) / 5.0 + 1.0;
|
|
|
|
|
1998-09-24 15:36:19 +00:00
|
|
|
// scale magnitudes again so they look ok
|
1998-08-10 20:33:09 +00:00
|
|
|
if ( magnitude > 1.0 ) { magnitude = 1.0; }
|
|
|
|
if ( magnitude < 0.0 ) { magnitude = 0.0; }
|
1998-09-24 15:36:19 +00:00
|
|
|
// magnitude =
|
|
|
|
// magnitude * 0.7 + (((FG_STAR_LEVELS - 1) - i) * 0.042);
|
|
|
|
|
1998-08-10 20:33:09 +00:00
|
|
|
magnitude = magnitude * 0.9 +
|
|
|
|
(((FG_STAR_LEVELS - 1) - i) * 0.014);
|
1998-09-24 15:36:19 +00:00
|
|
|
// printf(" Found star: %d %s, %.3f %.3f %.3f\n", count,
|
|
|
|
// name, right_ascension, declination, magnitude);
|
1998-08-06 12:45:20 +00:00
|
|
|
|
1998-08-10 20:33:09 +00:00
|
|
|
xglColor3f( magnitude, magnitude, magnitude );
|
1998-09-24 15:36:19 +00:00
|
|
|
//xglColor3f(0,0,0);*/
|
1998-08-10 20:33:09 +00:00
|
|
|
xglVertex3f( 50000.0*cos(right_ascension)*cos(declination),
|
|
|
|
50000.0*sin(right_ascension)*cos(declination),
|
|
|
|
50000.0*sin(declination) );
|
|
|
|
}
|
1998-09-24 15:36:19 +00:00
|
|
|
} // while
|
1998-01-07 03:16:15 +00:00
|
|
|
|
|
|
|
xglEnd();
|
|
|
|
|
|
|
|
/*
|
|
|
|
xglBegin(GL_LINE_LOOP);
|
|
|
|
xglColor3f(1.0, 0.0, 0.0);
|
|
|
|
xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
|
|
|
|
50000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
|
|
|
|
50000.0 * sin(decl_save-0.2) );
|
|
|
|
xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save-0.2),
|
|
|
|
50000.0 * sin(ra_save+0.2) * cos(decl_save-0.2),
|
|
|
|
50000.0 * sin(decl_save-0.2) );
|
|
|
|
xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save+0.2),
|
|
|
|
50000.0 * sin(ra_save+0.2) * cos(decl_save+0.2),
|
|
|
|
50000.0 * sin(decl_save+0.2) );
|
|
|
|
xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
|
|
|
|
50000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
|
|
|
|
50000.0 * sin(decl_save+0.2) );
|
|
|
|
xglEnd();
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
xglBegin(GL_LINE_LOOP);
|
|
|
|
xglColor3f(0.0, 1.0, 0.0);
|
|
|
|
xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
|
|
|
|
50000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
|
|
|
|
50000.0 * sin(decl_save1-0.2) );
|
|
|
|
xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1-0.2),
|
|
|
|
50000.0 * sin(ra_save1+0.2) * cos(decl_save1-0.2),
|
|
|
|
50000.0 * sin(decl_save1-0.2) );
|
|
|
|
xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1+0.2),
|
|
|
|
50000.0 * sin(ra_save1+0.2) * cos(decl_save1+0.2),
|
|
|
|
50000.0 * sin(decl_save1+0.2) );
|
|
|
|
xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
|
|
|
|
50000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
|
|
|
|
50000.0 * sin(decl_save1+0.2) );
|
|
|
|
xglEnd();
|
|
|
|
*/
|
1998-02-12 21:58:27 +00:00
|
|
|
|
1998-01-07 03:16:15 +00:00
|
|
|
xglEndList();
|
1998-08-10 20:33:09 +00:00
|
|
|
|
1998-11-06 21:17:31 +00:00
|
|
|
FG_LOG( FG_ASTRO, FG_INFO,
|
|
|
|
" Loading " << count << " stars brighter than "
|
|
|
|
<< min_magnitude[i] );
|
1998-01-07 03:16:15 +00:00
|
|
|
}
|
1998-02-12 21:58:27 +00:00
|
|
|
|
|
|
|
return 1; // OK, we got here because initialization worked.
|
1998-01-07 03:16:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-24 15:36:19 +00:00
|
|
|
// Draw the Stars
|
1998-01-19 18:40:15 +00:00
|
|
|
void fgStarsRender( void ) {
|
1999-02-05 21:28:09 +00:00
|
|
|
FGInterface *f;
|
1998-04-26 05:10:00 +00:00
|
|
|
fgLIGHT *l;
|
1999-04-08 19:53:46 +00:00
|
|
|
FGTime *t;
|
1998-01-07 03:16:15 +00:00
|
|
|
int i;
|
|
|
|
|
1998-12-05 15:53:59 +00:00
|
|
|
f = current_aircraft.fdm_state;
|
1998-01-07 03:16:15 +00:00
|
|
|
l = &cur_light_params;
|
1999-04-08 19:53:46 +00:00
|
|
|
t = FGTime::cur_time_params;
|
1998-01-07 03:16:15 +00:00
|
|
|
|
1998-09-24 15:36:19 +00:00
|
|
|
// FG_PI_2 + 0.1 is about 6 degrees after sundown and before sunrise
|
1998-01-07 03:16:15 +00:00
|
|
|
|
1998-09-24 15:36:19 +00:00
|
|
|
// t->sun_angle = 3.0; // to force stars to be drawn (for testing)
|
1998-01-07 03:16:15 +00:00
|
|
|
|
1998-09-24 15:36:19 +00:00
|
|
|
// render the stars
|
1998-01-07 03:16:15 +00:00
|
|
|
if ( l->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) {
|
1998-09-24 15:36:19 +00:00
|
|
|
// determine which star structure to draw
|
1998-08-06 12:45:20 +00:00
|
|
|
if ( l->sun_angle > (FG_PI_2 + 10.0 * DEG_TO_RAD ) ) {
|
1998-01-07 03:16:15 +00:00
|
|
|
i = 0;
|
1998-08-06 12:45:20 +00:00
|
|
|
} else if ( l->sun_angle > (FG_PI_2 + 8.8 * DEG_TO_RAD ) ) {
|
1998-01-07 03:16:15 +00:00
|
|
|
i = 1;
|
1998-08-06 12:45:20 +00:00
|
|
|
} else if ( l->sun_angle > (FG_PI_2 + 7.5 * DEG_TO_RAD ) ) {
|
1998-01-07 03:16:15 +00:00
|
|
|
i = 2;
|
1998-08-06 12:45:20 +00:00
|
|
|
} else if ( l->sun_angle > (FG_PI_2 + 7.0 * DEG_TO_RAD ) ) {
|
1998-01-07 03:16:15 +00:00
|
|
|
i = 3;
|
1998-08-06 12:45:20 +00:00
|
|
|
} else if ( l->sun_angle > (FG_PI_2 + 6.5 * DEG_TO_RAD ) ) {
|
|
|
|
i = 4;
|
|
|
|
} else if ( l->sun_angle > (FG_PI_2 + 6.0 * DEG_TO_RAD ) ) {
|
|
|
|
i = 5;
|
|
|
|
} else if ( l->sun_angle > (FG_PI_2 + 5.5 * DEG_TO_RAD ) ) {
|
|
|
|
i = 6;
|
|
|
|
} else {
|
|
|
|
i = 7;
|
1998-01-07 03:16:15 +00:00
|
|
|
}
|
|
|
|
|
1998-09-24 15:36:19 +00:00
|
|
|
// printf("RENDERING STARS = %d (night)\n", i);
|
1998-01-07 03:16:15 +00:00
|
|
|
|
|
|
|
xglCallList(stars[i]);
|
|
|
|
} else {
|
1998-09-24 15:36:19 +00:00
|
|
|
// printf("not RENDERING STARS (day)\n");
|
1998-01-07 03:16:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|