]> git.mxchange.org Git - simgear.git/commitdiff
To version 0.29
authorcurt <curt>
Mon, 2 Feb 1998 20:52:20 +0000 (20:52 +0000)
committerTim Moore <timoore@redhat.com>
Tue, 15 Sep 2009 16:31:28 +0000 (18:31 +0200)
Astro/moon.c
Astro/moon.h
Astro/orbits.c
Astro/orbits.h
Astro/planets.c
Astro/planets.h
Astro/stars.c
Astro/sun.c

index a32ccd3f53b07e77cd1581d08a1183b59bef1cff..4717c695b77dfba0172c385d81f12874319b06f3 100644 (file)
@@ -40,113 +40,12 @@ struct CelestialCoord moonPos;
 static float xMoon, yMoon, zMoon;
 static GLint moon;
 
 static float xMoon, yMoon, zMoon;
 static GLint moon;
 
-/*
-static GLfloat vdata[12][3] =
-{
-   {-X, 0.0, Z }, { X, 0.0, Z }, {-X, 0.0, -Z}, {X, 0.0, -Z },
-   { 0.0, Z, X }, { 0.0, Z, -X}, {0.0, -Z, -X}, {0.0, -Z, -X},
-   { Z, X, 0.0 }, { -Z, X, 0.0}, {Z, -X, 0.0 }, {-Z, -X, 0.0}
-};
-
-static GLuint tindices[20][3] =
-{
-   {0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},
-   {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
-   {7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6},
-   {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11}
-};*/
-
-/* -------------------------------------------------------------
-      This section contains the code that generates a yellow
-      Icosahedron. It's under development... (of Course)
-______________________________________________________________*/
-/*
-void NormalizeVector(float v[3])
-{
-   GLfloat d = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
-   if (d == 0.0)
-   {
-      printf("zero length vector\n");
-      return;
-   }
-   v[0] /= d;
-   v[1] /= d;
-   v[2] /= d;
-}
 
 
-void drawTriangle(float *v1, float *v2, float *v3)
-{
-   xglBegin(GL_POLYGON);
-   //xglBegin(GL_POINTS);
-      xglNormal3fv(v1);
-      xglVertex3fv(v1);
-      xglNormal3fv(v2);
-      xglVertex3fv(v2);
-      xglNormal3fv(v3);
-      xglVertex3fv(v3);
-   xglEnd();
-}
-
-void subdivide(float *v1, float *v2, float *v3, long depth)
-{
-   GLfloat v12[3], v23[3], v31[3];
-   GLint i;
-
-   if (!depth)
-   {
-     drawTriangle(v1, v2, v3);
-     return;
-   }
-   for (i = 0; i < 3; i++)
-   {
-       v12[i] = (v1[i] + v2[i]);
-       v23[i] = (v2[i] + v3[i]);
-       v31[i] = (v3[i] + v1[i]);
-   }
-   NormalizeVector(v12);
-   NormalizeVector(v23);
-   NormalizeVector(v31);
-   subdivide(v1, v12, v31, depth - 1);
-   subdivide(v2, v23, v12, depth - 1);
-   subdivide(v3, v31, v23, depth - 1);
-   subdivide(v12, v23, v31,depth - 1);
-
-} */
-/*
-void display(void)
-{
-   int i;
-   xglClear(GL_COLOR_BUFFER_BIT);
-   xglPushMatrix();
-   xglRotatef(spin, 0.0, 0.0, 0.0);
-   xglColor3f(1.0, 1.0, 0.0);
-//   xglBegin(GL_LINE_LOOP);
-   for (i = 0; i < 20; i++)
-   {
-
-       //xglVertex3fv(&vdata[tindices[i][0]][0]);
-       //xglVertex3fv(&vdata[tindices[i][1]][0]);
-       //xglVertex3fv(&vdata[tindices[i][2]][0]);
-
-       subdivide(&vdata[tindices[i][0]][0],
-                 &vdata[tindices[i][1]][0],
-                 &vdata[tindices[i][2]][0], 3);
-
-
-   }
-//   xglEnd();
-  // xglFlush();
-  xglPopMatrix();
-  glutSwapBuffers();
-} */
 
 /* --------------------------------------------------------------
 
 /* --------------------------------------------------------------
-
       This section contains the code that calculates the actual
       position of the moon in the night sky.
       This section contains the code that calculates the actual
       position of the moon in the night sky.
-
 ----------------------------------------------------------------*/
 ----------------------------------------------------------------*/
-
 struct CelestialCoord fgCalculateMoon(struct OrbElements params,
                                       struct OrbElements sunParams,
                                       struct fgTIME t)
 struct CelestialCoord fgCalculateMoon(struct OrbElements params,
                                       struct OrbElements sunParams,
                                       struct fgTIME t)
@@ -154,7 +53,6 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params,
   struct CelestialCoord
     geocCoord, topocCoord; 
   
   struct CelestialCoord
     geocCoord, topocCoord; 
   
-  
   double
     eccAnom, ecl, lonecl, latecl, actTime,
     xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze,
   double
     eccAnom, ecl, lonecl, latecl, actTime,
     xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze,
@@ -166,14 +64,16 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params,
   a = &current_aircraft;
   f = &a->flight;
   
   a = &current_aircraft;
   f = &a->flight;
   
-/* calculate the angle between ecliptic and equatorial coordinate system */
+  /* calculate the angle between ecliptic and equatorial coordinate
+   * system, in Radians */
   actTime = fgCalcActTime(t);
   actTime = fgCalcActTime(t);
-  ecl = fgDegToRad(23.4393 - 3.563E-7 * actTime);  // in radians of course
+  /* ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime);*/
+  ecl = 0.409093 - 6.2186E-9 * actTime;
                                                        
   /* calculate the eccentric anomaly */
   eccAnom = fgCalcEccAnom(params.M, params.e);
 
                                                        
   /* calculate the eccentric anomaly */
   eccAnom = fgCalcEccAnom(params.M, params.e);
 
-  /* calculate the moon's distance (d) and  true anomaly (v) */
+  /* calculate the moon's distance (r) and  true anomaly (v) */
   xv = params.a * ( cos(eccAnom) - params.e);
   yv = params.a * ( sqrt(1.0 - params.e*params.e) * sin(eccAnom));
   v =atan2(yv, xv);
   xv = params.a * ( cos(eccAnom) - params.e);
   yv = params.a * ( sqrt(1.0 - params.e*params.e) * sin(eccAnom));
   v =atan2(yv, xv);
@@ -188,39 +88,41 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params,
   lonecl = atan2( yh, xh);
   latecl = atan2( zh, sqrt( xh*xh + yh*yh));
 
   lonecl = atan2( yh, xh);
   latecl = atan2( zh, sqrt( xh*xh + yh*yh));
 
-  /* calculate a number of perturbations */
+  /* calculate a number of perturbations, i.e. disturbances caused by
+   * the gravitational influence of the sun and the other mayor
+   * planets, the largest even have their own names */
   Ls = sunParams.M + sunParams.w;
   Lm =    params.M +    params.w + params.N;
   D = Lm - Ls;
   F = Lm - params.N;
   
   Ls = sunParams.M + sunParams.w;
   Lm =    params.M +    params.w + params.N;
   D = Lm - Ls;
   F = Lm - params.N;
   
-  lonecl += fgDegToRad(
-                      - 1.274 * sin (params.M - 2*D)                           // the Evection
-                      + 0.658 * sin (2 * D)                                                    // the Variation
-                      - 0.186 * sin (sunParams.M)                                      // the yearly variation
-                      - 0.059 * sin (2*params.M - 2*D)
-                      - 0.057 * sin (params.M - 2*D + sunParams.M)
-                      + 0.053 * sin (params.M + 2*D)
-                      + 0.046 * sin (2*D - sunParams.M)
-                      + 0.041 * sin (params.M - sunParams.M)
-                      - 0.035 * sin (D)                             // the Parallactic Equation
-                      - 0.031 * sin (params.M + sunParams.M)
-                      - 0.015 * sin (2*F - 2*D)
-                      + 0.011 * sin (params.M - 4*D)
-                      ); /* Pheeuuwwww */
-  latecl += fgDegToRad(
-                      - 0.173 * sin (F - 2*D)
-                      - 0.055 * sin (params.M - F - 2*D)
-                      - 0.046 * sin (params.M + F - 2*D)
-                      + 0.033 * sin (F + 2*D)
-                      + 0.017 * sin (2 * params.M + F)
-                      );  /* Yep */
-
+  lonecl += DEG_TO_RAD * (
+                         - 1.274 * sin (params.M - 2*D)                        /* the Evection         */
+                         + 0.658 * sin (2 * D)                                 /* the Variation        */
+                         - 0.186 * sin (sunParams.M)                           /* the yearly variation */
+                         - 0.059 * sin (2*params.M - 2*D)
+                         - 0.057 * sin (params.M - 2*D + sunParams.M)
+                         + 0.053 * sin (params.M + 2*D)
+                         + 0.046 * sin (2*D - sunParams.M)
+                         + 0.041 * sin (params.M - sunParams.M)
+                         - 0.035 * sin (D)                                      /* the Parallactic Equation */
+                         - 0.031 * sin (params.M + sunParams.M)
+                         - 0.015 * sin (2*F - 2*D)
+                         + 0.011 * sin (params.M - 4*D)
+                         );
+  latecl += DEG_TO_RAD * (
+                         - 0.173 * sin (F - 2*D)
+                         - 0.055 * sin (params.M - F - 2*D)
+                         - 0.046 * sin (params.M + F - 2*D)
+                         + 0.033 * sin (F + 2*D)
+                         + 0.017 * sin (2 * params.M + F)
+                         );
+  
   r += (
        - 0.58 * cos(params.M - 2*D)
        - 0.46 * cos(2*D)
   r += (
        - 0.58 * cos(params.M - 2*D)
        - 0.46 * cos(2*D)
-       ); /* Ok! */
-
+       );
+  
   xg = r * cos(lonecl) * cos(latecl);
   yg = r * sin(lonecl) * cos(latecl);
   zg = r *               sin(latecl);
   xg = r * cos(lonecl) * cos(latecl);
   yg = r * sin(lonecl) * cos(latecl);
   zg = r *               sin(latecl);
@@ -238,10 +140,11 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params,
   /* New since 25 december 1997 */
   /* Calculate the moon's topocentric position instead of it's geocentric! */
 
   /* New since 25 december 1997 */
   /* Calculate the moon's topocentric position instead of it's geocentric! */
 
-  mpar = asin( 1 / r); /* calculate the moon's parrallax, i.e. the apparent size of the
-                         (equatorial) radius of the Earth, as seen from the moon */
-  gclat = FG_Latitude - 0.083358 * sin (2 * fgDegToRad( FG_Latitude));
-  rho = 0.99883 + 0.00167 * cos(2 * fgDegToRad(FG_Latitude));
+  /* calculate the moon's parrallax, i.e. the apparent size of the
+   * (equatorial) radius of the Earth, as seen from the moon */
+  mpar = asin( 1 / r); 
+  gclat = FG_Latitude - 0.083358 * sin (2 * DEG_TO_RAD *  FG_Latitude);
+  rho = 0.99883 + 0.00167 * cos(2 * DEG_TO_RAD * FG_Latitude);
 
   if (geocCoord.RightAscension < 0)
     geocCoord.RightAscension += (2*FG_PI);
 
   if (geocCoord.RightAscension < 0)
     geocCoord.RightAscension += (2*FG_PI);
@@ -259,22 +162,23 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params,
 
 
 void fgMoonInit( void ) {
 
 
 void fgMoonInit( void ) {
-    struct fgLIGHT *l;
+    /* struct fgLIGHT *l; */
     static int dl_exists = 0;
     static int dl_exists = 0;
+    /* GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; */
+    GLfloat moonColor[4] = {0.85, 0.65, 0.05, 1.0};
+    GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
 
     fgPrintf( FG_ASTRO, FG_INFO, "Initializing the Moon\n");
 
 
     fgPrintf( FG_ASTRO, FG_INFO, "Initializing the Moon\n");
 
-    l = &cur_light_params;
+    /* l = &cur_light_params; */
 
     /* position the moon */
     fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params);
     moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], 
                              cur_time_params);
 
     /* position the moon */
     fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params);
     moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], 
                              cur_time_params);
-#ifdef DEBUG
     fgPrintf( FG_ASTRO, FG_DEBUG, 
              "Moon found at %f (ra), %f (dec)\n", moonPos.RightAscension, 
              moonPos.Declination);
     fgPrintf( FG_ASTRO, FG_DEBUG, 
              "Moon found at %f (ra), %f (dec)\n", moonPos.RightAscension, 
              moonPos.Declination);
-#endif
 
     xMoon = 60000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination);
     yMoon = 60000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination);
 
     xMoon = 60000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination);
     yMoon = 60000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination);
@@ -290,7 +194,8 @@ void fgMoonInit( void ) {
 
        /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear);
           xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */
 
        /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear);
           xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */
-
+       xglMaterialfv(GL_FRONT, GL_AMBIENT, black);
+       xglMaterialfv(GL_FRONT, GL_DIFFUSE, moonColor);
 
        glutSolidSphere(1.0, 10, 10);
 
 
        glutSolidSphere(1.0, 10, 10);
 
@@ -301,15 +206,14 @@ void fgMoonInit( void ) {
 
 /* Draw the moon */
 void fgMoonRender( void ) {
 
 /* Draw the moon */
 void fgMoonRender( void ) {
-    struct fgLIGHT *l;
-    GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
+    /* struct fgLIGHT *l; */
 
     /* printf("Rendering moon\n"); */
 
 
     /* printf("Rendering moon\n"); */
 
-    l = &cur_light_params;
+    /* l = &cur_light_params; */
 
 
-    xglMaterialfv(GL_FRONT, GL_AMBIENT, l->sky_color );
-    xglMaterialfv(GL_FRONT, GL_DIFFUSE, white);
+    /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->sky_color ); */
+    /* xglMaterialfv(GL_FRONT, GL_DIFFUSE, white); */
 
     xglPushMatrix();
     xglTranslatef(xMoon, yMoon, zMoon);
 
     xglPushMatrix();
     xglTranslatef(xMoon, yMoon, zMoon);
@@ -322,10 +226,13 @@ void fgMoonRender( void ) {
 
 
 /* $Log$
 
 
 /* $Log$
-/* Revision 1.4  1998/01/27 00:47:46  curt
-/* Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
-/* system and commandline/config file processing code.
+/* Revision 1.5  1998/02/02 20:53:21  curt
+/* To version 0.29
 /*
 /*
+ * Revision 1.4  1998/01/27 00:47:46  curt
+ * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
+ * system and commandline/config file processing code.
+ *
  * Revision 1.3  1998/01/19 19:26:57  curt
  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
  * This should simplify things tremendously.
  * Revision 1.3  1998/01/19 19:26:57  curt
  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
  * This should simplify things tremendously.
index b5f803e0631a9f20e7f7b49f59bd9cfe5cfbff4f..1b4121a72203d972bbb01171cba30898830d0540 100644 (file)
 #include <Time/fg_time.h>
 #include <math.h>
 
 #include <Time/fg_time.h>
 #include <math.h>
 
-#define X .525731112119133606
-#define Z .850650808352039932
+/* #define X .525731112119133606 */
+/* #define Z .850650808352039932 */
 
 
  /* Initialize the Moon Display management Subsystem */
 void fgMoonInit( void );
 
 
 
  /* Initialize the Moon Display management Subsystem */
 void fgMoonInit( void );
 
-/* Draw the Stars */
+/* Draw the Moon */
 void fgMoonRender( void );
 
 struct CelestialCoord fgCalculateMoon(struct OrbElements Params,
 void fgMoonRender( void );
 
 struct CelestialCoord fgCalculateMoon(struct OrbElements Params,
@@ -51,9 +51,12 @@ extern struct OrbElements pltOrbElements[9];
 
 
 /* $Log$
 
 
 /* $Log$
-/* Revision 1.4  1998/01/22 02:59:27  curt
-/* Changed #ifdef FILE_H to #ifdef _FILE_H
+/* Revision 1.5  1998/02/02 20:53:21  curt
+/* To version 0.29
 /*
 /*
+ * Revision 1.4  1998/01/22 02:59:27  curt
+ * Changed #ifdef FILE_H to #ifdef _FILE_H
+ *
  * Revision 1.3  1998/01/19 19:26:58  curt
  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
  * This should simplify things tremendously.
  * Revision 1.3  1998/01/19 19:26:58  curt
  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
  * This should simplify things tremendously.
index 598ecd7861a1feef1983e7b9cc907299b8f3a82d..452a7818ac1ec6f261471583b0c97edd8192af2e 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <Astro/orbits.h>
 
 
 #include <Astro/orbits.h>
 
+#include <Include/fg_constants.h>
 #include <Include/general.h>
 #include <Time/fg_time.h>
 #include <Main/fg_debug.h>
 #include <Include/general.h>
 #include <Time/fg_time.h>
 #include <Main/fg_debug.h>
 struct OrbElements pltOrbElements[9];
 
 
 struct OrbElements pltOrbElements[9];
 
 
+//double fgCalcActTime(struct fgTIME t)
+//{
+//   double
+//         actTime, UT;
+//   int year;
+//
+//   /* a hack. This one introduces the 2000 problem into the program */
+//   year = t.gmt->tm_year + 1900;
+//
+//   /* calculate the actual time, remember to add 1 to tm_mon! */
+//   actTime = 367 * year - 7 *
+//               (year + ((t.gmt->tm_mon+1) + 9) / 12) / 4 + 275 *
+//                (t.gmt->tm_mon+1) / 9 + t.gmt->tm_mday - 730530;
+//
+//    UT = t.gmt->tm_hour + ((double) t.gmt->tm_min / 60);
+//    /*printf("UT = %f\n", UT); */
+//    actTime += (UT / 24.0);
+//    #define DEBUG 1
+//    #ifdef DEBUG
+//    /* printf("  Actual Time:\n"); */
+//    /* printf("  current day = %f\t", actTime); */
+//    /* printf("  GMT = %d, %d, %d, %d, %d, %d\n",
+//        year, t.gmt->tm_mon, t.gmt->tm_mday,
+//        t.gmt->tm_hour, t.gmt->tm_min, t.gmt->tm_sec); */
+//    #endif
+//    return actTime;
+//}
+
+
 double fgCalcActTime(struct fgTIME t)
 {
 double fgCalcActTime(struct fgTIME t)
 {
-   double
-         actTime, UT;
-   int year;
-
-   /* a hack. This one introduces the 2000 problem into the program */
-   year = t.gmt->tm_year + 1900;
-
-   /* calculate the actual time, rember to add 1 to tm_mon! */
-   actTime = 367 * year - 7 *
-                 (year + ((t.gmt->tm_mon+1) + 9) / 12) / 4 + 275 *
-                  (t.gmt->tm_mon+1) / 9 + t.gmt->tm_mday - 730530;
-
-    UT = t.gmt->tm_hour + ((double) t.gmt->tm_min / 60);
-    /*printf("UT = %f\n", UT); */
-    actTime += (UT / 24.0);
-    #define DEBUG 1
-    #ifdef DEBUG
-    /* printf("  Actual Time:\n"); */
-    /* printf("  current day = %f\t", actTime); */
-    /* printf("  GMT = %d, %d, %d, %d, %d, %d\n",
-          year, t.gmt->tm_mon, t.gmt->tm_mday,
-          t.gmt->tm_hour, t.gmt->tm_min, t.gmt->tm_sec); */
-    #endif
-    return actTime;
+  return (t.mjd - 36523.5);
 }
 
 }
 
+
 /* convert degrees to radians */
 /* convert degrees to radians */
+/*
 double fgDegToRad(double angle)
 {
        return (angle * PIOVER180);
 }
 double fgDegToRad(double angle)
 {
        return (angle * PIOVER180);
 }
-
+*/
 double fgCalcEccAnom(double M, double e)
 {
     double
 double fgCalcEccAnom(double M, double e)
 {
     double
@@ -85,7 +94,7 @@ double fgCalcEccAnom(double M, double e)
             diff = fabs(E0 - E1);
             E0 = E1;
                }
             diff = fabs(E0 - E1);
             E0 = E1;
                }
-        while (diff > fgDegToRad(0.001));
+        while (diff > (DEG_TO_RAD * 0.001));
         return E0;
        }
     return eccAnom;
         return E0;
        }
     return eccAnom;
@@ -137,12 +146,11 @@ void fgSolarSystemInit(struct fgTIME t)
 
    if ( (data = fopen(path, "r")) == NULL )
    {
 
    if ( (data = fopen(path, "r")) == NULL )
    {
-           fgPrintf( FG_ASTRO, FG_ALERT, "Cannot open data file: '%s'\n", path);
+           fgPrintf( FG_ASTRO, FG_ALERT, 
+                     "Cannot open data file: '%s'\n", path);
            return;
    }
            return;
    }
-   #ifdef DEBUG
    fgPrintf( FG_ASTRO, FG_INFO, "  reading datafile %s\n", path);
    fgPrintf( FG_ASTRO, FG_INFO, "  reading datafile %s\n", path);
-   #endif
 
    /* for all the objects... */
    for (i = 0; i < 9; i ++)
 
    /* for all the objects... */
    for (i = 0; i < 9; i ++)
@@ -164,20 +172,23 @@ void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t)
    actTime = fgCalcActTime(t);
 
    /* calculate the actual orbital elements */
    actTime = fgCalcActTime(t);
 
    /* calculate the actual orbital elements */
-    planet->M = fgDegToRad(planet->MFirst + (planet->MSec * actTime)); // angle in radians
-    planet->w = fgDegToRad(planet->wFirst + (planet->wSec * actTime)); // angle in radians
-    planet->N = fgDegToRad(planet->NFirst + (planet->NSec * actTime)); // angle in radians
-    planet->i = fgDegToRad(planet->iFirst + (planet->iSec * actTime));  // angle in radians
+    planet->M = DEG_TO_RAD * (planet->MFirst + (planet->MSec * actTime));      // angle in radians
+    planet->w = DEG_TO_RAD * (planet->wFirst + (planet->wSec * actTime));      // angle in radians
+    planet->N = DEG_TO_RAD * (planet->NFirst + (planet->NSec * actTime));      // angle in radians
+    planet->i = DEG_TO_RAD * (planet->iFirst + (planet->iSec * actTime));  // angle in radians
     planet->e = planet->eFirst + (planet->eSec * actTime);
     planet->a = planet->aFirst + (planet->aSec * actTime);
 }
 
 
 /* $Log$
     planet->e = planet->eFirst + (planet->eSec * actTime);
     planet->a = planet->aFirst + (planet->aSec * actTime);
 }
 
 
 /* $Log$
-/* Revision 1.4  1998/01/27 00:47:47  curt
-/* Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
-/* system and commandline/config file processing code.
+/* Revision 1.5  1998/02/02 20:53:22  curt
+/* To version 0.29
 /*
 /*
+ * Revision 1.4  1998/01/27 00:47:47  curt
+ * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
+ * system and commandline/config file processing code.
+ *
  * Revision 1.3  1998/01/22 02:59:27  curt
  * Changed #ifdef FILE_H to #ifdef _FILE_H
  *
  * Revision 1.3  1998/01/22 02:59:27  curt
  * Changed #ifdef FILE_H to #ifdef _FILE_H
  *
index d9ceb9dec42d7adf584f1de4b5f4658f9addf6c0..fcabc6593fadce98f2f1f99ca42b10206b4960b7 100644 (file)
@@ -68,7 +68,7 @@ struct CelestialCoord {
 };
 
 
 };
 
 
-double fgDegToRad(double angle);
+/* double fgDegToRad(double angle); */
 double fgCalcEccAnom(double M, double e);
 double fgCalcActTime(struct fgTIME t);
 
 double fgCalcEccAnom(double M, double e);
 double fgCalcActTime(struct fgTIME t);
 
@@ -81,9 +81,12 @@ void fgSolarSystemUpdate(struct OrbElements *planets, struct fgTIME t);
 
 
 /* $Log$
 
 
 /* $Log$
-/* Revision 1.3  1998/01/22 02:59:27  curt
-/* Changed #ifdef FILE_H to #ifdef _FILE_H
+/* Revision 1.4  1998/02/02 20:53:22  curt
+/* To version 0.29
 /*
 /*
+ * Revision 1.3  1998/01/22 02:59:27  curt
+ * Changed #ifdef FILE_H to #ifdef _FILE_H
+ *
  * Revision 1.2  1998/01/19 19:26:58  curt
  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
  * This should simplify things tremendously.
  * Revision 1.2  1998/01/19 19:26:58  curt
  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
  * This should simplify things tremendously.
index 6c3af2fc20d6a88569f623aa077be3c004a121b3..f33e5e9c9da24d64dd0003a63712b0bc124bc3e8 100644 (file)
  **************************************************************************/
 
 
  **************************************************************************/
 
 
+#ifdef WIN32
+#  include <windows.h>
+#endif
+
+#include <GL/glut.h>
+#include <XGL/xgl.h>
+
 #include <Time/fg_time.h>
 #include <Astro/orbits.h>
 #include <Astro/planets.h>
 #include <Astro/sun.h>
 #include <Time/fg_time.h>
 #include <Astro/orbits.h>
 #include <Astro/planets.h>
 #include <Astro/sun.h>
+#include <Include/fg_constants.h>
 #include <Main/fg_debug.h>
 
 #include <Main/fg_debug.h>
 
+GLint planets = 0;
+
 struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
                                         struct OrbElements theSun,
                                         struct fgTIME t, int idx)
 struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
                                         struct OrbElements theSun,
                                         struct fgTIME t, int idx)
@@ -45,8 +55,8 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
 
       actTime = fgCalcActTime(t);
       /* calculate the angle between ecliptic and equatorial coordinate system */
 
       actTime = fgCalcActTime(t);
       /* calculate the angle between ecliptic and equatorial coordinate system */
-      ecl = fgDegToRad(23.4393 - 3.563E-7 * actTime);
-
+      /* ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime); */
+      ecl = 0.409093 - 6.2186E-9 * actTime;
 
     /* calculate the eccentric anomaly */
        eccAnom  = fgCalcEccAnom(planet.M, planet.e);
 
     /* calculate the eccentric anomaly */
        eccAnom  = fgCalcEccAnom(planet.M, planet.e);
@@ -62,7 +72,7 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
     yh = r * ( sin(planet.N) * cos(v+planet.w) + cos(planet.N) * sin(v+planet.w) * cos(planet.i));
     zh = r * ( sin(v+planet.w) * sin(planet.i));
 
     yh = r * ( sin(planet.N) * cos(v+planet.w) + cos(planet.N) * sin(v+planet.w) * cos(planet.i));
     zh = r * ( sin(v+planet.w) * sin(planet.i));
 
-    /* calculate the ecleptic longitude and latitude */
+    /* calculate the ecliptic longitude and latitude */
 
     /*
     lonecl = atan2(yh, xh);
 
     /*
     lonecl = atan2(yh, xh);
@@ -133,12 +143,74 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
 }
 
 
 }
 
 
+void fgPlanetsInit( void )
+{
+  int i;
+  struct CelestialCoord pltPos;
+  double magnitude;
+
+  /* if the display list was already built during a previous init,
+     recycle it */
+
+  if (planets)
+      xglDeleteLists(planets, 1);
+
+  planets = xglGenLists(1);
+  xglNewList( planets, GL_COMPILE );
+  xglBegin( GL_POINTS );
+
+
+  /* Add the planets to all four display lists */
+  for ( i = 2; i < 9; i++ ) {
+    fgSolarSystemUpdate(&(pltOrbElements[i]), cur_time_params);
+    pltPos = fgCalculatePlanet(pltOrbElements[i], 
+                              pltOrbElements[0], cur_time_params, i);
+    
+    /* 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 */
+    /* magnitude = 
+       magnitude * 0.7 + (((FG_STAR_LEVELS - 1) - i) * 0.1); */
+
+    /* the following statement could be made a little more sopisticated
+       for the moment: Stick to this one */
+    magnitude = magnitude * 0.7 + (3 * 0.1);
+    if ( magnitude > 1.0 ) { magnitude = 1.0; }
+    if ( magnitude < 0.0 ) { magnitude = 0.0; }
+    
+    
+    xglColor3f(magnitude, magnitude, magnitude);
+    /* xglColor3f(1.0, 1.0,1.0); */
+    
+    xglVertex3f( 50000.0 * cos(pltPos.RightAscension) * 
+                          cos(pltPos.Declination),
+                50000.0 * sin(pltPos.RightAscension) * 
+                          cos(pltPos.Declination),
+                50000.0 * sin(pltPos.Declination) );
+  }
+  xglEnd();
+  xglEndList();
+
+}
+
+
+void fgPlanetsRender( void ) {
+       xglCallList(planets);
+}
+
 
 /* $Log$
 
 /* $Log$
-/* Revision 1.3  1998/01/27 00:47:47  curt
-/* Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
-/* system and commandline/config file processing code.
+/* Revision 1.4  1998/02/02 20:53:23  curt
+/* To version 0.29
 /*
 /*
+ * Revision 1.3  1998/01/27 00:47:47  curt
+ * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
+ * system and commandline/config file processing code.
+ *
  * Revision 1.2  1998/01/19 19:26:59  curt
  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
  * This should simplify things tremendously.
  * Revision 1.2  1998/01/19 19:26:59  curt
  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
  * This should simplify things tremendously.
index d5f10b9030829f64ef3a8b90a035bb733e3ac837..c5468ad6dbb8ea14d874b31c937234c9496d1a0f 100644 (file)
@@ -31,13 +31,21 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
                                          struct OrbElements theSun,
                                          struct fgTIME t, int idx);
 
                                          struct OrbElements theSun,
                                          struct fgTIME t, int idx);
 
+
+void fgPlanetsInit();
+void fgPlanetsRender();
+
+
 #endif /* PLANETS_H */
 
 
 /* $Log$
 #endif /* PLANETS_H */
 
 
 /* $Log$
-/* Revision 1.2  1998/01/22 02:59:28  curt
-/* Changed #ifdef FILE_H to #ifdef _FILE_H
+/* Revision 1.3  1998/02/02 20:53:23  curt
+/* To version 0.29
 /*
 /*
+ * Revision 1.2  1998/01/22 02:59:28  curt
+ * Changed #ifdef FILE_H to #ifdef _FILE_H
+ *
  * Revision 1.1  1998/01/07 03:16:18  curt
  * Moved from .../Src/Scenery/ to .../Src/Astro/
  *
  * Revision 1.1  1998/01/07 03:16:18  curt
  * Moved from .../Src/Scenery/ to .../Src/Astro/
  *
index 9e37f7c813ef99e299762c1506f671ebc974e655..dcc85156f0e6c833e0d800d22f60ac27e7bbcd35 100644 (file)
 void fgStarsInit( void ) {
     FILE *fd;
     struct fgGENERAL *g;
 void fgStarsInit( void ) {
     FILE *fd;
     struct fgGENERAL *g;
-    struct CelestialCoord pltPos;
+    /* 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; */
     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");
 
 
     fgPrintf( FG_ASTRO, FG_INFO, "Initializing stars\n");
 
@@ -81,10 +81,12 @@ void fgStarsInit( void ) {
     max_stars = FG_MAX_STARS;
 
     for ( i = 0; i < FG_STAR_LEVELS; i++ ) {
     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 ) {
 
        if ( (fd = fopen(path, "r")) == NULL ) {
-           fgPrintf( FG_ASTRO, FG_ALERT, "Cannot open star file: '%s'\n", path);
+           fgPrintf( FG_ASTRO, FG_ALERT, 
+                     "Cannot open star file: '%s'\n", path);
            return;
        }
        
            return;
        }
        
@@ -166,31 +168,6 @@ void fgStarsInit( void ) {
 
        fclose(fd);
 
 
        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();
 
        /*
        xglEnd();
 
        /*
@@ -276,9 +253,12 @@ void fgStarsRender( void ) {
 
 
 /* $Log$
 
 
 /* $Log$
-/* Revision 1.5  1998/01/27 18:35:53  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.
  * 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.
index b1a10585ad59278fc2431ae6d50a92a6c215bb2a..49c146e826fa69971cecd33c8144a5b1f05c08e9 100644 (file)
@@ -30,8 +30,9 @@
 #include <Astro/orbits.h>
 #include <Astro/sun.h>
 #include <Main/fg_debug.h>
 #include <Astro/orbits.h>
 #include <Astro/sun.h>
 #include <Main/fg_debug.h>
+#include <Include/fg_constants.h>
 
 
-GLint sun_obj;
+GLint sun_obj = 0;
 
 static struct CelestialCoord sunPos;
 
 
 static struct CelestialCoord sunPos;
 
@@ -77,7 +78,7 @@ struct CelestialCoord fgCalculateSun(struct OrbElements params, struct fgTIME t)
 
     /* calculate the angle between ecliptic and equatorial coordinate system */
     actTime = fgCalcActTime(t);
 
     /* calculate the angle between ecliptic and equatorial coordinate system */
     actTime = fgCalcActTime(t);
-    ecl = fgDegToRad(23.4393 - 3.563E-7 * actTime);                    // Angle now in Rads
+    ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime);                 // Angle now in Rads
 
     /* calculate the sun's ecliptic position */
     SolarPosition = fgCalcSunPos(params);
 
     /* calculate the sun's ecliptic position */
     SolarPosition = fgCalcSunPos(params);
@@ -96,47 +97,40 @@ struct CelestialCoord fgCalculateSun(struct OrbElements params, struct fgTIME t)
 
 /* Initialize the Sun */
 void fgSunInit( void ) {
 
 /* Initialize the Sun */
 void fgSunInit( void ) {
-    static int dl_exists = 0;
+    struct fgLIGHT *l;
+    struct fgTIME *t;
+    struct fgVIEW *v;  
+
+    /* GLfloat color[4] = { 1.00, 1.00, 1.00, 1.00 }; */
+    double x_2, x_4, x_8, x_10;
+    GLfloat ambient;
+    GLfloat amb[4];
+
+    l = &cur_light_params;
+    t = &cur_time_params;
+    v = &current_view;
 
     fgPrintf( FG_ASTRO, FG_INFO, "  Initializing the Sun\n");
 
     fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params);
     sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params);
 
     fgPrintf( FG_ASTRO, FG_INFO, "  Initializing the Sun\n");
 
     fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params);
     sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params);
-#ifdef DEBUG
     fgPrintf( FG_ASTRO, FG_INFO, 
              "Sun found at %f (ra), %f (dec)\n", 
              sunPos.RightAscension, sunPos.Declination);
     fgPrintf( FG_ASTRO, FG_INFO, 
              "Sun found at %f (ra), %f (dec)\n", 
              sunPos.RightAscension, sunPos.Declination);
-#endif
 
     xSun = 60000.0 * cos(sunPos.RightAscension) * cos(sunPos.Declination);
     ySun = 60000.0 * sin(sunPos.RightAscension) * cos(sunPos.Declination);
     zSun = 60000.0 * sin(sunPos.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);
 
-    if ( !dl_exists ) {
-       dl_exists = 1;
-
-       /* printf("First time through, creating sun display list\n"); */
-
-       sun_obj = xglGenLists(1);
-       xglNewList(sun_obj, GL_COMPILE );
-
-       glutSolidSphere(1.0, 10, 10);
 
 
-       xglEndList();
+    if (sun_obj) {
+       xglDeleteLists(sun_obj, 1);
     }
     }
-}
 
 
+    /* printf("First time through, creating sun display list\n"); */
 
 
-/* Draw the Sun */
-void fgSunRender( void ) {
-    struct fgVIEW *v;
-    struct fgTIME *t;
-    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];
+    sun_obj = xglGenLists(1);
+    xglNewList(sun_obj, GL_COMPILE );
 
 
     t = &cur_time_params;
 
 
     t = &cur_time_params;
@@ -152,29 +146,29 @@ void fgSunRender( void ) {
     if ( ambient < 0.3 ) ambient = 0.3;
     if ( ambient > 1.0 ) ambient = 1.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);
-    amb[3] = 0.00;
-#ifdef DEBUG
-    fgPrintf( FG_ASTRO, FG_INFO, 
-             "Color of the sun: %f, %f, %f\n"
-             "Ambient value   : %f\n"
-             "Sun Angle       : %f\n" , amb[0], amb[1], amb[2], ambient, t->sun_angle);
-#endif
-    diff[0] = 0.0;
-    diff[1] = 0.0;
-    diff[2] = 0.0;
-    diff[3] = 1.0;
-
+    amb[0] = 0.00 + ((ambient * 6.0) - 1.0);     /* minimum val = 0.8 */
+    amb[1] = 0.00 + ((ambient * 11.0) - 3.0);     /* minimum val = 0.3 */ 
+    amb[2] = 0.00 + ((ambient * 12.0) - 3.6);    /* minimum val = 0.0 */ 
+    amb[3] = 1.00;   
+
+    if (amb[0] > 1.0) amb[0] = 1.0;
+    if (amb[1] > 1.0) amb[1] = 1.0;
+    if (amb[2] > 1.0) amb[2] = 1.0;
+
+    fgPrintf( FG_ASTRO, FG_DEBUG, 
+           "Color of the sun: %f, %f, %f\n"
+           "Ambient value   : %f\n"
+           "Sun Angle       : %f\n" , 
+           amb[0], amb[1], amb[2], ambient, l->sun_angle);
+    
     /* set lighting parameters */
     /* set lighting parameters */
-    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);
+    /*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); */
 
     /* xglDisable( GL_LIGHTING ); */
 
 
     /* xglDisable( GL_LIGHTING ); */
 
@@ -182,21 +176,32 @@ void fgSunRender( void ) {
     xglTranslatef(xSun, ySun, zSun);
     xglScalef(1400, 1400, 1400);
 
     xglTranslatef(xSun, ySun, zSun);
     xglScalef(1400, 1400, 1400);
 
-    xglColor3f(0.85, 0.65, 0.05);
-
-    xglCallList(sun_obj);
+    /*xglColor3f(0.85, 0.65, 0.05);*/
+    xglColor3f(amb[0], amb[1], amb[2]); 
+    glutSolidSphere(1.0, 10, 10);
 
     xglPopMatrix();
 
     /* xglEnable( GL_LIGHTING ); */
 
     xglPopMatrix();
 
     /* xglEnable( GL_LIGHTING ); */
+
+    xglEndList();
+}
+
+
+/* Draw the Sun */
+void fgSunRender( void ) {
+    xglCallList(sun_obj);
 }
 
 
 /* $Log$
 }
 
 
 /* $Log$
-/* Revision 1.4  1998/01/27 00:47:50  curt
-/* Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
-/* system and commandline/config file processing code.
+/* Revision 1.5  1998/02/02 20:53:24  curt
+/* To version 0.29
 /*
 /*
+ * Revision 1.4  1998/01/27 00:47:50  curt
+ * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
+ * system and commandline/config file processing code.
+ *
  * Revision 1.3  1998/01/19 19:27:00  curt
  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
  * This should simplify things tremendously.
  * Revision 1.3  1998/01/19 19:27:00  curt
  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
  * This should simplify things tremendously.