1997-08-27 03:34:48 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* stars.c -- data structures and routines for managing and rendering stars.
|
|
|
|
*
|
|
|
|
* Written by Curtis Olson, started August 1997.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
|
|
|
*
|
|
|
|
* 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$
|
|
|
|
* (Log is kept at end of this file)
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1997-08-29 17:55:27 +00:00
|
|
|
#include <time.h>
|
1997-08-27 03:34:48 +00:00
|
|
|
|
|
|
|
#include <GL/glut.h>
|
|
|
|
|
1997-10-25 03:18:26 +00:00
|
|
|
#include "orbits.h"
|
|
|
|
#include "planets.h"
|
1997-08-27 03:34:48 +00:00
|
|
|
#include "stars.h"
|
|
|
|
|
1997-08-29 17:55:27 +00:00
|
|
|
#include "../constants.h"
|
1997-08-27 03:34:48 +00:00
|
|
|
#include "../general.h"
|
1997-08-29 17:55:27 +00:00
|
|
|
#include "../Aircraft/aircraft.h"
|
1997-10-28 21:00:20 +00:00
|
|
|
#include "../Main/views.h"
|
1997-09-16 15:50:29 +00:00
|
|
|
#include "../Time/fg_time.h"
|
1997-08-29 17:55:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define EpochStart (631065600)
|
|
|
|
#define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
|
1997-08-27 21:32:23 +00:00
|
|
|
|
1997-08-27 03:34:48 +00:00
|
|
|
|
1997-09-18 16:20:08 +00:00
|
|
|
/* Define four structures, each with varying amounts of stars */
|
1997-11-25 19:25:27 +00:00
|
|
|
/* static */ GLint stars[FG_STAR_LEVELS];
|
1997-08-27 03:34:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Initialize the Star Management Subsystem */
|
|
|
|
void fgStarsInit() {
|
|
|
|
FILE *fd;
|
1997-08-27 21:32:23 +00:00
|
|
|
struct GENERAL *g;
|
1997-10-25 03:18:26 +00:00
|
|
|
struct CelestialCoord pltPos;
|
1997-08-27 03:34:48 +00:00
|
|
|
char path[1024];
|
|
|
|
char line[256], name[256];
|
1997-09-05 01:35:53 +00:00
|
|
|
char *front, *end;
|
1997-08-27 03:34:48 +00:00
|
|
|
double right_ascension, declination, magnitude;
|
1997-09-05 01:35:53 +00:00
|
|
|
double ra_save, decl_save;
|
|
|
|
double ra_save1, decl_save1;
|
1997-10-25 03:18:26 +00:00
|
|
|
int count, i, j, max_stars;
|
1997-08-27 03:34:48 +00:00
|
|
|
|
|
|
|
g = &general;
|
|
|
|
|
|
|
|
/* build the full path name to the stars data base file */
|
|
|
|
path[0] = '\0';
|
|
|
|
strcat(path, g->root_dir);
|
|
|
|
strcat(path, "/Scenery/");
|
|
|
|
strcat(path, "Stars.dat");
|
|
|
|
|
1997-09-18 16:20:08 +00:00
|
|
|
max_stars = FG_MAX_STARS;
|
1997-08-27 03:34:48 +00:00
|
|
|
|
1997-09-18 16:20:08 +00:00
|
|
|
for ( i = 0; i < FG_STAR_LEVELS; i++ ) {
|
|
|
|
printf("Loading %d Stars: %s\n", max_stars, path);
|
1997-09-05 01:35:53 +00:00
|
|
|
|
1997-09-18 16:20:08 +00:00
|
|
|
if ( (fd = fopen(path, "r")) == NULL ) {
|
|
|
|
printf("Cannot open star file: '%s'\n", path);
|
|
|
|
return;
|
1997-08-27 03:34:48 +00:00
|
|
|
}
|
1997-09-18 16:20:08 +00:00
|
|
|
|
|
|
|
stars[i] = glGenLists(1);
|
|
|
|
glNewList( stars[i], GL_COMPILE );
|
|
|
|
glBegin( GL_POINTS );
|
1997-08-27 03:34:48 +00:00
|
|
|
|
1997-09-18 16:20:08 +00:00
|
|
|
/* read in each line of the file */
|
|
|
|
count = 0;
|
|
|
|
while ( (fgets(line, 256, fd) != NULL) && (count < max_stars) ) {
|
|
|
|
front = line;
|
1997-09-05 01:35:53 +00:00
|
|
|
|
1997-09-18 16:20:08 +00:00
|
|
|
/* printf("Read line = %s", front); */
|
1997-09-05 01:35:53 +00:00
|
|
|
|
1997-09-18 16:20:08 +00:00
|
|
|
/* advance to first non-whitespace character */
|
|
|
|
while ( (front[0] == ' ') || (front[0] == '\t') ) {
|
|
|
|
front++;
|
1997-09-05 01:35:53 +00:00
|
|
|
}
|
|
|
|
|
1997-09-18 16:20:08 +00:00
|
|
|
/* printf("Line length (after trimming) = %d\n", strlen(front)); */
|
|
|
|
|
|
|
|
if ( front[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++;
|
|
|
|
|
|
|
|
sscanf(front, "%lf,%lf,%lf\n",
|
|
|
|
&right_ascension, &declination, &magnitude);
|
|
|
|
|
1997-09-22 14:44:19 +00:00
|
|
|
if ( strcmp(name, "Betelgeuse") == 0 ) {
|
1997-09-18 16:20:08 +00:00
|
|
|
printf(" *** Marking %s\n", name);
|
|
|
|
ra_save = right_ascension;
|
|
|
|
decl_save = declination;
|
|
|
|
}
|
|
|
|
|
1997-09-22 14:44:19 +00:00
|
|
|
if ( strcmp(name, "Alnilam") == 0 ) {
|
1997-09-18 16:20:08 +00:00
|
|
|
printf(" *** Marking %s\n", name);
|
|
|
|
ra_save1 = right_ascension;
|
|
|
|
decl_save1 = declination;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scale magnitudes to (0.0 - 1.0) */
|
|
|
|
magnitude = (0.0 - magnitude) / 5.0 + 1.0;
|
|
|
|
|
|
|
|
/* 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);
|
1997-09-22 14:44:19 +00:00
|
|
|
/* printf("Found star: %d %s, %.3f %.3f %.3f\n", count,
|
|
|
|
name, right_ascension, declination, magnitude); */
|
1997-09-18 16:20:08 +00:00
|
|
|
|
|
|
|
glColor3f( magnitude, magnitude, magnitude );
|
1997-10-25 03:18:26 +00:00
|
|
|
/*glColor3f(0,0,0);*/
|
1997-09-22 14:44:19 +00:00
|
|
|
glVertex3f( 190000.0 * cos(right_ascension) * cos(declination),
|
|
|
|
190000.0 * sin(right_ascension) * cos(declination),
|
1997-09-18 16:20:08 +00:00
|
|
|
190000.0 * sin(declination) );
|
1997-10-25 03:18:26 +00:00
|
|
|
|
1997-09-18 16:20:08 +00:00
|
|
|
count++;
|
|
|
|
} /* if valid line */
|
|
|
|
|
|
|
|
} /* while */
|
|
|
|
|
|
|
|
fclose(fd);
|
|
|
|
|
1997-10-25 03:18:26 +00:00
|
|
|
/* Add the planets to all four display lists */
|
|
|
|
for ( j = 2; j < 9; j++ ) {
|
|
|
|
pltPos = fgCalculatePlanet(pltOrbElements[j],
|
|
|
|
pltOrbElements[0], cur_time_params);
|
|
|
|
printf("Planet found at %f (ra), %f (dec)\n",
|
|
|
|
pltPos.RightAscension, pltPos.Declination);
|
|
|
|
/* give the planets a temporary color, for testing purposes */
|
|
|
|
glColor3f( 1.0, 0.0, 0.0);
|
|
|
|
glVertex3f( 190000.0 * cos(pltPos.RightAscension) *
|
|
|
|
cos(pltPos.Declination),
|
|
|
|
190000.0 * sin(pltPos.RightAscension) *
|
|
|
|
cos(pltPos.Declination),
|
|
|
|
190000.0 * sin(pltPos.Declination) );
|
|
|
|
}
|
1997-09-18 16:20:08 +00:00
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glBegin(GL_LINE_LOOP);
|
1997-09-05 01:35:53 +00:00
|
|
|
glColor3f(1.0, 0.0, 0.0);
|
1997-09-22 14:44:19 +00:00
|
|
|
glVertex3f( 190000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
|
|
|
|
190000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
|
1997-09-05 01:35:53 +00:00
|
|
|
190000.0 * sin(decl_save-0.2) );
|
1997-09-22 14:44:19 +00:00
|
|
|
glVertex3f( 190000.0 * cos(ra_save+0.2) * cos(decl_save-0.2),
|
|
|
|
190000.0 * sin(ra_save+0.2) * cos(decl_save-0.2),
|
1997-09-05 01:35:53 +00:00
|
|
|
190000.0 * sin(decl_save-0.2) );
|
1997-09-22 14:44:19 +00:00
|
|
|
glVertex3f( 190000.0 * cos(ra_save+0.2) * cos(decl_save+0.2),
|
|
|
|
190000.0 * sin(ra_save+0.2) * cos(decl_save+0.2),
|
1997-09-05 01:35:53 +00:00
|
|
|
190000.0 * sin(decl_save+0.2) );
|
1997-09-22 14:44:19 +00:00
|
|
|
glVertex3f( 190000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
|
|
|
|
190000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
|
1997-09-05 01:35:53 +00:00
|
|
|
190000.0 * sin(decl_save+0.2) );
|
1997-09-18 16:20:08 +00:00
|
|
|
glEnd();
|
1997-09-05 01:35:53 +00:00
|
|
|
|
1997-09-18 16:20:08 +00:00
|
|
|
glBegin(GL_LINE_LOOP);
|
1997-09-05 01:35:53 +00:00
|
|
|
glColor3f(0.0, 1.0, 0.0);
|
1997-09-22 14:44:19 +00:00
|
|
|
glVertex3f( 190000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
|
|
|
|
190000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
|
1997-09-05 01:35:53 +00:00
|
|
|
190000.0 * sin(decl_save1-0.2) );
|
1997-09-22 14:44:19 +00:00
|
|
|
glVertex3f( 190000.0 * cos(ra_save1+0.2) * cos(decl_save1-0.2),
|
|
|
|
190000.0 * sin(ra_save1+0.2) * cos(decl_save1-0.2),
|
1997-09-05 01:35:53 +00:00
|
|
|
190000.0 * sin(decl_save1-0.2) );
|
1997-09-22 14:44:19 +00:00
|
|
|
glVertex3f( 190000.0 * cos(ra_save1+0.2) * cos(decl_save1+0.2),
|
|
|
|
190000.0 * sin(ra_save1+0.2) * cos(decl_save1+0.2),
|
1997-09-05 01:35:53 +00:00
|
|
|
190000.0 * sin(decl_save1+0.2) );
|
1997-09-22 14:44:19 +00:00
|
|
|
glVertex3f( 190000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
|
|
|
|
190000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
|
1997-09-05 01:35:53 +00:00
|
|
|
190000.0 * sin(decl_save1+0.2) );
|
1997-09-18 16:20:08 +00:00
|
|
|
glEnd();
|
1997-09-05 01:35:53 +00:00
|
|
|
|
1997-09-18 16:20:08 +00:00
|
|
|
glEndList();
|
|
|
|
|
|
|
|
max_stars /= 2;
|
|
|
|
}
|
1997-08-27 03:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Draw the Stars */
|
|
|
|
void fgStarsRender() {
|
1997-08-29 17:55:27 +00:00
|
|
|
struct FLIGHT *f;
|
1997-08-27 21:32:23 +00:00
|
|
|
struct VIEW *v;
|
1997-09-16 15:50:29 +00:00
|
|
|
struct fgTIME *t;
|
1997-09-18 16:20:08 +00:00
|
|
|
int i;
|
1997-08-27 21:32:23 +00:00
|
|
|
|
1997-08-29 17:55:27 +00:00
|
|
|
f = ¤t_aircraft.flight;
|
1997-09-16 15:50:29 +00:00
|
|
|
t = &cur_time_params;
|
1997-08-27 21:32:23 +00:00
|
|
|
v = ¤t_view;
|
|
|
|
|
1997-09-16 22:14:47 +00:00
|
|
|
/* FG_PI_2 + 0.1 is about 6 degrees after sundown and before sunrise */
|
1997-08-27 21:32:23 +00:00
|
|
|
|
1997-09-23 00:29:27 +00:00
|
|
|
/* t->sun_angle = 3.0; */ /* to force stars to be drawn (for testing) */
|
1997-09-22 14:44:19 +00:00
|
|
|
|
1997-11-25 19:25:27 +00:00
|
|
|
/* render the stars */
|
1997-09-18 16:20:08 +00:00
|
|
|
if ( t->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) {
|
|
|
|
/* 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);
|
1997-08-27 21:32:23 +00:00
|
|
|
|
1997-09-16 22:14:47 +00:00
|
|
|
glDisable( GL_LIGHTING );
|
1997-09-18 16:20:08 +00:00
|
|
|
glCallList(stars[i]);
|
1997-09-16 22:14:47 +00:00
|
|
|
glEnable( GL_LIGHTING );
|
|
|
|
} else {
|
|
|
|
printf("not RENDERING STARS (day)\n");
|
|
|
|
}
|
1997-08-27 03:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* $Log$
|
1997-11-25 19:25:27 +00:00
|
|
|
/* Revision 1.16 1997/11/25 19:25:38 curt
|
|
|
|
/* Changes to integrate Durk's moon/sun code updates + clean up.
|
1997-08-27 03:34:48 +00:00
|
|
|
/*
|
1997-11-25 19:25:27 +00:00
|
|
|
* Revision 1.15 1997/10/30 12:38:45 curt
|
|
|
|
* Working on new scenery subsystem.
|
|
|
|
*
|
1997-10-30 12:38:35 +00:00
|
|
|
* Revision 1.14 1997/10/28 21:00:22 curt
|
|
|
|
* Changing to new terrain format.
|
|
|
|
*
|
1997-10-28 21:00:20 +00:00
|
|
|
* Revision 1.13 1997/10/25 03:18:28 curt
|
|
|
|
* Incorporated sun, moon, and planet position and rendering code contributed
|
|
|
|
* by Durk Talsma.
|
|
|
|
*
|
1997-10-25 03:18:26 +00:00
|
|
|
* Revision 1.12 1997/09/23 00:29:43 curt
|
|
|
|
* Tweaks to get things to compile with gcc-win32.
|
|
|
|
*
|
1997-09-23 00:29:27 +00:00
|
|
|
* Revision 1.11 1997/09/22 14:44:21 curt
|
|
|
|
* Continuing to try to align stars correctly.
|
|
|
|
*
|
1997-09-22 14:44:19 +00:00
|
|
|
* Revision 1.10 1997/09/20 03:34:32 curt
|
|
|
|
* Still trying to get those durned stars aligned properly.
|
|
|
|
*
|
1997-09-20 03:34:25 +00:00
|
|
|
* Revision 1.9 1997/09/18 16:20:09 curt
|
|
|
|
* At dusk/dawn add/remove stars in stages.
|
|
|
|
*
|
1997-09-18 16:20:08 +00:00
|
|
|
* Revision 1.8 1997/09/16 22:14:52 curt
|
|
|
|
* Tweaked time of day lighting equations. Don't draw stars during the day.
|
|
|
|
*
|
1997-09-16 22:14:47 +00:00
|
|
|
* Revision 1.7 1997/09/16 15:50:31 curt
|
|
|
|
* Working on star alignment and time issues.
|
|
|
|
*
|
1997-09-16 15:50:29 +00:00
|
|
|
* Revision 1.6 1997/09/05 14:17:31 curt
|
|
|
|
* More tweaking with stars.
|
|
|
|
*
|
1997-09-05 14:17:26 +00:00
|
|
|
* Revision 1.5 1997/09/05 01:35:59 curt
|
|
|
|
* Working on getting stars right.
|
|
|
|
*
|
1997-09-05 01:35:53 +00:00
|
|
|
* Revision 1.4 1997/09/04 02:17:38 curt
|
|
|
|
* Shufflin' stuff.
|
|
|
|
*
|
1997-09-04 02:17:18 +00:00
|
|
|
* Revision 1.3 1997/08/29 17:55:28 curt
|
|
|
|
* Worked on properly aligning the stars.
|
|
|
|
*
|
1997-08-29 17:55:27 +00:00
|
|
|
* Revision 1.2 1997/08/27 21:32:30 curt
|
|
|
|
* Restructured view calculation code. Added stars.
|
|
|
|
*
|
1997-08-27 21:32:23 +00:00
|
|
|
* Revision 1.1 1997/08/27 03:34:48 curt
|
1997-08-29 17:55:27 +00:00
|
|
|
* Initial revision.
|
1997-08-27 21:32:23 +00:00
|
|
|
*
|
1997-08-27 03:34:48 +00:00
|
|
|
*/
|