]> git.mxchange.org Git - flightgear.git/commitdiff
Fixed so moon and sun display lists aren't recreate periodically.
authorcurt <curt>
Wed, 17 Dec 1997 23:12:14 +0000 (23:12 +0000)
committercurt <curt>
Wed, 17 Dec 1997 23:12:14 +0000 (23:12 +0000)
Scenery/moon.c
Scenery/sun.c

index ac97aa94e555fcd32c99055236efd395100a682e..203d70bf265c78f9458447e487eff46629919fbc 100644 (file)
@@ -34,8 +34,8 @@
 
 struct CelestialCoord moonPos;
 
-float xMoon, yMoon, zMoon;
-GLint moon;
+static float xMoon, yMoon, zMoon;
+static GLint moon;
 
 /*
 static GLfloat vdata[12][3] =
@@ -227,16 +227,11 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params,
 
 void fgMoonInit() {
     struct fgLIGHT *l;
-//   int i;
+    static int dl_exists = 0;
 
     l = &cur_light_params;
 
-    moon = xglGenLists(1);
-    xglNewList(moon, GL_COMPILE );
-
-    /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear);
-    xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */
-
+    /* position the moon */
     fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params);
     moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], 
                              cur_time_params);
@@ -245,24 +240,34 @@ void fgMoonInit() {
           moonPos.Declination);
 #endif
 
-    /* xMoon = 90000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination);
-       yMoon = 90000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination);
-       zMoon = 90000.0 * sin(moonPos.Declination); */
+    if ( !dl_exists ) {
+       dl_exists = 1;
+
+       /* printf("First time through, creating moon display list\n"); */
+
+       moon = xglGenLists(1);
+       xglNewList(moon, GL_COMPILE );
+
+       /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear);
+          xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */
+
 
-    xMoon = 60000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination);
-    yMoon = 60000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination);
-    zMoon = 60000.0 * sin(moonPos.Declination);
+       xMoon = 60000.0 * cos(moonPos.RightAscension) * 
+           cos(moonPos.Declination);
+       yMoon = 60000.0 * sin(moonPos.RightAscension) * 
+           cos(moonPos.Declination);
+       zMoon = 60000.0 * sin(moonPos.Declination);
 
-    glutSolidSphere(1.0, 15, 15);
+       glutSolidSphere(1.0, 15, 15);
 
-    xglEndList();
+       xglEndList();
+    }
 }
 
 
 /* Draw the moon */
 void fgMoonRender() {
     struct fgLIGHT *l;
-    GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
     GLfloat moon_color[4] = { 1.0, 1.0, 1.0, 1.0 };
 
     l = &cur_light_params;
index e53dfbb53f99eb6df8890808a177fe042274a2a2..8b012c3e8cc88712dc1d8d648e837bbdd15d5e7f 100644 (file)
@@ -93,14 +93,8 @@ struct CelestialCoord fgCalculateSun(struct OrbElements params, struct fgTIME t)
 
 
 /* Initialize the Sun */
-void fgSunInit()
-{
-//   int i;
-
-    sun_obj = xglGenLists(1);
-    xglNewList(sun_obj, GL_COMPILE );
-
-//     xglBegin( GL_POINTS );
+void fgSunInit() {
+    static int dl_exists = 0;
 
     fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params);
     sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params);
@@ -109,38 +103,22 @@ void fgSunInit()
           sunPos.Declination);
 #endif
 
-    /* give the moon a temporary color, for testing purposes */
-//   xglColor3f( 0.0, 1.0, 0.0);
-//   xglVertex3f( 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination),
- //              190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination),
-//                190000.0 * sin(moonPos.Declination) );
-   //xglVertex3f(0.0, 0.0, 0.0);
-//   xglEnd();
-//   xglColor3f(1.0, 1.0, 1.0);
-   //xMoon = 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination);
-   //yMoon = 190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination);
-   //zMoon = 190000.0 * sin(moonPos.Declination);
-
-   xSun = 60000.0 * cos(sunPos.RightAscension) * cos(sunPos.Declination);
-   ySun = 60000.0 * sin(sunPos.RightAscension) * cos(sunPos.Declination);
-   zSun = 60000.0 * sin(sunPos.Declination);
-
-//   xglPushMatrix();
-//   xglTranslatef(x, y, z);
-//   xglScalef(16622.8, 16622.8, 16622.8);
-//     xglBegin(GL_TRIANGLES);
-//   for (i = 0; i < 20; i++)
-//      subdivide(&vdata[tindices[i][0]][0],
-//                &vdata[tindices[i][1]][0],
-//                &vdata[tindices[i][2]][0], 3);
-//     glutSolidSphere(1.0, 25, 25);
-
-//     xglEnd();
-    //xglPopMatrix();
-
-    glutSolidSphere(1.0, 10, 10);
-
-    xglEndList();
+    if ( !dl_exists ) {
+       dl_exists = 1;
+
+       /* printf("First time through, creating sun display list\n"); */
+
+       sun_obj = xglGenLists(1);
+       xglNewList(sun_obj, GL_COMPILE );
+
+       xSun = 60000.0 * cos(sunPos.RightAscension) * cos(sunPos.Declination);
+       ySun = 60000.0 * sin(sunPos.RightAscension) * cos(sunPos.Declination);
+       zSun = 60000.0 * sin(sunPos.Declination);
+
+       glutSolidSphere(1.0, 10, 10);
+
+       xglEndList();
+    }
 }
 
 
@@ -204,10 +182,13 @@ void fgSunRender() {
 
 
 /* $Log$
-/* Revision 1.6  1997/12/15 23:55:04  curt
-/* Add xgl wrappers for debugging.
-/* Generate terrain normals on the fly.
+/* Revision 1.7  1997/12/17 23:12:16  curt
+/* Fixed so moon and sun display lists aren't recreate periodically.
 /*
+ * Revision 1.6  1997/12/15 23:55:04  curt
+ * Add xgl wrappers for debugging.
+ * Generate terrain normals on the fly.
+ *
  * Revision 1.5  1997/12/12 21:41:31  curt
  * More light/material property tweaking ... still a ways off.
  *