1 /**************************************************************************
2 * stars.c -- data structures and routines for managing and rendering stars.
4 * Written by Curtis Olson, started August 1997.
6 * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * (Log is kept at end of this file)
24 **************************************************************************/
40 #include "../constants.h"
41 #include "../general.h"
43 #include "../GLUT/views.h"
44 #include "../Aircraft/aircraft.h"
47 #define EpochStart (631065600)
48 #define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
54 /* Initialize the Star Management Subsystem */
59 char line[256], name[256];
61 double right_ascension, declination, magnitude;
62 GLfloat mag[4] = {0.0, 0.0, 0.0, 1.0};
67 /* build the full path name to the stars data base file */
69 strcat(path, g->root_dir);
70 strcat(path, "/Scenery/");
71 strcat(path, "Stars.dat");
73 printf("Loading Stars: %s\n", path);
75 if ( (fd = fopen(path, "r")) == NULL ) {
76 printf("Cannot open star file: '%s'\n", path);
80 stars = glGenLists(1);
81 glNewList( stars, GL_COMPILE );
84 /* read in each line of the file */
86 while ( (fgets(line, 256, fd) != NULL) && (count < FG_MAX_STARS) ) {
89 /* advance to first non-whitespace character */
90 while ( (tmp_ptr[0] == ' ') || (tmp_ptr[0] == '\t') ) {
94 if ( tmp_ptr[0] == '#' ) {
96 } else if ( strlen(tmp_ptr) == 0 ) {
100 fscanf(fd, "%s %lf %lf %lf\n",
101 name, &right_ascension, &declination, &magnitude);
102 /* printf("Found star: %d %s, %.3f %.3f %.3f\n", count,
103 name, right_ascension, declination, magnitude); */
105 magnitude = magnitude * 0.8 + 0.2;
106 mag[0] = mag[1] = mag[2] = magnitude;
107 glColor3f( mag[0], mag[1], mag[2] );
108 glVertex3f( 190000.0 * sin(right_ascension) * cos(declination),
109 190000.0 * cos(right_ascension) * cos(declination),
110 190000.0 * sin(declination) );
112 } /* if valid line */
122 void fgStarsRender() {
127 f = ¤t_aircraft.flight;
130 printf("RENDERING STARS\n");
133 glDisable( GL_LIGHTING );
136 /* set lighting parameters for stars */
137 /* amb[0] = amb[1] = amb[2] = 1.0;
138 diff[0] = diff[1] = diff[2] = 1.0;
139 glLightfv(GL_LIGHT0, GL_AMBIENT, amb );
140 glLightfv(GL_LIGHT0, GL_DIFFUSE, diff ); */
142 glTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z );
144 angle = FG_2PI * fmod(DaysSinceEpoch(time(NULL)), 1.0);
145 glRotatef( -angle * RAD_TO_DEG, 0.0, 0.0, 1.0 );
146 printf("Rotating stars by %.2f\n", -angle * RAD_TO_DEG);
151 glEnable( GL_LIGHTING );
157 /* Revision 1.3 1997/08/29 17:55:28 curt
158 /* Worked on properly aligning the stars.
160 * Revision 1.2 1997/08/27 21:32:30 curt
161 * Restructured view calculation code. Added stars.
163 * Revision 1.1 1997/08/27 03:34:48 curt