]> git.mxchange.org Git - flightgear.git/blob - Scenery/stars.c
Initial revisio.
[flightgear.git] / Scenery / stars.c
1 /**************************************************************************
2  * stars.c -- data structures and routines for managing and rendering stars.
3  *
4  * Written by Curtis Olson, started August 1997.
5  *
6  * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7  *
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.
12  *
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.
17  *
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.
21  *
22  * $Id$
23  * (Log is kept at end of this file)
24  **************************************************************************/
25
26
27 #ifdef WIN32
28 #  include <windows.h>
29 #endif
30
31 #include <math.h>
32 #include <stdio.h>
33 #include <string.h>
34
35 #include <GL/glut.h>
36
37 #include "stars.h"
38
39 #include "../general.h"
40
41
42 /* static struct STAR stars[FG_MAX_STARS]; */
43 static GLint stars;
44
45
46 /* Initialize the Star Management Subsystem */
47 void fgStarsInit() {
48     FILE *fd;
49     struct general_params *g;
50     char path[1024];
51     char line[256], name[256];
52     char *tmp_ptr;
53     double right_ascension, declination, magnitude;
54     int count;
55
56     g = &general;
57
58     /* build the full path name to the stars data base file */
59     path[0] = '\0';
60     strcat(path, g->root_dir);
61     strcat(path, "/Scenery/");
62     strcat(path, "Stars.dat");
63
64     printf("Loading Stars: %s\n", path);
65
66     if ( (fd = fopen(path, "r")) == NULL ) {
67         printf("Cannot open star file: '%s'\n", path);
68         return;
69     }
70
71     stars = glGenLists(1);
72     glNewList( stars, GL_COMPILE );
73     glBegin( GL_POINTS );
74
75     /* read in each line of the file */
76     count = 0;
77     while ( (fgets(line, 256, fd) != NULL) && (count < FG_MAX_STARS) ) {
78         tmp_ptr = line;
79         
80         /* advance to first non-whitespace character */
81         while ( (tmp_ptr[0] == ' ') || (tmp_ptr[0] == '\t') ) {
82             tmp_ptr++;
83         }
84
85         if ( tmp_ptr[0] == '#' ) {
86             /* comment */
87         } else if ( strlen(tmp_ptr) == 0 ) {
88             /* blank line */
89         } else {
90             /* star data line */
91             fscanf(fd, "%s %lf %lf %lf\n", 
92                    name, &right_ascension, &declination, &magnitude);
93             /* printf("Found star: %d %s, %.3f %.3f %.3f\n", count,
94                name, right_ascension, declination, magnitude); */
95             count++;
96             glColor3f( magnitude, magnitude, magnitude );
97             glVertex3f( 100.0 * sin(right_ascension) * cos(declination),
98                         100.0 * cos(right_ascension) * cos(declination),
99                         100.0 * sin(declination) );
100
101         } /* if valid line */
102
103     } /* while */
104
105     glEnd();
106     glEndList();
107 }
108
109
110 /* Draw the Stars */
111 void fgStarsRender() {
112     glCallList(stars);
113 }
114
115
116 /* $Log$
117 /* Revision 1.1  1997/08/27 03:34:48  curt
118 /* Initial revisio.
119 /*
120  */