]> git.mxchange.org Git - flightgear.git/blobdiff - Scenery/stars.c
Add xgl wrappers for debugging.
[flightgear.git] / Scenery / stars.c
index 6c3ff954fe0eac608af9a6fdda57e723ace29196..d3c671055cf18d6b0d8ec0378b5a68aa3bc73882 100644 (file)
 #include <time.h>
 
 #include <GL/glut.h>
+#include "../XGL/xgl.h"
 
+#include "orbits.h"
+#include "planets.h"
 #include "stars.h"
 
-#include "../constants.h"
-#include "../general.h"
-
-#include "../GLUT/views.h"
+#include "../Include/constants.h"
+#include "../Include/general.h"
 #include "../Aircraft/aircraft.h"
+#include "../Main/views.h"
 #include "../Time/fg_time.h"
 
 
 
 
 /* Define four structures, each with varying amounts of stars */
-static GLint stars[FG_STAR_LEVELS];
+/* static */  GLint stars[FG_STAR_LEVELS];
 
 
 /* Initialize the Star Management Subsystem */
 void fgStarsInit() {
     FILE *fd;
-    struct GENERAL *g;
+    struct 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, max_stars;
+    int count, i, j, max_stars;
 
     g = &general;
 
@@ -83,9 +86,9 @@ void fgStarsInit() {
            return;
        }
        
-       stars[i] = glGenLists(1);
-       glNewList( stars[i], GL_COMPILE );
-       glBegin( GL_POINTS );
+       stars[i] = xglGenLists(1);
+       xglNewList( stars[i], GL_COMPILE );
+       xglBegin( GL_POINTS );
 
        /* read in each line of the file */
        count = 0;
@@ -121,17 +124,21 @@ void fgStarsInit() {
                sscanf(front, "%lf,%lf,%lf\n", 
                       &right_ascension, &declination, &magnitude);
 
-               if ( strcmp(name, "Hamal") == 0 ) {
+               /*
+               if ( strcmp(name, "Betelgeuse") == 0 ) {
                    printf("  *** Marking %s\n", name);
                    ra_save = right_ascension;
                    decl_save = declination;
                }
+               */
 
-               if ( strcmp(name, "Algenib") == 0 ) {
+               /*
+               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;
@@ -141,14 +148,15 @@ void fgStarsInit() {
                if ( magnitude < 0.0 ) { magnitude = 0.0; }
                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);
-
-               glColor3f( magnitude, magnitude, magnitude );
-               glVertex3f( 190000.0 * sin(right_ascension) * cos(declination),
-                           -190000.0 * cos(right_ascension) * cos(declination),
-                           190000.0 * sin(declination) );
-
+               /* printf("Found star: %d %s, %.3f %.3f %.3f\n", count,
+                      name, right_ascension, declination, magnitude); */
+
+               xglColor3f( magnitude, magnitude, magnitude );
+               /*xglColor3f(0,0,0);*/
+               xglVertex3f( 190000.0 * cos(right_ascension) * cos(declination),
+                            190000.0 * sin(right_ascension) * cos(declination),
+                            190000.0 * sin(declination) );
+               
                count++;
            } /* if valid line */
 
@@ -156,42 +164,59 @@ void fgStarsInit() {
 
        fclose(fd);
 
-       glEnd();
-
+       /* Add the planets to all four display lists */
+       for ( j = 2; j < 9; j++ ) {
+           pltPos = fgCalculatePlanet(pltOrbElements[j], 
+                                      pltOrbElements[0], cur_time_params);
+           printf("Planet found at %f (ra), %f (dec)\n", 
+                  pltPos.RightAscension, pltPos.Declination);
+           /* give the planets a temporary color, for testing purposes */
+           xglColor3f( 1.0, 0.0, 0.0);
+           xglVertex3f( 190000.0 * cos(pltPos.RightAscension) * 
+                        cos(pltPos.Declination),
+                        190000.0 * sin(pltPos.RightAscension) * 
+                        cos(pltPos.Declination),
+                        190000.0 * sin(pltPos.Declination) );
+       }
+       xglEnd();
 
-       glBegin(GL_LINE_LOOP);
-        glColor3f(1.0, 0.0, 0.0);
-       glVertex3f( 190000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
-                   -190000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
+       /*
+       xglBegin(GL_LINE_LOOP);
+        xglColor3f(1.0, 0.0, 0.0);
+       xglVertex3f( 190000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
+                   190000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
                    190000.0 * sin(decl_save-0.2) );
-       glVertex3f( 190000.0 * sin(ra_save+0.2) * cos(decl_save-0.2),
-                   -190000.0 * cos(ra_save+0.2) * cos(decl_save-0.2),
+       xglVertex3f( 190000.0 * cos(ra_save+0.2) * cos(decl_save-0.2),
+                   190000.0 * sin(ra_save+0.2) * cos(decl_save-0.2),
                    190000.0 * sin(decl_save-0.2) );
-       glVertex3f( 190000.0 * sin(ra_save+0.2) * cos(decl_save+0.2),
-                   -190000.0 * cos(ra_save+0.2) * cos(decl_save+0.2),
+       xglVertex3f( 190000.0 * cos(ra_save+0.2) * cos(decl_save+0.2),
+                   190000.0 * sin(ra_save+0.2) * cos(decl_save+0.2),
                    190000.0 * sin(decl_save+0.2) );
-       glVertex3f( 190000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
-                   -190000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
+       xglVertex3f( 190000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
+                   190000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
                    190000.0 * sin(decl_save+0.2) );
-       glEnd();
-
-       glBegin(GL_LINE_LOOP);
-        glColor3f(0.0, 1.0, 0.0);
-       glVertex3f( 190000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
-                   -190000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
+       xglEnd();
+       */
+
+       /*
+       xglBegin(GL_LINE_LOOP);
+        xglColor3f(0.0, 1.0, 0.0);
+       xglVertex3f( 190000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
+                   190000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
                    190000.0 * sin(decl_save1-0.2) );
-       glVertex3f( 190000.0 * sin(ra_save1+0.2) * cos(decl_save1-0.2),
-                   -190000.0 * cos(ra_save1+0.2) * cos(decl_save1-0.2),
+       xglVertex3f( 190000.0 * cos(ra_save1+0.2) * cos(decl_save1-0.2),
+                   190000.0 * sin(ra_save1+0.2) * cos(decl_save1-0.2),
                    190000.0 * sin(decl_save1-0.2) );
-       glVertex3f( 190000.0 * sin(ra_save1+0.2) * cos(decl_save1+0.2),
-                   -190000.0 * cos(ra_save1+0.2) * cos(decl_save1+0.2),
+       xglVertex3f( 190000.0 * cos(ra_save1+0.2) * cos(decl_save1+0.2),
+                   190000.0 * sin(ra_save1+0.2) * cos(decl_save1+0.2),
                    190000.0 * sin(decl_save1+0.2) );
-       glVertex3f( 190000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
-                   -190000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
+       xglVertex3f( 190000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
+                   190000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
                    190000.0 * sin(decl_save1+0.2) );
-       glEnd();
+       xglEnd();
+       */
        
-       glEndList();
+       xglEndList();
 
        max_stars /= 2;
     }
@@ -200,26 +225,29 @@ void fgStarsInit() {
 
 /* Draw the Stars */
 void fgStarsRender() {
-    struct FLIGHT *f;
-    struct VIEW *v;
+    struct fgFLIGHT *f;
+    struct fgVIEW *v;
+    struct fgLIGHT *l;
     struct fgTIME *t;
-    double angle;
-    static double warp = 0;
     int i;
 
     f = &current_aircraft.flight;
+    l = &cur_light_params;
     t = &cur_time_params;
     v = &current_view;
 
     /* FG_PI_2 + 0.1 is about 6 degrees after sundown and before sunrise */
 
-    if ( t->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) {
+    /* t->sun_angle = 3.0; */ /* to force stars to be drawn (for testing) */
+
+    /* render the stars */
+    if ( l->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) {
        /* determine which star structure to draw */
-       if ( t->sun_angle > (FG_PI_2 + 7.25 * DEG_TO_RAD ) ) {
+       if ( l->sun_angle > (FG_PI_2 + 7.25 * DEG_TO_RAD ) ) {
            i = 0;
-       } else if ( t->sun_angle > (FG_PI_2 + 6.50 * DEG_TO_RAD ) ) {
+       } else if ( l->sun_angle > (FG_PI_2 + 6.50 * DEG_TO_RAD ) ) {
            i = 1;
-       } else if ( t->sun_angle > (FG_PI_2 + 5.75 * DEG_TO_RAD ) ) {
+       } else if ( l->sun_angle > (FG_PI_2 + 5.75 * DEG_TO_RAD ) ) {
            i = 2;
        } else {
            i = 3;
@@ -227,24 +255,9 @@ void fgStarsRender() {
 
        printf("RENDERING STARS = %d (night)\n", i);
 
-       glDisable( GL_FOG );
-       glDisable( GL_LIGHTING );
-       glPushMatrix();
-
-       glTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z );
-
-       angle = t->gst * 15.0;  /* 15 degrees per hour rotation */
-       /* warp += 1.0; */
-       /* warp = 15.0; */
-       warp = 0.0;
-       glRotatef( -(angle+warp), 0.0, 0.0, 1.0 );
-       printf("Rotating stars by %.2f degrees + %.2f degrees\n",-angle,-warp);
-
-       glCallList(stars[i]);
-
-       glPopMatrix();
-       glEnable( GL_LIGHTING );
-       glEnable( GL_FOG );
+       xglDisable( GL_LIGHTING );
+       xglCallList(stars[i]);
+       xglEnable( GL_LIGHTING );
     } else {
        printf("not RENDERING STARS (day)\n");
     }
@@ -252,9 +265,42 @@ void fgStarsRender() {
 
 
 /* $Log$
-/* Revision 1.10  1997/09/20 03:34:32  curt
-/* Still trying to get those durned stars aligned properly.
+/* Revision 1.20  1997/12/15 23:55:03  curt
+/* Add xgl wrappers for debugging.
+/* Generate terrain normals on the fly.
 /*
+ * Revision 1.19  1997/12/12  19:53:00  curt
+ * Working on lightling and material properties.
+ *
+ * Revision 1.18  1997/12/10 22:37:52  curt
+ * Prepended "fg" on the name of all global structures that didn't have it yet.
+ * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
+ *
+ * Revision 1.17  1997/12/09 04:25:33  curt
+ * Working on adding a global lighting params structure.
+ *
+ * Revision 1.16  1997/11/25 19:25:38  curt
+ * Changes to integrate Durk's moon/sun code updates + clean up.
+ *
+ * Revision 1.15  1997/10/30 12:38:45  curt
+ * Working on new scenery subsystem.
+ *
+ * Revision 1.14  1997/10/28 21:00:22  curt
+ * Changing to new terrain format.
+ *
+ * Revision 1.13  1997/10/25 03:18:28  curt
+ * Incorporated sun, moon, and planet position and rendering code contributed
+ * by Durk Talsma.
+ *
+ * Revision 1.12  1997/09/23 00:29:43  curt
+ * Tweaks to get things to compile with gcc-win32.
+ *
+ * Revision 1.11  1997/09/22 14:44:21  curt
+ * Continuing to try to align stars correctly.
+ *
+ * Revision 1.10  1997/09/20 03:34:32  curt
+ * Still trying to get those durned stars aligned properly.
+ *
  * Revision 1.9  1997/09/18 16:20:09  curt
  * At dusk/dawn add/remove stars in stages.
  *