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 double ra_save, decl_save;
63 double ra_save1, decl_save1;
64 double ra_save2, decl_save2;
65 GLfloat mag[4] = {0.0, 0.0, 0.0, 1.0};
70 /* build the full path name to the stars data base file */
72 strcat(path, g->root_dir);
73 strcat(path, "/Scenery/");
74 strcat(path, "Stars.dat");
76 printf("Loading Stars: %s\n", path);
78 if ( (fd = fopen(path, "r")) == NULL ) {
79 printf("Cannot open star file: '%s'\n", path);
83 stars = glGenLists(1);
84 glNewList( stars, GL_COMPILE );
87 /* read in each line of the file */
89 while ( (fgets(line, 256, fd) != NULL) && (count < FG_MAX_STARS) ) {
92 /* printf("Read line = %s", front); */
94 /* advance to first non-whitespace character */
95 while ( (front[0] == ' ') || (front[0] == '\t') ) {
99 /* printf("Line length (after trimming) = %d\n", strlen(front)); */
101 if ( front[0] == '#' ) {
103 } else if ( strlen(front) <= 1 ) {
110 while ( end[0] != ',' ) {
118 sscanf(front, "%lf,%lf,%lf\n",
119 &right_ascension, &declination, &magnitude);
121 if ( strcmp(name, "Deneb") == 0 ) {
122 printf("\n*** Marking %s\n\n", name);
123 ra_save = right_ascension;
124 decl_save = declination;
127 if ( strcmp(name, "Alderamin") == 0 ) {
128 printf("\n*** Marking %s\n\n", name);
129 ra_save1 = right_ascension;
130 decl_save1 = declination;
133 /* scale magnitudes to (0.0 - 1.0) */
134 magnitude = (-1.46 - magnitude) / 10.0 + 1.0;
136 /* scale magnitudes again so they look ok */
137 magnitude = magnitude * 0.8 + 0.2;
138 mag[0] = mag[1] = mag[2] = magnitude;
140 printf("Found star: %d %s, %.3f %.3f %.3f\n", count,
141 name, right_ascension, declination, magnitude);
143 glColor3f( mag[0], mag[1], mag[2] );
144 glVertex3f( 190000.0 * sin(right_ascension) * cos(declination),
145 190000.0 * cos(right_ascension) * cos(declination),
146 190000.0 * sin(declination) );
149 } /* if valid line */
157 glBegin(GL_LINE_LOOP);
158 glColor3f(1.0, 0.0, 0.0);
159 glVertex3f( 190000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
160 190000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
161 190000.0 * sin(decl_save-0.2) );
162 glVertex3f( 190000.0 * sin(ra_save+0.2) * cos(decl_save-0.2),
163 190000.0 * cos(ra_save+0.2) * cos(decl_save-0.2),
164 190000.0 * sin(decl_save-0.2) );
165 glVertex3f( 190000.0 * sin(ra_save+0.2) * cos(decl_save+0.2),
166 190000.0 * cos(ra_save+0.2) * cos(decl_save+0.2),
167 190000.0 * sin(decl_save+0.2) );
168 glVertex3f( 190000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
169 190000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
170 190000.0 * sin(decl_save+0.2) );
173 glBegin(GL_LINE_LOOP);
174 glColor3f(0.0, 1.0, 0.0);
175 glVertex3f( 190000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
176 190000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
177 190000.0 * sin(decl_save1-0.2) );
178 glVertex3f( 190000.0 * sin(ra_save1+0.2) * cos(decl_save1-0.2),
179 190000.0 * cos(ra_save1+0.2) * cos(decl_save1-0.2),
180 190000.0 * sin(decl_save1-0.2) );
181 glVertex3f( 190000.0 * sin(ra_save1+0.2) * cos(decl_save1+0.2),
182 190000.0 * cos(ra_save1+0.2) * cos(decl_save1+0.2),
183 190000.0 * sin(decl_save1+0.2) );
184 glVertex3f( 190000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
185 190000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
186 190000.0 * sin(decl_save1+0.2) );
194 void fgStarsRender() {
199 f = ¤t_aircraft.flight;
202 printf("RENDERING STARS\n");
205 glDisable( GL_LIGHTING );
208 glTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z );
210 angle = FG_2PI * fmod(DaysSinceEpoch(time(NULL)), 1.0);
211 glRotatef( -angle * RAD_TO_DEG, 0.0, 0.0, 1.0 );
212 printf("Rotating stars by %.2f\n", -angle * RAD_TO_DEG);
217 glEnable( GL_LIGHTING );
223 /* Revision 1.5 1997/09/05 01:35:59 curt
224 /* Working on getting stars right.
226 * Revision 1.4 1997/09/04 02:17:38 curt
229 * Revision 1.3 1997/08/29 17:55:28 curt
230 * Worked on properly aligning the stars.
232 * Revision 1.2 1997/08/27 21:32:30 curt
233 * Restructured view calculation code. Added stars.
235 * Revision 1.1 1997/08/27 03:34:48 curt