]> git.mxchange.org Git - simgear.git/blobdiff - Scenery/sun.c
Integrated new event manager with subsystem initializations.
[simgear.git] / Scenery / sun.c
index 2b97740cf3ecb10588cd59bc4b778677591cf2ac..372044a73cd1663e004cc4dabf275cef3c36597e 100644 (file)
@@ -23,6 +23,8 @@
  **************************************************************************/
 
 #include <GL/glut.h>
+#include "../XGL/xgl.h"
+
 #include "../Time/fg_time.h"
 #include "../Main/views.h"
 #include "orbits.h"
@@ -58,6 +60,7 @@ struct SunPos fgCalcSunPos(struct OrbElements params)
       coordinates (xs, ys) */
     solarPosition.xs = r * cos(lonSun);
     solarPosition.ys = r * sin(lonSun);
+    solarPosition.dist = r;
     return solarPosition;
 }
 
@@ -91,14 +94,10 @@ struct CelestialCoord fgCalculateSun(struct OrbElements params, struct fgTIME t)
 
 
 /* Initialize the Sun */
-void fgSunInit()
-{
-//   int i;
+void fgSunInit() {
+    static int dl_exists = 0;
 
-    sun_obj = glGenLists(1);
-    glNewList(sun_obj, GL_COMPILE );
-
-//     glBegin( GL_POINTS );
+    printf("Initializing the Sun\n");
 
     fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params);
     sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params);
@@ -107,38 +106,22 @@ void fgSunInit()
           sunPos.Declination);
 #endif
 
-    /* give the moon a temporary color, for testing purposes */
-//   glColor3f( 0.0, 1.0, 0.0);
-//   glVertex3f( 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination),
- //              190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination),
-//                190000.0 * sin(moonPos.Declination) );
-   //glVertex3f(0.0, 0.0, 0.0);
-//   glEnd();
-//   glColor3f(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);
-
-//   glPushMatrix();
-//   glTranslatef(x, y, z);
-//   glScalef(16622.8, 16622.8, 16622.8);
-//     glBegin(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);
-
-//     glEnd();
-    //glPopMatrix();
-
-    glutSolidSphere(1.0, 10, 10);
-
-    glEndList();
+    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();
+    }
 }
 
 
@@ -146,23 +129,27 @@ void fgSunInit()
 void fgSunRender() {
     struct fgVIEW *v;
     struct fgTIME *t;
-    GLfloat color[4] = { 0.85, 0.65, 0.05, 1.0 };
-    /* double x_2, x_4, x_8, x_10; */
-    /* GLfloat ambient; */
-    /* GLfloat amb[3], diff[3]; */
+    struct fgLIGHT *l;
+    /* GLfloat color[4] = { 0.85, 0.65, 0.05, 1.0 }; */
+    GLfloat color[4] = { 1.00, 1.00, 1.00, 1.00 };
+    double x_2, x_4, x_8, x_10;
+    GLfloat ambient;
+    GLfloat amb[3], diff[3];
 
 
     t = &cur_time_params;
     v = &current_view;
+    l = &cur_light_params;
 
-    /* x_2 = t->sun_angle * t->sun_angle;
+    x_2 = l->sun_angle * l->sun_angle;
     x_4 = x_2 * x_2;
     x_8 = x_4 * x_4;
-    x_10 = x_8 * x_2; */
+    x_10 = x_8 * x_2;
 
-    /* ambient = (0.4 * pow(1.1, -x_10 / 30.0));
+    ambient = (0.4 * pow(1.1, -x_10 / 30.0));
     if ( ambient < 0.3 ) ambient = 0.3;
     if ( ambient > 1.0 ) ambient = 1.0;
+
     amb[0] = 0.50 + ((ambient * 6.66) - 1.6);
     amb[1] = 0.00 + ((ambient * 6.66) - 1.6);
     amb[2] = 0.00 + ((ambient * 6.66) - 1.6);
@@ -175,36 +162,53 @@ void fgSunRender() {
     diff[0] = 0.0;
     diff[1] = 0.0;
     diff[2] = 0.0;
-    diff[3] = 0.0; */
+    diff[3] = 1.0;
 
     /* set lighting parameters */
-    /* glLightfv(GL_LIGHT0, GL_AMBIENT, color );
-    glLightfv(GL_LIGHT0, GL_DIFFUSE, color );
-    glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
-    glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); */
+    xglLightfv(GL_LIGHT0, GL_AMBIENT, color );
+    xglLightfv(GL_LIGHT0, GL_DIFFUSE, color );
+    xglMaterialfv(GL_FRONT, GL_AMBIENT, amb);
+    xglMaterialfv(GL_FRONT, GL_DIFFUSE, diff); 
+    xglMaterialfv(GL_FRONT, GL_SHININESS, diff);
+    xglMaterialfv(GL_FRONT, GL_EMISSION, diff);
+    xglMaterialfv(GL_FRONT, GL_SPECULAR, diff);
 
-    glDisable( GL_LIGHTING );
+    /* xglDisable( GL_LIGHTING ); */
 
-    glPushMatrix();
-    glTranslatef(xSun, ySun, zSun);
-    glScalef(1400, 1400, 1400);
+    xglPushMatrix();
+    xglTranslatef(xSun, ySun, zSun);
+    xglScalef(1400, 1400, 1400);
 
-    glColor3f(0.85, 0.65, 0.05);
+    xglColor3f(0.85, 0.65, 0.05);
 
-    /* glColor3fv( color ); */
-    /* glutSolidSphere(1.0, 25, 25); */
-    glCallList(sun_obj);
+    xglCallList(sun_obj);
 
-    glPopMatrix();
+    xglPopMatrix();
 
-    glEnable( GL_LIGHTING );
+    /* xglEnable( GL_LIGHTING ); */
 }
 
 
 /* $Log$
-/* Revision 1.5  1997/12/12 21:41:31  curt
-/* More light/material property tweaking ... still a ways off.
+/* Revision 1.10  1997/12/30 20:47:54  curt
+/* Integrated new event manager with subsystem initializations.
 /*
+ * Revision 1.9  1997/12/30 16:36:54  curt
+ * Merged in Durk's changes ...
+ *
+ * Revision 1.8  1997/12/19 23:35:00  curt
+ * Lot's of tweaking with sky rendering and lighting.
+ *
+ * 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.
+ *
  * Revision 1.4  1997/12/10 22:37:53  curt
  * Prepended "fg" on the name of all global structures that didn't have it yet.
  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"