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 **************************************************************************/
39 #include "../general.h"
41 #include "../GLUT/views.h"
47 /* Initialize the Star Management Subsystem */
52 char line[256], name[256];
54 double right_ascension, declination, magnitude;
55 GLfloat mag[4] = {0.0, 0.0, 0.0, 1.0};
60 /* build the full path name to the stars data base file */
62 strcat(path, g->root_dir);
63 strcat(path, "/Scenery/");
64 strcat(path, "Stars.dat");
66 printf("Loading Stars: %s\n", path);
68 if ( (fd = fopen(path, "r")) == NULL ) {
69 printf("Cannot open star file: '%s'\n", path);
73 stars = glGenLists(1);
74 glNewList( stars, GL_COMPILE );
77 /* read in each line of the file */
79 while ( (fgets(line, 256, fd) != NULL) && (count < FG_MAX_STARS) ) {
82 /* advance to first non-whitespace character */
83 while ( (tmp_ptr[0] == ' ') || (tmp_ptr[0] == '\t') ) {
87 if ( tmp_ptr[0] == '#' ) {
89 } else if ( strlen(tmp_ptr) == 0 ) {
93 fscanf(fd, "%s %lf %lf %lf\n",
94 name, &right_ascension, &declination, &magnitude);
95 /* printf("Found star: %d %s, %.3f %.3f %.3f\n", count,
96 name, right_ascension, declination, magnitude); */
98 magnitude = magnitude * 0.8 + 0.2;
99 mag[0] = mag[1] = mag[2] = magnitude;
100 glColor3f( magnitude, magnitude, magnitude );
101 glVertex3f( 190000.0 * sin(right_ascension) * cos(declination),
102 190000.0 * cos(right_ascension) * cos(declination),
103 190000.0 * sin(declination) );
105 } /* if valid line */
115 void fgStarsRender() {
117 GLfloat amb[3], diff[3];
121 printf("RENDERING STARS\n");
124 glDisable( GL_LIGHTING );
127 /* set lighting parameters for stars */
128 /* amb[0] = amb[1] = amb[2] = 1.0;
129 diff[0] = diff[1] = diff[2] = 1.0;
130 glLightfv(GL_LIGHT0, GL_AMBIENT, amb );
131 glLightfv(GL_LIGHT0, GL_DIFFUSE, diff ); */
133 glTranslatef(v->view_pos.x, v->view_pos.y, v->view_pos.z);
138 glEnable( GL_LIGHTING );
144 /* Revision 1.2 1997/08/27 21:32:30 curt
145 /* Restructured view calculation code. Added stars.
147 * Revision 1.1 1997/08/27 03:34:48 curt