]> git.mxchange.org Git - flightgear.git/blobdiff - Astro/stars.c
Prepairing for C++ integration.
[flightgear.git] / Astro / stars.c
index 9e37f7c813ef99e299762c1506f671ebc974e655..a71f30e00ccfe862a2eb1e545111d85f12cd1545 100644 (file)
@@ -24,7 +24,9 @@
  **************************************************************************/
 
 
-#ifdef WIN32
+#include <config.h>
+
+#ifdef HAVE_WINDOWS_H
 #  include <windows.h>
 #endif
 
 #include <Astro/planets.h>
 #include <Astro/stars.h>
 
+#include <Aircraft/aircraft.h>
+#include <Debug/fg_debug.h>
 #include <Include/fg_constants.h>
 #include <Include/general.h>
-#include <Aircraft/aircraft.h>
 #include <Main/views.h>
 #include <Time/fg_time.h>
-#include <Main/fg_debug.h>
 
 #define EpochStart           (631065600)
 #define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
 
 
 /* Initialize the Star Management Subsystem */
-void fgStarsInit( void ) {
+int fgStarsInit( void ) {
     FILE *fd;
-    struct fgGENERAL *g;
-    struct CelestialCoord pltPos;
+    fgGENERAL *g;
+    /* struct CelestialCoord pltPos; */
     char path[1024];
     char line[256], name[256];
     char *front, *end;
     double right_ascension, declination, magnitude;
     /* double ra_save, decl_save; */
     /* double ra_save1, decl_save1; */
-    int count, i, j, max_stars;
+    int count, i, max_stars;
 
     fgPrintf( FG_ASTRO, FG_INFO, "Initializing stars\n");
 
@@ -81,13 +83,15 @@ void fgStarsInit( void ) {
     max_stars = FG_MAX_STARS;
 
     for ( i = 0; i < FG_STAR_LEVELS; i++ ) {
-       fgPrintf( FG_ASTRO, FG_INFO, "  Loading %d Stars: %s\n", max_stars, path);
+       fgPrintf( FG_ASTRO, FG_INFO,
+                 "  Loading %d Stars: %s\n", max_stars, path);
 
        if ( (fd = fopen(path, "r")) == NULL ) {
-           fgPrintf( FG_ASTRO, FG_ALERT, "Cannot open star file: '%s'\n", path);
-           return;
+           fgPrintf( FG_ASTRO, FG_ALERT,
+                     "Cannot open star file: '%s'\n", path);
+           return 0; // Oops, lets not even try to continue. This is critical.
        }
-       
+
        stars[i] = xglGenLists(1);
        xglNewList( stars[i], GL_COMPILE );
        xglBegin( GL_POINTS );
@@ -112,7 +116,7 @@ void fgStarsInit( void ) {
                /* blank line */
            } else {
                /* star data line */
-               
+
                /* get name */
                end = front;
                while ( end[0] != ',' ) {
@@ -123,24 +127,24 @@ void fgStarsInit( void ) {
                front = end;
                front++;
 
-               sscanf(front, "%lf,%lf,%lf\n", 
+               sscanf(front, "%lf,%lf,%lf\n",
                       &right_ascension, &declination, &magnitude);
 
                /*
-               if ( strcmp(name, "Betelgeuse") == 0 ) {
-                   printf("  *** Marking %s\n", name);
-                   ra_save = right_ascension;
-                   decl_save = declination;
-               }
-               */
+                 if ( strcmp(name, "Betelgeuse") == 0 ) {
+                 printf("  *** Marking %s\n", name);
+                 ra_save = right_ascension;
+                 decl_save = declination;
+                 }
+                 */
 
                /*
-               if ( strcmp(name, "Alnilam") == 0 ) {
-                   printf("  *** Marking %s\n", name);
-                   ra_save1 = right_ascension;
-                   decl_save1 = declination;
-               }
-               */
+                 if ( strcmp(name, "Alnilam") == 0 ) {
+                 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;
@@ -148,49 +152,24 @@ void fgStarsInit( void ) {
                /* scale magnitudes again so they look ok */
                if ( magnitude > 1.0 ) { magnitude = 1.0; }
                if ( magnitude < 0.0 ) { magnitude = 0.0; }
-               magnitude = 
+               magnitude =
                    magnitude * 0.7 + (((FG_STAR_LEVELS - 1) - i) * 0.1);
                /* printf("  Found star: %d %s, %.3f %.3f %.3f\n", count,
-                      name, right_ascension, declination, magnitude); */
+                  name, right_ascension, declination, magnitude); */
 
                xglColor3f( magnitude, magnitude, magnitude );
                /*xglColor3f(0,0,0);*/
                xglVertex3f( 50000.0 * cos(right_ascension) * cos(declination),
                             50000.0 * sin(right_ascension) * cos(declination),
                             50000.0 * sin(declination) );
-               
+
                count++;
-           } /* if valid line */
+           } //  valid line
 
        } /* while */
 
        fclose(fd);
 
-       /* Add the planets to all four display lists */
-       for ( j = 2; j < 9; j++ ) {
-           pltPos = fgCalculatePlanet(pltOrbElements[j], 
-                                      pltOrbElements[0], cur_time_params, j);
-           /* give the planets a temporary color, for testing purposes */
-           /* xglColor3f( 1.0, 0.0, 0.0); */
-
-           /* scale magnitudes to (0.0 - 1.0) */
-           magnitude = (0.0 - pltPos.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);        
-           
-
-           xglColor3f(magnitude, magnitude, magnitude);
-
-           xglVertex3f( 50000.0 * cos(pltPos.RightAscension) * 
-                        cos(pltPos.Declination),
-                        50000.0 * sin(pltPos.RightAscension) * 
-                        cos(pltPos.Declination),
-                        50000.0 * sin(pltPos.Declination) );
-       }
        xglEnd();
 
        /*
@@ -228,23 +207,25 @@ void fgStarsInit( void ) {
                    50000.0 * sin(decl_save1+0.2) );
        xglEnd();
        */
-       
+
        xglEndList();
 
        max_stars /= 2;
     }
+
+    return 1;  // OK, we got here because initialization worked.
 }
 
 
 /* Draw the Stars */
 void fgStarsRender( void ) {
-    struct fgFLIGHT *f;
+    fgFLIGHT *f;
     struct fgVIEW *v;
     struct fgLIGHT *l;
     struct fgTIME *t;
     int i;
 
-    f = &current_aircraft.flight;
+    f = current_aircraft.flight;
     l = &cur_light_params;
     t = &cur_time_params;
     v = &current_view;
@@ -276,9 +257,28 @@ void fgStarsRender( void ) {
 
 
 /* $Log$
-/* Revision 1.5  1998/01/27 18:35:53  curt
-/* Minor tweaks.
+/* Revision 1.11  1998/04/18 04:13:58  curt
+/* Moved fg_debug.c to it's own library.
 /*
+ * Revision 1.10  1998/04/03 21:52:51  curt
+ * Converting to Gnu autoconf system.
+ *
+ * Revision 1.9  1998/03/14 00:27:12  curt
+ * Updated fgGENERAL to a "type" of struct.
+ *
+ * Revision 1.8  1998/02/12 21:59:38  curt
+ * Incorporated code changes contributed by Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * Revision 1.7  1998/02/09 15:07:48  curt
+ * Minor tweaks.
+ *
+ * Revision 1.6  1998/02/02 20:53:23  curt
+ * To version 0.29
+ *
+ * Revision 1.5  1998/01/27 18:35:53  curt
+ * Minor tweaks.
+ *
  * Revision 1.4  1998/01/27 00:47:49  curt
  * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
  * system and commandline/config file processing code.