]> git.mxchange.org Git - flightgear.git/commitdiff
C++ - ifing the code a bit.
authorcurt <curt>
Wed, 22 Apr 1998 13:21:26 +0000 (13:21 +0000)
committercurt <curt>
Wed, 22 Apr 1998 13:21:26 +0000 (13:21 +0000)
46 files changed:
Aircraft/aircraft.h
Astro/Makefile.am
Astro/Makefile.in
Astro/moon.c [deleted file]
Astro/moon.cxx [new file with mode: 0644]
Astro/moon.h [deleted file]
Astro/moon.hxx [new file with mode: 0644]
Astro/orbits.c [deleted file]
Astro/orbits.cxx [new file with mode: 0644]
Astro/orbits.h [deleted file]
Astro/orbits.hxx [new file with mode: 0644]
Astro/planets.c [deleted file]
Astro/planets.cxx [new file with mode: 0644]
Astro/planets.h [deleted file]
Astro/planets.hxx [new file with mode: 0644]
Astro/sky.c [deleted file]
Astro/sky.cxx [new file with mode: 0644]
Astro/sky.h [deleted file]
Astro/sky.hxx [new file with mode: 0644]
Astro/stars.c [deleted file]
Astro/stars.cxx [new file with mode: 0644]
Astro/stars.h [deleted file]
Astro/stars.hxx [new file with mode: 0644]
Astro/sun.c [deleted file]
Astro/sun.cxx [new file with mode: 0644]
Astro/sun.h [deleted file]
Astro/sun.hxx [new file with mode: 0644]
Autopilot/autopilot.h
Cockpit/cockpit.h
Controls/controls.h
FDM/flight.h
Joystick/joystick.h
Scenery/Makefile.am
Scenery/Makefile.in
Scenery/obj.c
Scenery/obj.h
Scenery/scenery.h
Scenery/texload.h
Scenery/tilecache.c [deleted file]
Scenery/tilecache.cxx [new file with mode: 0644]
Scenery/tilecache.h [deleted file]
Scenery/tilecache.hxx [new file with mode: 0644]
Scenery/tilemgr.c [deleted file]
Scenery/tilemgr.cxx [new file with mode: 0644]
Scenery/tilemgr.h [deleted file]
Scenery/tilemgr.hxx [new file with mode: 0644]

index e39985ab2b32e821f73b88ddf033714391364f1c..9f67798047ddde8daf3d0578d5c3af28ddeb31da 100644 (file)
 #define _AIRCRAFT_H
 
 
+#include <Flight/flight.h>
+#include <Controls/controls.h>
+
+
 #ifdef __cplusplus                                                          
 extern "C" {                            
 #endif                                   
 
 
-#include <Flight/flight.h>
-#include <Controls/controls.h>
-
-
 /* Define a structure containing all the parameters for an aircraft */
 typedef struct{
     fgFLIGHT   *flight;
@@ -66,9 +66,12 @@ void fgAircraftOutputCurrent(fgAIRCRAFT *a);
 
 
 /* $Log$
-/* Revision 1.11  1998/04/21 17:02:27  curt
-/* Prepairing for C++ integration.
+/* Revision 1.12  1998/04/22 13:26:15  curt
+/* C++ - ifing the code a bit.
 /*
+ * Revision 1.11  1998/04/21 17:02:27  curt
+ * Prepairing for C++ integration.
+ *
  * Revision 1.10  1998/02/07 15:29:32  curt
  * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
  * <chotchkiss@namg.us.anritsu.com>
@@ -85,9 +88,12 @@ void fgAircraftOutputCurrent(fgAIRCRAFT *a);
 
 
 /* $Log$
-/* Revision 1.11  1998/04/21 17:02:27  curt
-/* Prepairing for C++ integration.
+/* Revision 1.12  1998/04/22 13:26:15  curt
+/* C++ - ifing the code a bit.
 /*
+ * Revision 1.11  1998/04/21 17:02:27  curt
+ * Prepairing for C++ integration.
+ *
  * Revision 1.10  1998/02/07 15:29:32  curt
  * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
  * <chotchkiss@namg.us.anritsu.com>
index e9d12c06531545d718476cdb9175350a8067b389..4c7a2075e99ebc63c250591222473f28f8a55c3b 100644 (file)
@@ -2,11 +2,11 @@ libdir        = ${exec_prefix}/lib
 
 lib_LTLIBRARIES = libAstro.la
 libAstro_la_SOURCES = \
-       moon.c moon.h \
-       orbits.c orbits.h \
-       planets.c planets.h \
-       sky.c sky.h \
-       stars.c stars.h \
-       sun.c sun.h
+       moon.cxx moon.hxx \
+       orbits.cxx orbits.hxx \
+       planets.cxx planets.hxx \
+       sky.cxx sky.hxx \
+       stars.cxx stars.hxx \
+       sun.cxx sun.hxx
 
 INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
index 9b9348cb296803a7d79aa8c151159c041f7ce2e9..562944cbcd363726187472bfc028c5a39b56a5ff 100644 (file)
@@ -74,12 +74,12 @@ libdir      = ${exec_prefix}/lib
 
 lib_LTLIBRARIES = libAstro.la
 libAstro_la_SOURCES = \
-       moon.c moon.h \
-       orbits.c orbits.h \
-       planets.c planets.h \
-       sky.c sky.h \
-       stars.c stars.h \
-       sun.c sun.h
+       moon.cxx moon.hxx \
+       orbits.cxx orbits.hxx \
+       planets.cxx planets.hxx \
+       sky.cxx sky.hxx \
+       stars.cxx stars.hxx \
+       sun.cxx sun.hxx
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
 CONFIG_HEADER = ../../Include/config.h
 CONFIG_CLEAN_FILES = 
@@ -98,10 +98,10 @@ libAstro_la_LDFLAGS =
 libAstro_la_LIBADD = 
 libAstro_la_OBJECTS =  moon.lo orbits.lo planets.lo sky.lo stars.lo \
 sun.lo
-CFLAGS = @CFLAGS@
-COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
-LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
-LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
+CXXFLAGS = @CXXFLAGS@
+CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
+CXXLINK = $(LIBTOOL) --mode=link $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@
 DIST_COMMON =  Makefile.am Makefile.in
 
 
@@ -111,13 +111,14 @@ TAR = tar
 GZIP = --best
 DEP_FILES =  .deps/moon.P .deps/orbits.P .deps/planets.P .deps/sky.P \
 .deps/stars.P .deps/sun.P
+CXXMKDEP = $(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
 SOURCES = $(libAstro_la_SOURCES)
 OBJECTS = $(libAstro_la_OBJECTS)
 
 all: Makefile $(LTLIBRARIES)
 
 .SUFFIXES:
-.SUFFIXES: .S .c .lo .o .s
+.SUFFIXES: .S .c .cxx .lo .o .s
 $(srcdir)/Makefile.in: @MAINT@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
        cd $(top_srcdir) && $(AUTOMAKE) --gnu Simulator/Astro/Makefile
 
@@ -184,7 +185,11 @@ distclean-libtool:
 maintainer-clean-libtool:
 
 libAstro.la: $(libAstro_la_OBJECTS) $(libAstro_la_DEPENDENCIES)
-       $(LINK) -rpath $(libdir) $(libAstro_la_LDFLAGS) $(libAstro_la_OBJECTS) $(libAstro_la_LIBADD) $(LIBS)
+       $(CXXLINK) -rpath $(libdir) $(libAstro_la_LDFLAGS) $(libAstro_la_OBJECTS) $(libAstro_la_LIBADD) $(LIBS)
+.cxx.o:
+       $(CXXCOMPILE) -c $<
+.cxx.lo:
+       $(LTCXXCOMPILE) -c $<
 
 tags: TAGS
 
@@ -251,6 +256,17 @@ maintainer-clean-depend:
        @-sed -e 's/^\([^:]*\)\.o:/\1.lo \1.o:/' \
          < .deps/$(*F).p > .deps/$(*F).P
        @-rm -f .deps/$(*F).p
+
+%.o: %.cxx
+       @echo '$(CXXCOMPILE) -c $<'; \
+       $(CXXCOMPILE) -Wp,-MD,.deps/$(*F).P -c $<
+
+%.lo: %.cxx
+       @echo '$(LTCXXCOMPILE) -c $<'; \
+       $(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).p -c $<
+       @-sed -e 's/^\([^:]*\)\.o:/\1.lo \1.o:/' \
+         < .deps/$(*F).p > .deps/$(*F).P
+       @-rm -f .deps/$(*F).p
 info:
 dvi:
 check: all
diff --git a/Astro/moon.c b/Astro/moon.c
deleted file mode 100644 (file)
index f5480dd..0000000
+++ /dev/null
@@ -1,261 +0,0 @@
-/**************************************************************************
- * moon.c
- * Written by Durk Talsma. Started October 1997, for the flight gear project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#include <config.h>
-
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#endif
-
-#include <math.h>
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-
-#include <Astro/orbits.h>
-#include <Astro/moon.h>
-
-#include <Aircraft/aircraft.h>
-#include <Debug/fg_debug.h>
-#include <Include/fg_constants.h>
-#include <Include/general.h>
-#include <Main/views.h>
-#include <Time/fg_time.h>
-
-struct CelestialCoord moonPos;
-
-static float xMoon, yMoon, zMoon;
-static GLint moon = 0;
-
-
-
-/* --------------------------------------------------------------
-      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
-    geocCoord, topocCoord; 
-  
-  double
-    eccAnom, ecl, lonecl, latecl, actTime,
-    xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze,
-    Ls, Lm, D, F, mpar, gclat, rho, HA, g;
-  
-  fgAIRCRAFT *a;
-  fgFLIGHT *f;
-
-  a = &current_aircraft;
-  f = a->flight;
-  
-  /* calculate the angle between ecliptic and equatorial coordinate
-   * system, in Radians */
-  actTime = fgCalcActTime(t);
-  ecl = ((DEG_TO_RAD * 23.4393) - (DEG_TO_RAD * 3.563E-7) * actTime);
-  /*ecl = 0.409093 - 6.2186E-9 * actTime; */
-                                                       
-  /* calculate the eccentric anomaly */
-  eccAnom = fgCalcEccAnom(params.M, params.e);
-
-  /* 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);
-  r = sqrt(xv*xv + yv*yv);
-  
-  /* estimate the geocentric rectangular coordinates here */
-  xh = r * (cos (params.N) * cos (v + params.w) -
-           sin (params.N) * sin (v + params.w) * cos (params.i));
-  yh = r * (sin (params.N) * cos (v + params.w) +
-           cos (params.N) * sin (v + params.w) * cos (params.i));
-  zh = r * (sin(v + params.w) * sin(params.i));
-  
-  /* calculate the ecliptic latitude and longitude here */
-  lonecl = atan2( yh, xh);
-  latecl = atan2( zh, sqrt( xh*xh + yh*yh));
-
-  /* calculate a number of perturbations, i.e. disturbances caused by
-   * the gravitational influence of the sun and the other mayor
-   * planets. The largest of these even have their own names */
-  Ls = sunParams.M + sunParams.w;
-  Lm =    params.M +    params.w + params.N;
-  D = Lm - Ls;
-  F = Lm - params.N;
-  
-  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)
-       );
-  
-  xg = r * cos(lonecl) * cos(latecl);
-  yg = r * sin(lonecl) * cos(latecl);
-  zg = r *               sin(latecl);
-
-  xe  = xg;
-  ye = yg * cos(ecl) - zg * sin(ecl);
-  ze = yg * sin(ecl) + zg * cos(ecl);
-  
-
-  
-
-  geocCoord.RightAscension = atan2(ye, xe);
-  geocCoord.Declination = atan2(ze, sqrt(xe*xe + ye*ye));
-  
-  /* New since 25 december 1997 */
-  /* Calculate the moon's topocentric position instead of it's geocentric! */
-
-  /* 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);
-
-  HA = t.lst - (3.8197186 * geocCoord.RightAscension);
-
-  g = atan (tan(gclat) / cos( (HA / 3.8197186))); 
-
-     
-
-  topocCoord.RightAscension = geocCoord.RightAscension -
-      mpar * rho * cos (gclat) * sin (HA) / cos (geocCoord.Declination);
-  topocCoord.Declination = geocCoord.Declination -
-      mpar * rho * sin (gclat) * sin (g - geocCoord.Declination) / sin (g);
-  return topocCoord;
-}
-
-
-void fgMoonInit( void ) {
-    GLfloat moonColor[4] = {0.85, 0.75, 0.35, 1.0};
-    GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
-
-    fgPrintf( FG_ASTRO, FG_INFO, "Initializing the Moon\n");
-    fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params);
-    moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], 
-                             cur_time_params);
-    fgPrintf( FG_ASTRO, FG_DEBUG, 
-             "Moon found at %f (ra), %f (dec)\n", moonPos.RightAscension, 
-             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);
-
-    if (moon) {
-       xglDeleteLists (moon, 1);
-    }
-
-    moon = xglGenLists (1);
-    xglNewList (moon, GL_COMPILE);
-  
-    xglMaterialfv (GL_FRONT, GL_AMBIENT, black);
-    xglMaterialfv (GL_FRONT, GL_DIFFUSE, moonColor);
-    xglPushMatrix ();
-    xglTranslatef (xMoon, yMoon, zMoon);
-    xglScalef (1400, 1400, 1400);
-  
-    glutSolidSphere (1.0, 10, 10);
-    xglPopMatrix ();
-    xglEndList ();
-}
-
-
-/* Draw the moon */
-void fgMoonRender( void ) {
-    xglCallList(moon);
-}
-
-
-/* $Log$
-/* Revision 1.9  1998/04/18 04:13:56  curt
-/* Moved fg_debug.c to it's own library.
-/*
- * Revision 1.8  1998/04/03 21:52:49  curt
- * Converting to Gnu autoconf system.
- *
- * Revision 1.7  1998/02/23 19:07:54  curt
- * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
- * calculation code between sun display, and other FG sections that use this
- * for things like lighting.
- *
- * Revision 1.6  1998/02/07 15:29:32  curt
- * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
- * <chotchkiss@namg.us.anritsu.com>
- *
- * 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.2  1998/01/19 18:40:16  curt
- * Tons of little changes to clean up the code and to remove fatal errors
- * when building with the c++ compiler.
- *
- * Revision 1.1  1998/01/07 03:16:16  curt
- * Moved from .../Src/Scenery/ to .../Src/Astro/
- *
- * Revision 1.16  1998/01/06 01:20:24  curt
- * Tweaks to help building with MSVC++
- *
- * Revision 1.15  1998/01/05 18:44:35  curt
- * Add an option to advance/decrease time from keyboard.
- *
- * Revision 1.14  1997/12/30 20:47:50  curt
- * Integrated new event manager with subsystem initializations.
- *
- * Revision 1.13  1997/12/30 16:41:00  curt
- * Added log at end of file.
- *
- */
diff --git a/Astro/moon.cxx b/Astro/moon.cxx
new file mode 100644 (file)
index 0000000..53dda6d
--- /dev/null
@@ -0,0 +1,265 @@
+/**************************************************************************
+ * moon.c
+ * Written by Durk Talsma. Started October 1997, for the flight gear project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#include <config.h>
+
+#ifdef HAVE_WINDOWS_H
+#  include <windows.h>
+#endif
+
+#include <math.h>
+#include <GL/glut.h>
+#include <XGL/xgl.h>
+
+#include <Aircraft/aircraft.h>
+#include <Debug/fg_debug.h>
+#include <Include/fg_constants.h>
+#include <Include/general.h>
+#include <Main/views.hxx>
+#include <Time/fg_time.h>
+
+#include "orbits.hxx"
+#include "moon.hxx"
+
+
+struct CelestialCoord moonPos;
+
+static float xMoon, yMoon, zMoon;
+static GLint moon = 0;
+
+
+
+/* --------------------------------------------------------------
+      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
+    geocCoord, topocCoord; 
+  
+  double
+    eccAnom, ecl, lonecl, latecl, actTime,
+    xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze,
+    Ls, Lm, D, F, mpar, gclat, rho, HA, g;
+  
+  fgAIRCRAFT *a;
+  fgFLIGHT *f;
+
+  a = &current_aircraft;
+  f = a->flight;
+  
+  /* calculate the angle between ecliptic and equatorial coordinate
+   * system, in Radians */
+  actTime = fgCalcActTime(t);
+  ecl = ((DEG_TO_RAD * 23.4393) - (DEG_TO_RAD * 3.563E-7) * actTime);
+  /*ecl = 0.409093 - 6.2186E-9 * actTime; */
+                                                       
+  /* calculate the eccentric anomaly */
+  eccAnom = fgCalcEccAnom(params.M, params.e);
+
+  /* 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);
+  r = sqrt(xv*xv + yv*yv);
+  
+  /* estimate the geocentric rectangular coordinates here */
+  xh = r * (cos (params.N) * cos (v + params.w) -
+           sin (params.N) * sin (v + params.w) * cos (params.i));
+  yh = r * (sin (params.N) * cos (v + params.w) +
+           cos (params.N) * sin (v + params.w) * cos (params.i));
+  zh = r * (sin(v + params.w) * sin(params.i));
+  
+  /* calculate the ecliptic latitude and longitude here */
+  lonecl = atan2( yh, xh);
+  latecl = atan2( zh, sqrt( xh*xh + yh*yh));
+
+  /* calculate a number of perturbations, i.e. disturbances caused by
+   * the gravitational influence of the sun and the other mayor
+   * planets. The largest of these even have their own names */
+  Ls = sunParams.M + sunParams.w;
+  Lm =    params.M +    params.w + params.N;
+  D = Lm - Ls;
+  F = Lm - params.N;
+  
+  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)
+       );
+  
+  xg = r * cos(lonecl) * cos(latecl);
+  yg = r * sin(lonecl) * cos(latecl);
+  zg = r *               sin(latecl);
+
+  xe  = xg;
+  ye = yg * cos(ecl) - zg * sin(ecl);
+  ze = yg * sin(ecl) + zg * cos(ecl);
+  
+
+  
+
+  geocCoord.RightAscension = atan2(ye, xe);
+  geocCoord.Declination = atan2(ze, sqrt(xe*xe + ye*ye));
+  
+  /* New since 25 december 1997 */
+  /* Calculate the moon's topocentric position instead of it's geocentric! */
+
+  /* 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);
+
+  HA = t.lst - (3.8197186 * geocCoord.RightAscension);
+
+  g = atan (tan(gclat) / cos( (HA / 3.8197186))); 
+
+     
+
+  topocCoord.RightAscension = geocCoord.RightAscension -
+      mpar * rho * cos (gclat) * sin (HA) / cos (geocCoord.Declination);
+  topocCoord.Declination = geocCoord.Declination -
+      mpar * rho * sin (gclat) * sin (g - geocCoord.Declination) / sin (g);
+  return topocCoord;
+}
+
+
+void fgMoonInit( void ) {
+    GLfloat moonColor[4] = {0.85, 0.75, 0.35, 1.0};
+    GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
+
+    fgPrintf( FG_ASTRO, FG_INFO, "Initializing the Moon\n");
+    fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params);
+    moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], 
+                             cur_time_params);
+    fgPrintf( FG_ASTRO, FG_DEBUG, 
+             "Moon found at %f (ra), %f (dec)\n", moonPos.RightAscension, 
+             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);
+
+    if (moon) {
+       xglDeleteLists (moon, 1);
+    }
+
+    moon = xglGenLists (1);
+    xglNewList (moon, GL_COMPILE);
+  
+    xglMaterialfv (GL_FRONT, GL_AMBIENT, black);
+    xglMaterialfv (GL_FRONT, GL_DIFFUSE, moonColor);
+    xglPushMatrix ();
+    xglTranslatef (xMoon, yMoon, zMoon);
+    xglScalef (1400, 1400, 1400);
+  
+    glutSolidSphere (1.0, 10, 10);
+    xglPopMatrix ();
+    xglEndList ();
+}
+
+
+/* Draw the moon */
+void fgMoonRender( void ) {
+    xglCallList(moon);
+}
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:21:28  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.9  1998/04/18 04:13:56  curt
+ * Moved fg_debug.c to it's own library.
+ *
+ * Revision 1.8  1998/04/03 21:52:49  curt
+ * Converting to Gnu autoconf system.
+ *
+ * Revision 1.7  1998/02/23 19:07:54  curt
+ * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
+ * calculation code between sun display, and other FG sections that use this
+ * for things like lighting.
+ *
+ * Revision 1.6  1998/02/07 15:29:32  curt
+ * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * 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.2  1998/01/19 18:40:16  curt
+ * Tons of little changes to clean up the code and to remove fatal errors
+ * when building with the c++ compiler.
+ *
+ * Revision 1.1  1998/01/07 03:16:16  curt
+ * Moved from .../Src/Scenery/ to .../Src/Astro/
+ *
+ * Revision 1.16  1998/01/06 01:20:24  curt
+ * Tweaks to help building with MSVC++
+ *
+ * Revision 1.15  1998/01/05 18:44:35  curt
+ * Add an option to advance/decrease time from keyboard.
+ *
+ * Revision 1.14  1997/12/30 20:47:50  curt
+ * Integrated new event manager with subsystem initializations.
+ *
+ * Revision 1.13  1997/12/30 16:41:00  curt
+ * Added log at end of file.
+ *
+ */
diff --git a/Astro/moon.h b/Astro/moon.h
deleted file mode 100644 (file)
index ff7b210..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/**************************************************************************
- * moon.h
- *
- * Written 1997 by Durk Talsma, started October, 1997.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#ifndef _MOON_H
-#define _MOON_H
-
-
-#ifdef __cplusplus                                                          
-extern "C" {                            
-#endif                                   
-
-
-#include <Astro/orbits.h>
-
-#include <Time/fg_time.h>
-#include <math.h>
-
-
-/* Initialize the Moon Display management Subsystem */
-void fgMoonInit( void );
-
-/* Draw the Moon */
-void fgMoonRender( void );
-
-struct CelestialCoord fgCalculateMoon(struct OrbElements Params,
-                                      struct OrbElements sunParams,
-                                      struct fgTIME t);
-
-extern struct OrbElements pltOrbElements[9];
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _MOON_H */
-
-
-/* $Log$
-/* Revision 1.7  1998/04/21 17:02:30  curt
-/* Prepairing for C++ integration.
-/*
- * Revision 1.6  1998/02/23 19:07:54  curt
- * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
- * calculation code between sun display, and other FG sections that use this
- * for things like lighting.
- *
- * 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.2  1998/01/19 18:40:17  curt
- * Tons of little changes to clean up the code and to remove fatal errors
- * when building with the c++ compiler.
- *
- * Revision 1.1  1998/01/07 03:16:16  curt
- * Moved from .../Src/Scenery/ to .../Src/Astro/
- *
- * Revision 1.4  1997/12/11 04:43:56  curt
- * Fixed sun vector and lighting problems.  I thing the moon is now lit
- * correctly.
- *
- * Revision 1.3  1997/11/25 19:25:35  curt
- * Changes to integrate Durk's moon/sun code updates + clean up.
- *
- * Revision 1.2  1997/10/25 03:24:23  curt
- * Incorporated sun, moon, and star positioning code contributed by Durk Talsma.
- *
- * Revision 1.1  1997/10/25 03:16:09  curt
- * Initial revision of code contributed by Durk Talsma.
- *
- */
diff --git a/Astro/moon.hxx b/Astro/moon.hxx
new file mode 100644 (file)
index 0000000..c183800
--- /dev/null
@@ -0,0 +1,99 @@
+/**************************************************************************
+ * moon.h
+ *
+ * Written 1997 by Durk Talsma, started October, 1997.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#ifndef _MOON_HXX
+#define _MOON_HXX
+
+
+#ifndef __cplusplus                                                          
+# error This library requires C++
+#endif                                   
+
+
+#include <math.h>
+
+#include <Time/fg_time.h>
+
+#include "orbits.hxx"
+
+
+/* Initialize the Moon Display management Subsystem */
+void fgMoonInit( void );
+
+/* Draw the Moon */
+void fgMoonRender( void );
+
+struct CelestialCoord fgCalculateMoon(struct OrbElements Params,
+                                      struct OrbElements sunParams,
+                                      struct fgTIME t);
+
+extern struct OrbElements pltOrbElements[9];
+
+
+#endif /* _MOON_HXX */
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:21:28  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.7  1998/04/21 17:02:30  curt
+ * Prepairing for C++ integration.
+ *
+ * Revision 1.6  1998/02/23 19:07:54  curt
+ * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
+ * calculation code between sun display, and other FG sections that use this
+ * for things like lighting.
+ *
+ * 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.2  1998/01/19 18:40:17  curt
+ * Tons of little changes to clean up the code and to remove fatal errors
+ * when building with the c++ compiler.
+ *
+ * Revision 1.1  1998/01/07 03:16:16  curt
+ * Moved from .../Src/Scenery/ to .../Src/Astro/
+ *
+ * Revision 1.4  1997/12/11 04:43:56  curt
+ * Fixed sun vector and lighting problems.  I thing the moon is now lit
+ * correctly.
+ *
+ * Revision 1.3  1997/11/25 19:25:35  curt
+ * Changes to integrate Durk's moon/sun code updates + clean up.
+ *
+ * Revision 1.2  1997/10/25 03:24:23  curt
+ * Incorporated sun, moon, and star positioning code contributed by Durk Talsma.
+ *
+ * Revision 1.1  1997/10/25 03:16:09  curt
+ * Initial revision of code contributed by Durk Talsma.
+ *
+ */
diff --git a/Astro/orbits.c b/Astro/orbits.c
deleted file mode 100644 (file)
index 97619ef..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-/**************************************************************************
- * orbits.c - calculates the orbital elements of the sun, moon and planets.
- *            For inclusion in flight gear
- *
- * Written 1997 by Durk Talsma, started October 19, 1997.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#include <math.h>
-#include <string.h>
-
-#include <Astro/orbits.h>
-
-#include <Debug/fg_debug.h>
-#include <Include/fg_constants.h>
-#include <Include/general.h>
-#include <Time/fg_time.h>
-
-struct OrbElements pltOrbElements[9];
-
-
-double fgCalcActTime(struct fgTIME t)
-{
-  return (t.mjd - 36523.5);
-}
-
-
-double fgCalcEccAnom(double M, double e)
-{
-    double
-       eccAnom, E0, E1, diff;
-
-    eccAnom = M + e * sin(M) * (1.0 + e * cos(M));
-    /* iterate to achieve a greater precision for larger eccentricities */
-    if (e > 0.05)
-    {
-       E0 = eccAnom;
-        do
-        {
-               E1 = E0 - (E0 - e * sin(E0) - M) / (1 - e * cos(E0));
-            diff = fabs(E0 - E1);
-            E0 = E1;
-               }
-        while (diff > (DEG_TO_RAD * 0.001));
-        return E0;
-       }
-    return eccAnom;
-}
-
-
-/* This function assumes that if the FILE ptr is valid that the
-   contents will be valid. Should we check the file for validity? */
-  
-/* Sounds like a good idea to me. What type of checks are you thinking
-   of, other than feof(FILE*)? That's currently the only check I can
-   think of (Durk) */
-
-int fgReadOrbElements(struct OrbElements *dest, FILE *src)
-{
-       char line[256];
-    int i,j;
-    j = 0;
-    do
-    {
-       if (feof (src)) {
-           fgPrintf (FG_ASTRO, FG_ALERT,
-                     "End of file found while reading planetary positions:\n");
-           return 0;
-       }
-       fgets(line, 256,src);
-        for (i = 0; i < 256; i++)
-        {
-               if (line[i] == '#')
-               line[i] = 0;
-               }
-               /*printf("Reading line %d\n", j++); */
-    }
-    while (!(strlen(line)));
-    sscanf(line, "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n",
-           &dest->NFirst, &dest->NSec,
-           &dest->iFirst, &dest->iSec,
-           &dest->wFirst, &dest->wSec,
-           &dest->aFirst, &dest->aSec,
-           &dest->eFirst, &dest->eSec,
-           &dest->MFirst, &dest->MSec);
-
-    return(1);
-}
-
-
-int fgSolarSystemInit(struct fgTIME t)
-{
-    fgGENERAL *g;
-    char path[80];
-    int i;
-    FILE *data;
-    int ret_val = 0;
-
-    fgPrintf( FG_ASTRO, FG_INFO, "Initializing solar system\n");
-
-   /* build the full path name to the orbital elements database file */
-    g = &general;
-    path[0] = '\0';
-    strcat(path, g->root_dir);
-    strcat(path, "/Scenery/");
-    strcat(path, "Planets.dat");
-
-    if ( (data = fopen(path, "r")) == NULL )
-    {
-           fgPrintf( FG_ASTRO, FG_ALERT,
-                     "Cannot open data file: '%s'\n", path);
-    } else {
-       /* printf("  reading datafile %s\n", path); */
-       fgPrintf( FG_ASTRO, FG_INFO, "  reading datafile %s\n", path);
-
-       /* for all the objects... */
-       for (i = 0; i < 9; i ++)
-           {
-               /* ...read from the data file ... */
-               if (!(fgReadOrbElements (&pltOrbElements[i], data))) {
-                   ret_val = 0;
-               }
-               /* ...and calculate the actual values */
-               fgSolarSystemUpdate(&pltOrbElements[i], t);
-           }
-       ret_val = 1;
-    }
-    return ret_val;
-}
-
-
-void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t)
-{
-   double
-         actTime;
-
-   actTime = fgCalcActTime(t);
-
-   /* calculate the actual orbital elements */
-   planet->M = DEG_TO_RAD * (planet->MFirst + (planet->MSec * actTime));
-   planet->w = DEG_TO_RAD * (planet->wFirst + (planet->wSec * actTime));
-   planet->N = DEG_TO_RAD * (planet->NFirst + (planet->NSec * actTime));
-   planet->i = DEG_TO_RAD * (planet->iFirst + (planet->iSec * actTime));
-   planet->e = planet->eFirst + (planet->eSec * actTime);
-   planet->a = planet->aFirst + (planet->aSec * actTime);
-}
-
-
-/* $Log$
-/* Revision 1.10  1998/04/18 04:13:57  curt
-/* Moved fg_debug.c to it's own library.
-/*
- * Revision 1.9  1998/03/14 00:27:12  curt
- * Updated fgGENERAL to a "type" of struct.
- *
- * Revision 1.8  1998/02/23 19:07:55  curt
- * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
- * calculation code between sun display, and other FG sections that use this
- * for things like lighting.
- *
- * Revision 1.7  1998/02/12 21:59:33  curt
- * Incorporated code changes contributed by Charlie Hotchkiss
- * <chotchkiss@namg.us.anritsu.com>
- *
- * Revision 1.6  1998/02/03 23:20:11  curt
- * Lots of little tweaks to fix various consistency problems discovered by
- * Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
- * passed arguments along to the real printf().  Also incorporated HUD changes
- * by Michele America.
- *
- * 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.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.1  1998/01/07 03:16:17  curt
- * Moved from .../Src/Scenery/ to .../Src/Astro/
- *
- * Revision 1.6  1997/12/30 20:47:52  curt
- * Integrated new event manager with subsystem initializations.
- *
- * Revision 1.5  1997/12/15 23:55:02  curt
- * Add xgl wrappers for debugging.
- * Generate terrain normals on the fly.
- *
- * Revision 1.4  1997/12/10 22:37:51  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.3  1997/11/25 23:20:44  curt
- * Changed planets.dat Planets.dat
- *
- * Revision 1.2  1997/11/25 19:25:36  curt
- * Changes to integrate Durk's moon/sun code updates + clean up.
- *
- * Revision 1.1  1997/10/25 03:16:10  curt
- * Initial revision of code contributed by Durk Talsma.
- *
- */
diff --git a/Astro/orbits.cxx b/Astro/orbits.cxx
new file mode 100644 (file)
index 0000000..40ff471
--- /dev/null
@@ -0,0 +1,232 @@
+/**************************************************************************
+ * orbits.c - calculates the orbital elements of the sun, moon and planets.
+ *            For inclusion in flight gear
+ *
+ * Written 1997 by Durk Talsma, started October 19, 1997.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#include <config.h>
+
+#include <math.h>
+#include <string.h>
+
+#include <Debug/fg_debug.h>
+#include <Include/fg_constants.h>
+#include <Include/general.h>
+#include <Time/fg_time.h>
+
+#include "orbits.hxx"
+
+
+struct OrbElements pltOrbElements[9];
+
+
+double fgCalcActTime(struct fgTIME t)
+{
+  return (t.mjd - 36523.5);
+}
+
+
+double fgCalcEccAnom(double M, double e)
+{
+    double
+       eccAnom, E0, E1, diff;
+
+    eccAnom = M + e * sin(M) * (1.0 + e * cos(M));
+    /* iterate to achieve a greater precision for larger eccentricities */
+    if (e > 0.05)
+    {
+       E0 = eccAnom;
+        do
+        {
+               E1 = E0 - (E0 - e * sin(E0) - M) / (1 - e * cos(E0));
+            diff = fabs(E0 - E1);
+            E0 = E1;
+               }
+        while (diff > (DEG_TO_RAD * 0.001));
+        return E0;
+       }
+    return eccAnom;
+}
+
+
+/* This function assumes that if the FILE ptr is valid that the
+   contents will be valid. Should we check the file for validity? */
+  
+/* Sounds like a good idea to me. What type of checks are you thinking
+   of, other than feof(FILE*)? That's currently the only check I can
+   think of (Durk) */
+
+int fgReadOrbElements(struct OrbElements *dest, FILE *src)
+{
+       char line[256];
+    int i,j;
+    j = 0;
+    do
+    {
+       if (feof (src)) {
+           fgPrintf (FG_ASTRO, FG_ALERT,
+                     "End of file found while reading planetary positions:\n");
+           return 0;
+       }
+       fgets(line, 256,src);
+        for (i = 0; i < 256; i++)
+        {
+               if (line[i] == '#')
+               line[i] = 0;
+               }
+               /*printf("Reading line %d\n", j++); */
+    }
+    while (!(strlen(line)));
+    sscanf(line, "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n",
+           &dest->NFirst, &dest->NSec,
+           &dest->iFirst, &dest->iSec,
+           &dest->wFirst, &dest->wSec,
+           &dest->aFirst, &dest->aSec,
+           &dest->eFirst, &dest->eSec,
+           &dest->MFirst, &dest->MSec);
+
+    return(1);
+}
+
+
+int fgSolarSystemInit(struct fgTIME t)
+{
+    fgGENERAL *g;
+    char path[80];
+    int i;
+    FILE *data;
+    int ret_val = 0;
+
+    fgPrintf( FG_ASTRO, FG_INFO, "Initializing solar system\n");
+
+   /* build the full path name to the orbital elements database file */
+    g = &general;
+    path[0] = '\0';
+    strcat(path, g->root_dir);
+    strcat(path, "/Scenery/");
+    strcat(path, "Planets.dat");
+
+    if ( (data = fopen(path, "r")) == NULL )
+    {
+           fgPrintf( FG_ASTRO, FG_ALERT,
+                     "Cannot open data file: '%s'\n", path);
+    } else {
+       /* printf("  reading datafile %s\n", path); */
+       fgPrintf( FG_ASTRO, FG_INFO, "  reading datafile %s\n", path);
+
+       /* for all the objects... */
+       for (i = 0; i < 9; i ++)
+           {
+               /* ...read from the data file ... */
+               if (!(fgReadOrbElements (&pltOrbElements[i], data))) {
+                   ret_val = 0;
+               }
+               /* ...and calculate the actual values */
+               fgSolarSystemUpdate(&pltOrbElements[i], t);
+           }
+       ret_val = 1;
+    }
+    return ret_val;
+}
+
+
+void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t)
+{
+   double
+         actTime;
+
+   actTime = fgCalcActTime(t);
+
+   /* calculate the actual orbital elements */
+   planet->M = DEG_TO_RAD * (planet->MFirst + (planet->MSec * actTime));
+   planet->w = DEG_TO_RAD * (planet->wFirst + (planet->wSec * actTime));
+   planet->N = DEG_TO_RAD * (planet->NFirst + (planet->NSec * actTime));
+   planet->i = DEG_TO_RAD * (planet->iFirst + (planet->iSec * actTime));
+   planet->e = planet->eFirst + (planet->eSec * actTime);
+   planet->a = planet->aFirst + (planet->aSec * actTime);
+}
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:21:29  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.10  1998/04/18 04:13:57  curt
+ * Moved fg_debug.c to it's own library.
+ *
+ * Revision 1.9  1998/03/14 00:27:12  curt
+ * Updated fgGENERAL to a "type" of struct.
+ *
+ * Revision 1.8  1998/02/23 19:07:55  curt
+ * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
+ * calculation code between sun display, and other FG sections that use this
+ * for things like lighting.
+ *
+ * Revision 1.7  1998/02/12 21:59:33  curt
+ * Incorporated code changes contributed by Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * Revision 1.6  1998/02/03 23:20:11  curt
+ * Lots of little tweaks to fix various consistency problems discovered by
+ * Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
+ * passed arguments along to the real printf().  Also incorporated HUD changes
+ * by Michele America.
+ *
+ * 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.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.1  1998/01/07 03:16:17  curt
+ * Moved from .../Src/Scenery/ to .../Src/Astro/
+ *
+ * Revision 1.6  1997/12/30 20:47:52  curt
+ * Integrated new event manager with subsystem initializations.
+ *
+ * Revision 1.5  1997/12/15 23:55:02  curt
+ * Add xgl wrappers for debugging.
+ * Generate terrain normals on the fly.
+ *
+ * Revision 1.4  1997/12/10 22:37:51  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.3  1997/11/25 23:20:44  curt
+ * Changed planets.dat Planets.dat
+ *
+ * Revision 1.2  1997/11/25 19:25:36  curt
+ * Changes to integrate Durk's moon/sun code updates + clean up.
+ *
+ * Revision 1.1  1997/10/25 03:16:10  curt
+ * Initial revision of code contributed by Durk Talsma.
+ *
+ */
diff --git a/Astro/orbits.h b/Astro/orbits.h
deleted file mode 100644 (file)
index ab94bea..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/**************************************************************************
- * orbits.h - calculates the orbital elements of the sun, moon and planets.
- *            For inclusion in flight gear
- *
- * Written 1997 by Durk Talsma, started October 19, 1997.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#ifndef _ORBITS_H
-#define _ORBITS_H
-
-
-#ifdef __cplusplus                                                          
-extern "C" {                            
-#endif                                   
-
-
-#include <stdio.h>
-#include <math.h>
-
-#include <Time/fg_time.h>
-
-
-
-//#define STANDARDEPOCH 2000
-
-typedef struct {
-    double xs;
-    double ys;
-    double dist;
-    double lonSun;
-} fgSUNPOS;
-
-extern fgSUNPOS solarPosition;
-
-
-struct OrbElements {
-    double NFirst;             /* longitude of the ascending node first part */
-    double NSec;               /* longitude of the ascending node second part */
-    double iFirst;             /* inclination to the ecliptic first part */
-    double iSec;               /* inclination to the ecliptic second part */
-    double wFirst;             /* first part of argument of perihelion */
-    double wSec;               /* second part of argument of perihelion */
-    double aFirst;             /* semimayor axis first part*/
-    double aSec;               /* semimayor axis second part */
-    double eFirst;             /* eccentricity first part */
-    double eSec;               /* eccentricity second part */
-    double MFirst;             /* Mean anomaly first part */
-    double MSec;               /* Mean anomaly second part */
-
-    double N, i, w, a, e, M;   /* the resultant orbital elements, obtained from the former */
-};
-
-struct CelestialCoord {
-    double RightAscension;
-    double Declination;
-    double distance;
-    double magnitude;
-};
-
-
-double fgCalcEccAnom(double M, double e);
-double fgCalcActTime(struct fgTIME t);
-
-int fgReadOrbElements (struct OrbElements *dest, FILE * src);
-int  fgSolarSystemInit(struct fgTIME t);
-void fgSolarSystemUpdate(struct OrbElements *planets, struct fgTIME t);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _ORBITS_H */
-
-
-/* $Log$
-/* Revision 1.7  1998/04/21 17:02:31  curt
-/* Prepairing for C++ integration.
-/*
- * Revision 1.6  1998/02/23 19:07:55  curt
- * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
- * calculation code between sun display, and other FG sections that use this
- * for things like lighting.
- *
- * Revision 1.5  1998/02/12 21:59:35  curt
- * Incorporated code changes contributed by Charlie Hotchkiss
- * <chotchkiss@namg.us.anritsu.com>
- *
- * 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.1  1998/01/07 03:16:17  curt
- * Moved from .../Src/Scenery/ to .../Src/Astro/
- *
- * Revision 1.2  1997/12/30 16:36:52  curt
- * Merged in Durk's changes ...
- *
- * Revision 1.1  1997/10/25 03:16:10  curt
- * Initial revision of code contributed by Durk Talsma.
- *
- */
diff --git a/Astro/orbits.hxx b/Astro/orbits.hxx
new file mode 100644 (file)
index 0000000..a468fcb
--- /dev/null
@@ -0,0 +1,125 @@
+/**************************************************************************
+ * orbits.h - calculates the orbital elements of the sun, moon and planets.
+ *            For inclusion in flight gear
+ *
+ * Written 1997 by Durk Talsma, started October 19, 1997.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#ifndef _ORBITS_HXX
+#define _ORBITS_HXX
+
+
+#ifndef __cplusplus                                                          
+# error This library requires C++
+#endif                                   
+
+
+#include <stdio.h>
+#include <math.h>
+
+#include <Time/fg_time.h>
+
+
+
+//#define STANDARDEPOCH 2000
+
+typedef struct {
+    double xs;
+    double ys;
+    double dist;
+    double lonSun;
+} fgSUNPOS;
+
+extern fgSUNPOS solarPosition;
+
+
+struct OrbElements {
+    double NFirst;             /* longitude of the ascending node first part */
+    double NSec;               /* longitude of the ascending node second part */
+    double iFirst;             /* inclination to the ecliptic first part */
+    double iSec;               /* inclination to the ecliptic second part */
+    double wFirst;             /* first part of argument of perihelion */
+    double wSec;               /* second part of argument of perihelion */
+    double aFirst;             /* semimayor axis first part*/
+    double aSec;               /* semimayor axis second part */
+    double eFirst;             /* eccentricity first part */
+    double eSec;               /* eccentricity second part */
+    double MFirst;             /* Mean anomaly first part */
+    double MSec;               /* Mean anomaly second part */
+
+    double N, i, w, a, e, M;   /* the resultant orbital elements, obtained from the former */
+};
+
+struct CelestialCoord {
+    double RightAscension;
+    double Declination;
+    double distance;
+    double magnitude;
+};
+
+
+double fgCalcEccAnom(double M, double e);
+double fgCalcActTime(struct fgTIME t);
+
+int fgReadOrbElements (struct OrbElements *dest, FILE * src);
+int  fgSolarSystemInit(struct fgTIME t);
+void fgSolarSystemUpdate(struct OrbElements *planets, struct fgTIME t);
+
+
+#endif /* _ORBITS_HXX */
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:21:30  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.7  1998/04/21 17:02:31  curt
+ * Prepairing for C++ integration.
+ *
+ * Revision 1.6  1998/02/23 19:07:55  curt
+ * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
+ * calculation code between sun display, and other FG sections that use this
+ * for things like lighting.
+ *
+ * Revision 1.5  1998/02/12 21:59:35  curt
+ * Incorporated code changes contributed by Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * 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.1  1998/01/07 03:16:17  curt
+ * Moved from .../Src/Scenery/ to .../Src/Astro/
+ *
+ * Revision 1.2  1997/12/30 16:36:52  curt
+ * Merged in Durk's changes ...
+ *
+ * Revision 1.1  1997/10/25 03:16:10  curt
+ * Initial revision of code contributed by Durk Talsma.
+ *
+ */
diff --git a/Astro/planets.c b/Astro/planets.c
deleted file mode 100644 (file)
index 8f99ba0..0000000
+++ /dev/null
@@ -1,258 +0,0 @@
-/**************************************************************************
- * planets.c
- *
- * Written 1997 by Durk Talsma, started October, 1997.  For the flight gear
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#include <config.h>
-
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#endif
-
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-
-#include <Astro/orbits.h>
-#include <Astro/planets.h>
-#include <Astro/sun.h>
-#include <Debug/fg_debug.h>
-#include <Include/fg_constants.h>
-#include <Time/fg_time.h>
-
-GLint planets = 0;
-
-struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
-                                        struct OrbElements theSun,
-                                        struct fgTIME t, int idx)
-{
-    struct CelestialCoord result;
-
-    fgSUNPOS SolarPosition;
-
-    double eccAnom, r, v, ecl, actTime, R, s, ir, Nr, B, FV, ring_magn,
-        xv, yv, xh, yh, zh, xg, yg, zg, xe, ye, ze;
-
-    actTime = fgCalcActTime(t);
-    /*calculate the angle between ecliptic and equatorial coordinate system */
-    ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime);
-
-    /* calculate the eccentric anomaly */
-    eccAnom  = fgCalcEccAnom(planet.M, planet.e);
-
-    /* calculate the planets distance (r) and true anomaly (v) */
-    xv = planet.a * (cos(eccAnom) - planet.e);
-    yv = planet.a * (sqrt(1.0 - planet.e*planet.e) * sin(eccAnom));
-    v = atan2(yv, xv);
-    r = sqrt ( xv*xv + yv*yv);
-    
-    /* calculate the planets position in 3-dimensional space */
-    xh = r * (cos (planet.N) * cos (v + planet.w) -
-             sin (planet.N) * sin (v + planet.w) * cos (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 ecliptic longitude and latitude */
-
-    xg = xh + solarPosition.xs;
-    yg = yh + solarPosition.ys;
-    zg = zh;
-
-    xe = xg;
-    ye = yg * cos(ecl) - zg * sin(ecl);
-    ze = yg * sin(ecl) + zg * cos(ecl);
-
-    result.RightAscension = atan2(ye,xe);
-    result.Declination = atan2(ze, sqrt(xe*xe + ye*ye));
-        
-    /* Let's calculate the brightness of the planet */
-    R = sqrt ( xg*xg + yg*yg + zg*zg);
-    s = SolarPosition.dist;
-    FV = acos(  (r*r + R*R - s*s) / (2*r*R));
-    FV  *= 57.29578;  /* convert radians to degrees */ 
-    switch(idx)
-      {
-      case 2: /* mercury */
-       result.magnitude = -0.36 + 5*log10( r*R ) + 0.027 * FV + 2.2E-13 * pow(FV, 6);
-       break;
-      case 3: /*venus */
-       result.magnitude = -4.34 + 5*log10( r*R ) + 0.013 * FV + 4.2E-07 * pow(FV,3);
-       break;
-      case 4: /* mars */
-       result.magnitude = -1.51 + 5*log10( r*R ) + 0.016 * FV;
-       break;
-      case 5: /* Jupiter */
-       result.magnitude = -9.25 + 5*log10( r*R ) + 0.014 * FV;
-       break;
-      case 6: /* Saturn */
-       
-       ir = 0.4897394;
-       Nr = 2.9585076 + 6.6672E-7*actTime;
-       
-       B = asin (sin (result.Declination) * cos (ir) -
-                 cos (result.Declination) * sin (ir) *
-                 sin (result.RightAscension - Nr));
-       ring_magn = -2.6 * sin (fabs(B)) + 1.2 * pow(sin(B),2);
-       result.magnitude = -9.0 + 5*log10( r*R ) + 0.044 * FV + ring_magn;
-       break;
-      case 7: /* Uranus */
-       result.magnitude = -7.15 + 5*log10( r*R) + 0.001 * FV;
-       break;
-      case 8:  /* Neptune */
-       result.magnitude = -6.90 + 5*log10 (r*R) + 0.001 *FV;
-       break;
-      default:
-       fgPrintf( FG_ASTRO, FG_ALERT, "index %d out of range !!!!\n", idx);
-      }
-    fgPrintf( FG_ASTRO, FG_DEBUG,
-             "    Planet found at %f (ra), %f (dec)\n",
-             result.RightAscension, result.Declination);
-    fgPrintf( FG_ASTRO, FG_DEBUG,
-             "      Geocentric dist     %f\n"
-             "      Heliocentric dist   %f\n"
-             "      Distance to the sun %f\n"
-             "      Phase angle         %f\n"
-             "      Brightness          %f\n", R, r, s, FV, result.magnitude);
-    return result;
-}
-
-
-void fgPlanetsInit( void )
-{
-  struct fgLIGHT *l;
-  int i;
-  struct CelestialCoord pltPos;
-  double magnitude;
-
-  l = &cur_light_params;
-  /* if the display list was already built during a previous init,
-     then 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);
-    
-    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; }
-    
-    /* Add planets to the display list, based on sun_angle and current
-       magnitude It's pretty experimental... */
-
-    if ((double) (l->sun_angle - FG_PI_2) > 
-       ((magnitude - 1.0) * -20 * DEG_TO_RAD))
-       {
-           xglColor3f (magnitude, magnitude, magnitude);
-           printf ("Sun Angle to Horizon (in Rads) = %f\n", 
-                   (double) (l->sun_angle - FG_PI_2));
-           printf ("Transformed Magnitude is :%f  %f\n", 
-                   magnitude, (magnitude - 1.0) * -20 * DEG_TO_RAD);
-           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$
-/* Revision 1.9  1998/04/18 04:13:57  curt
-/* Moved fg_debug.c to it's own library.
-/*
- * Revision 1.8  1998/04/03 21:52:50  curt
- * Converting to Gnu autoconf system.
- *
- * Revision 1.7  1998/02/23 19:07:55  curt
- * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
- * calculation code between sun display, and other FG sections that use this
- * for things like lighting.
- *
- * Revision 1.6  1998/02/12 21:59:36  curt
- * Incorporated code changes contributed by Charlie Hotchkiss
- * <chotchkiss@namg.us.anritsu.com>
- *
- * Revision 1.5  1998/02/03 23:20:12  curt
- * Lots of little tweaks to fix various consistency problems discovered by
- * Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
- * passed arguments along to the real printf().  Also incorporated HUD changes
- * by Michele America.
- *
- * 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.1  1998/01/07 03:16:18  curt
- * Moved from .../Src/Scenery/ to .../Src/Astro/
- *
- * Revision 1.4  1997/12/30 20:47:52  curt
- * Integrated new event manager with subsystem initializations.
- *
- * Revision 1.3  1997/12/30 16:36:52  curt
- * Merged in Durk's changes ...
- *
- * Revision 1.2  1997/12/12 21:41:29  curt
- * More light/material property tweaking ... still a ways off.
- *
- * Revision 1.1  1997/10/25 03:16:10  curt
- * Initial revision of code contributed by Durk Talsma.
- *
- */
-
-
diff --git a/Astro/planets.cxx b/Astro/planets.cxx
new file mode 100644 (file)
index 0000000..2d90d99
--- /dev/null
@@ -0,0 +1,263 @@
+/**************************************************************************
+ * planets.c
+ *
+ * Written 1997 by Durk Talsma, started October, 1997.  For the flight gear
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#include <config.h>
+
+#ifdef HAVE_WINDOWS_H
+#  include <windows.h>
+#endif
+
+#include <GL/glut.h>
+#include <XGL/xgl.h>
+
+#include <Debug/fg_debug.h>
+#include <Include/fg_constants.h>
+#include <Time/fg_time.h>
+#include <Time/light.hxx>
+
+#include "orbits.hxx"
+#include "planets.hxx"
+#include "sun.hxx"
+
+GLint planets = 0;
+
+struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
+                                        struct OrbElements theSun,
+                                        struct fgTIME t, int idx)
+{
+    struct CelestialCoord result;
+
+    fgSUNPOS SolarPosition;
+
+    double eccAnom, r, v, ecl, actTime, R, s, ir, Nr, B, FV, ring_magn,
+        xv, yv, xh, yh, zh, xg, yg, zg, xe, ye, ze;
+
+    actTime = fgCalcActTime(t);
+    /*calculate the angle between ecliptic and equatorial coordinate system */
+    ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime);
+
+    /* calculate the eccentric anomaly */
+    eccAnom  = fgCalcEccAnom(planet.M, planet.e);
+
+    /* calculate the planets distance (r) and true anomaly (v) */
+    xv = planet.a * (cos(eccAnom) - planet.e);
+    yv = planet.a * (sqrt(1.0 - planet.e*planet.e) * sin(eccAnom));
+    v = atan2(yv, xv);
+    r = sqrt ( xv*xv + yv*yv);
+    
+    /* calculate the planets position in 3-dimensional space */
+    xh = r * (cos (planet.N) * cos (v + planet.w) -
+             sin (planet.N) * sin (v + planet.w) * cos (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 ecliptic longitude and latitude */
+
+    xg = xh + solarPosition.xs;
+    yg = yh + solarPosition.ys;
+    zg = zh;
+
+    xe = xg;
+    ye = yg * cos(ecl) - zg * sin(ecl);
+    ze = yg * sin(ecl) + zg * cos(ecl);
+
+    result.RightAscension = atan2(ye,xe);
+    result.Declination = atan2(ze, sqrt(xe*xe + ye*ye));
+        
+    /* Let's calculate the brightness of the planet */
+    R = sqrt ( xg*xg + yg*yg + zg*zg);
+    s = SolarPosition.dist;
+    FV = acos(  (r*r + R*R - s*s) / (2*r*R));
+    FV  *= 57.29578;  /* convert radians to degrees */ 
+    switch(idx)
+      {
+      case 2: /* mercury */
+       result.magnitude = -0.36 + 5*log10( r*R ) + 0.027 * FV + 2.2E-13 * pow(FV, 6);
+       break;
+      case 3: /*venus */
+       result.magnitude = -4.34 + 5*log10( r*R ) + 0.013 * FV + 4.2E-07 * pow(FV,3);
+       break;
+      case 4: /* mars */
+       result.magnitude = -1.51 + 5*log10( r*R ) + 0.016 * FV;
+       break;
+      case 5: /* Jupiter */
+       result.magnitude = -9.25 + 5*log10( r*R ) + 0.014 * FV;
+       break;
+      case 6: /* Saturn */
+       
+       ir = 0.4897394;
+       Nr = 2.9585076 + 6.6672E-7*actTime;
+       
+       B = asin (sin (result.Declination) * cos (ir) -
+                 cos (result.Declination) * sin (ir) *
+                 sin (result.RightAscension - Nr));
+       ring_magn = -2.6 * sin (fabs(B)) + 1.2 * pow(sin(B),2);
+       result.magnitude = -9.0 + 5*log10( r*R ) + 0.044 * FV + ring_magn;
+       break;
+      case 7: /* Uranus */
+       result.magnitude = -7.15 + 5*log10( r*R) + 0.001 * FV;
+       break;
+      case 8:  /* Neptune */
+       result.magnitude = -6.90 + 5*log10 (r*R) + 0.001 *FV;
+       break;
+      default:
+       fgPrintf( FG_ASTRO, FG_ALERT, "index %d out of range !!!!\n", idx);
+      }
+    fgPrintf( FG_ASTRO, FG_DEBUG,
+             "    Planet found at %f (ra), %f (dec)\n",
+             result.RightAscension, result.Declination);
+    fgPrintf( FG_ASTRO, FG_DEBUG,
+             "      Geocentric dist     %f\n"
+             "      Heliocentric dist   %f\n"
+             "      Distance to the sun %f\n"
+             "      Phase angle         %f\n"
+             "      Brightness          %f\n", R, r, s, FV, result.magnitude);
+    return result;
+}
+
+
+void fgPlanetsInit( void )
+{
+  struct fgLIGHT *l;
+  int i;
+  struct CelestialCoord pltPos;
+  double magnitude;
+
+  l = &cur_light_params;
+  /* if the display list was already built during a previous init,
+     then 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);
+    
+    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; }
+    
+    /* Add planets to the display list, based on sun_angle and current
+       magnitude It's pretty experimental... */
+
+    if ((double) (l->sun_angle - FG_PI_2) > 
+       ((magnitude - 1.0) * -20 * DEG_TO_RAD))
+       {
+           xglColor3f (magnitude, magnitude, magnitude);
+           printf ("Sun Angle to Horizon (in Rads) = %f\n", 
+                   (double) (l->sun_angle - FG_PI_2));
+           printf ("Transformed Magnitude is :%f  %f\n", 
+                   magnitude, (magnitude - 1.0) * -20 * DEG_TO_RAD);
+           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$
+/* Revision 1.1  1998/04/22 13:21:31  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.9  1998/04/18 04:13:57  curt
+ * Moved fg_debug.c to it's own library.
+ *
+ * Revision 1.8  1998/04/03 21:52:50  curt
+ * Converting to Gnu autoconf system.
+ *
+ * Revision 1.7  1998/02/23 19:07:55  curt
+ * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
+ * calculation code between sun display, and other FG sections that use this
+ * for things like lighting.
+ *
+ * Revision 1.6  1998/02/12 21:59:36  curt
+ * Incorporated code changes contributed by Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * Revision 1.5  1998/02/03 23:20:12  curt
+ * Lots of little tweaks to fix various consistency problems discovered by
+ * Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
+ * passed arguments along to the real printf().  Also incorporated HUD changes
+ * by Michele America.
+ *
+ * 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.1  1998/01/07 03:16:18  curt
+ * Moved from .../Src/Scenery/ to .../Src/Astro/
+ *
+ * Revision 1.4  1997/12/30 20:47:52  curt
+ * Integrated new event manager with subsystem initializations.
+ *
+ * Revision 1.3  1997/12/30 16:36:52  curt
+ * Merged in Durk's changes ...
+ *
+ * Revision 1.2  1997/12/12 21:41:29  curt
+ * More light/material property tweaking ... still a ways off.
+ *
+ * Revision 1.1  1997/10/25 03:16:10  curt
+ * Initial revision of code contributed by Durk Talsma.
+ *
+ */
+
+
diff --git a/Astro/planets.h b/Astro/planets.h
deleted file mode 100644 (file)
index 8c147ff..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/**************************************************************************
- * planets.h
- *
- * Written 1997 by Durk Talsma, started October, 1997.  For the flight gear
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#ifndef _PLANETS_H
-#define _PLANETS_H
-
-
-#ifdef __cplusplus                                                          
-extern "C" {                            
-#endif                                   
-
-
-struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
-                                         struct OrbElements theSun,
-                                         struct fgTIME t, int idx);
-
-
-void fgPlanetsInit( void );
-void fgPlanetsRender( void );
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* PLANETS_H */
-
-
-/* $Log$
-/* Revision 1.5  1998/04/21 17:02:31  curt
-/* Prepairing for C++ integration.
-/*
- * Revision 1.4  1998/02/12 21:59:38  curt
- * Incorporated code changes contributed by Charlie Hotchkiss
- * <chotchkiss@namg.us.anritsu.com>
- *
- * 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.3  1997/12/30 16:36:53  curt
- * Merged in Durk's changes ...
- *
- * Revision 1.2  1997/12/12 21:41:30  curt
- * More light/material property tweaking ... still a ways off.
- *
- * Revision 1.1  1997/10/25 03:16:11  curt
- * Initial revision of code contributed by Durk Talsma.
- *
- */
diff --git a/Astro/planets.hxx b/Astro/planets.hxx
new file mode 100644 (file)
index 0000000..b83a270
--- /dev/null
@@ -0,0 +1,76 @@
+/**************************************************************************
+ * planets.hxx
+ *
+ * Written 1997 by Durk Talsma, started October, 1997.  For the flight gear
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#ifndef _PLANETS_HXX
+#define _PLANETS_HXX
+
+
+#ifndef __cplusplus                                                          
+# error This library requires C++
+#endif                                   
+
+
+struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
+                                         struct OrbElements theSun,
+                                         struct fgTIME t, int idx);
+
+
+void fgPlanetsInit( void );
+void fgPlanetsRender( void );
+
+
+#endif /* PLANETS_HXX */
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:21:32  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.5  1998/04/21 17:02:31  curt
+ * Prepairing for C++ integration.
+ *
+ * Revision 1.4  1998/02/12 21:59:38  curt
+ * Incorporated code changes contributed by Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * 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.3  1997/12/30 16:36:53  curt
+ * Merged in Durk's changes ...
+ *
+ * Revision 1.2  1997/12/12 21:41:30  curt
+ * More light/material property tweaking ... still a ways off.
+ *
+ * Revision 1.1  1997/10/25 03:16:11  curt
+ * Initial revision of code contributed by Durk Talsma.
+ *
+ */
diff --git a/Astro/sky.c b/Astro/sky.c
deleted file mode 100644 (file)
index 1382cc2..0000000
+++ /dev/null
@@ -1,423 +0,0 @@
-/**************************************************************************
- * sky.c -- model sky with an upside down "bowl"
- *
- * Written by Curtis Olson, started December 1997.
- *
- * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#include <config.h>
-
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#endif
-
-#include <math.h>
-
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-
-#include <Astro/sky.h>
-
-#include <Time/event.h>
-#include <Time/fg_time.h>
-
-#include <Aircraft/aircraft.h>
-#include <Flight/flight.h>
-#include <Include/fg_constants.h>
-#include <Main/views.h>
-#include <Math/fg_random.h>
-
-/*
-#include <Include/general.h>
-*/
-
-/* in meters of course */
-#define CENTER_ELEV   25000.0
-
-#define INNER_RADIUS  50000.0
-#define INNER_ELEV    20000.0
-
-#define MIDDLE_RADIUS 70000.0
-#define MIDDLE_ELEV    8000.0
-
-#define OUTER_RADIUS  80000.0
-#define OUTER_ELEV        0.0
-
-#define BOTTOM_RADIUS 50000.0
-#define BOTTOM_ELEV   -2000.0
-
-
-static float inner_vertex[12][3];
-static float middle_vertex[12][3];
-static float outer_vertex[12][3];
-static float bottom_vertex[12][3];
-
-static float inner_color[12][4];
-static float middle_color[12][4];
-static float outer_color[12][4];
-
-
-/* Calculate the sky structure vertices */
-void fgSkyVerticesInit( void ) {
-    float theta;
-    int i;
-
-    printf("  Generating the sky dome vertices.\n");
-
-    for ( i = 0; i < 12; i++ ) {
-       theta = (i * 30.0) * DEG_TO_RAD;
-       
-       inner_vertex[i][0] = cos(theta) * INNER_RADIUS;
-       inner_vertex[i][1] = sin(theta) * INNER_RADIUS;
-       inner_vertex[i][2] = INNER_ELEV;
-       
-       /* printf("    %.2f %.2f\n", cos(theta) * INNER_RADIUS, 
-              sin(theta) * INNER_RADIUS); */
-
-       middle_vertex[i][0] = cos((double)theta) * MIDDLE_RADIUS;
-       middle_vertex[i][1] = sin((double)theta) * MIDDLE_RADIUS;
-       middle_vertex[i][2] = MIDDLE_ELEV;
-           
-       outer_vertex[i][0] = cos((double)theta) * OUTER_RADIUS;
-       outer_vertex[i][1] = sin((double)theta) * OUTER_RADIUS;
-       outer_vertex[i][2] = OUTER_ELEV;
-           
-       bottom_vertex[i][0] = cos((double)theta) * BOTTOM_RADIUS;
-       bottom_vertex[i][1] = sin((double)theta) * BOTTOM_RADIUS;
-       bottom_vertex[i][2] = BOTTOM_ELEV;
-    }
-}
-
-
-/* (Re)calculate the sky colors at each vertex */
-void fgSkyColorsInit( void ) {
-    struct fgLIGHT *l;
-    float sun_angle, diff;
-    float outer_param[3], outer_amt[3], outer_diff[3];
-    float middle_param[3], middle_amt[3], middle_diff[3];
-    int i, j;
-
-    l = &cur_light_params;
-
-    printf("  Generating the sky colors for each vertex.\n");
-
-    /* setup for the possibility of sunset effects */
-    sun_angle = l->sun_angle * RAD_TO_DEG;
-    printf("  Sun angle in degrees = %.2f\n", sun_angle);
-
-    if ( (sun_angle > 80.0) && (sun_angle < 100.0) ) {
-       /* 0.0 - 0.4 */
-       outer_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 25.0;
-       outer_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 35.0;
-       outer_param[2] = 0.0;
-
-       middle_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 20.0;
-       middle_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 40.0;
-       middle_param[2] = 0.0;
-
-       outer_diff[0] = outer_param[0] / 6.0;
-       outer_diff[1] = outer_param[1] / 6.0;
-       outer_diff[2] = outer_param[2] / 6.0;
-
-       middle_diff[0] = middle_param[0] / 6.0;
-       middle_diff[1] = middle_param[1] / 6.0;
-       middle_diff[2] = middle_param[2] / 6.0;
-    } else {
-       outer_param[0] = outer_param[1] = outer_param[2] = 0.0;
-       middle_param[0] = middle_param[1] = middle_param[2] = 0.0;
-
-       outer_diff[0] = outer_diff[1] = outer_diff[2] = 0.0;
-       middle_diff[0] = middle_diff[1] = middle_diff[2] = 0.0;
-    }
-    /* printf("  outer_red_param = %.2f  outer_red_diff = %.2f\n", 
-          outer_red_param, outer_red_diff); */
-
-    /* calculate transition colors between sky and fog */
-    for ( j = 0; j < 3; j++ ) {
-       outer_amt[j] = outer_param[j];
-       middle_amt[j] = middle_param[j];
-    }
-
-    for ( i = 0; i < 6; i++ ) {
-       for ( j = 0; j < 3; j++ ) {
-           diff = l->sky_color[j] - l->fog_color[j];
-
-           inner_color[i][j] = l->sky_color[j] - diff * 0.3;
-           middle_color[i][j] = l->sky_color[j] - diff * 0.9 + middle_amt[j];
-           outer_color[i][j] = l->fog_color[j] + outer_amt[j];
-
-           if ( middle_color[i][j] > 1.00 ) { middle_color[i][j] = 1.00; }
-           if ( middle_color[i][j] < 0.10 ) { middle_color[i][j] = 0.10; }
-           if ( outer_color[i][j] > 1.00 ) { outer_color[i][j] = 1.00; }
-           if ( outer_color[i][j] < 0.10 ) { outer_color[i][j] = 0.10; }
-       }
-       inner_color[i][3] = middle_color[i][3] = outer_color[i][3] = 
-           l->sky_color[3];
-
-       for ( j = 0; j < 3; j++ ) {
-           outer_amt[j] -= outer_diff[j];
-           middle_amt[j] -= middle_diff[j];
-       }
-
-       /*
-       printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i, inner_color[i][0],
-              inner_color[i][1], inner_color[i][2], inner_color[i][3]);
-       printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i, 
-              middle_color[i][0], middle_color[i][1], middle_color[i][2], 
-              middle_color[i][3]);
-       printf("outer_color[%d] = %.2f %.2f %.2f %.2f\n", i, 
-              outer_color[i][0], outer_color[i][1], outer_color[i][2], 
-              outer_color[i][3]);
-       */
-    }
-
-    for ( j = 0; j < 3; j++ ) {
-       outer_amt[j] = 0.0;
-       middle_amt[j] = 0.0;
-    }
-
-    for ( i = 6; i < 12; i++ ) {
-
-       for ( j = 0; j < 3; j++ ) {
-           diff = l->sky_color[j] - l->fog_color[j];
-
-           inner_color[i][j] = l->sky_color[j] - diff * 0.3;
-           middle_color[i][j] = l->sky_color[j] - diff * 0.9 + middle_amt[j];
-           outer_color[i][j] = l->fog_color[j] + outer_amt[j];
-
-           if ( middle_color[i][j] > 1.00 ) { middle_color[i][j] = 1.00; }
-           if ( middle_color[i][j] < 0.10 ) { middle_color[i][j] = 0.10; }
-           if ( outer_color[i][j] > 1.00 ) { outer_color[i][j] = 1.00; }
-           if ( outer_color[i][j] < 0.15 ) { outer_color[i][j] = 0.15; }
-       }
-       inner_color[i][3] = middle_color[i][3] = outer_color[i][3] = 
-           l->sky_color[3];
-
-       for ( j = 0; j < 3; j++ ) {
-           outer_amt[j] += outer_diff[j];
-           middle_amt[j] += middle_diff[j];
-       }
-
-       /*
-       printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i, inner_color[i][0],
-              inner_color[i][1], inner_color[i][2], inner_color[i][3]);
-       printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i, 
-              middle_color[i][0], middle_color[i][1], middle_color[i][2], 
-              middle_color[i][3]);
-       printf("outer_color[%d] = %.2f %.2f %.2f %.2f\n", i, 
-              outer_color[i][0], outer_color[i][1], outer_color[i][2], 
-              outer_color[i][3]);
-       */
-    }
-}
-
-
-/* Initialize the sky structure and colors */
-void fgSkyInit( void ) {
-    printf("Initializing the sky\n");
-
-    fgSkyVerticesInit();
-
-    /* regester fgSkyColorsInit() as an event to be run periodically */
-    fgEventRegister("fgSkyColorsInit()", fgSkyColorsInit, 
-                   FG_EVENT_READY, 30000);
-}
-
-
-/* Draw the Sky */
-void fgSkyRender( void ) {
-    fgFLIGHT *f;
-    struct fgLIGHT *l;
-    struct fgVIEW *v;
-    float /* inner_color[4], middle_color[4], diff, */ east_dot, dot, angle;
-    int i;
-
-    f = current_aircraft.flight;
-    l = &cur_light_params;
-    v = &current_view;
-
-    /* printf("Rendering the sky.\n"); */
-
-    xglPushMatrix();
-
-    /* calculate the angle between v->surface_to_sun and
-     * v->surface_east.  We do this so we can sort out the acos()
-     * ambiguity.  I wish I could think of a more efficient way ... :-( */
-    east_dot = MAT3_DOT_PRODUCT(v->surface_to_sun, v->surface_east);
-    /* printf("  East dot product = %.2f\n", east_dot); */
-
-    /* calculate the angle between v->surface_to_sun and
-     * v->surface_south.  this is how much we have to rotate the sky
-     * for it to align with the sun */
-    dot = MAT3_DOT_PRODUCT(v->surface_to_sun, v->surface_south);
-    /* printf("  Dot product = %.2f\n", dot); */
-    if ( east_dot >= 0 ) {
-       angle = acos(dot);
-    } else {
-       angle = -acos(dot);
-    }
-    /*printf("  Sky needs to rotate = %.3f rads = %.1f degrees.\n", 
-          angle, angle * RAD_TO_DEG); */
-
-    /* Translate to view position */
-    xglTranslatef( v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z );
-    /* printf("  Translated to %.2f %.2f %.2f\n", 
-          v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z ); */
-
-    /* Rotate to proper orientation */
-    /* printf("  lon = %.2f  lat = %.2f\n", FG_Longitude * RAD_TO_DEG,
-          FG_Latitude * RAD_TO_DEG); */
-    xglRotatef( FG_Longitude * RAD_TO_DEG, 0.0, 0.0, 1.0 );
-    xglRotatef( 90.0 - FG_Latitude * RAD_TO_DEG, 0.0, 1.0, 0.0 );
-    xglRotatef( angle * RAD_TO_DEG, 0.0, 0.0, 1.0 );
-
-    /* Draw inner/center section of sky*/
-    xglBegin( GL_TRIANGLE_FAN );
-    xglColor4fv(l->sky_color);
-    xglVertex3f(0.0, 0.0, CENTER_ELEV);
-    for ( i = 0; i < 12; i++ ) {
-       xglColor4fv( inner_color[i] );
-       xglVertex3fv( inner_vertex[i] );
-    }
-    xglColor4fv( inner_color[0] );
-    xglVertex3fv( inner_vertex[0] );
-    xglEnd();
-
-    /* Draw the middle ring */
-    xglBegin( GL_TRIANGLE_STRIP );
-    for ( i = 0; i < 12; i++ ) {
-       xglColor4fv( middle_color[i] );
-       xglVertex3fv( middle_vertex[i] );
-       xglColor4fv( inner_color[i] );
-       xglVertex3fv( inner_vertex[i] );
-    }
-    xglColor4fv( middle_color[0] );
-    /* xglColor4f(1.0, 0.0, 0.0, 1.0); */
-    xglVertex3fv( middle_vertex[0] );
-    xglColor4fv( inner_color[0] );
-    /* xglColor4f(1.0, 0.0, 0.0, 1.0); */
-    xglVertex3fv( inner_vertex[0] );
-    xglEnd();
-
-    /* Draw the outer ring */
-    xglBegin( GL_TRIANGLE_STRIP );
-    for ( i = 0; i < 12; i++ ) {
-       xglColor4fv( outer_color[i] );
-       xglVertex3fv( outer_vertex[i] );
-       xglColor4fv( middle_color[i] );
-       xglVertex3fv( middle_vertex[i] );
-    }
-    xglColor4fv( outer_color[0] );
-    xglVertex3fv( outer_vertex[0] );
-    xglColor4fv( middle_color[0] );
-    xglVertex3fv( middle_vertex[0] );
-    xglEnd();
-
-    /* Draw the bottom skirt */
-    xglBegin( GL_TRIANGLE_STRIP );
-    for ( i = 0; i < 12; i++ ) {
-       xglColor4fv( l->fog_color );
-       xglVertex3fv( bottom_vertex[i] );
-       xglColor4fv( outer_color[i] );
-       xglVertex3fv( outer_vertex[i] );
-    }
-    xglColor4fv( l->fog_color );
-    xglVertex3fv( bottom_vertex[0] );
-    xglColor4fv( outer_color[0] );
-    xglVertex3fv( outer_vertex[0] );
-    xglEnd();
-
-    xglPopMatrix();
-}
-
-
-/* $Log$
-/* Revision 1.9  1998/04/03 21:52:50  curt
-/* Converting to Gnu autoconf system.
-/*
- * Revision 1.8  1998/03/09 22:47:25  curt
- * Incorporated Durk's updates.
- *
- * Revision 1.7  1998/02/19 13:05:49  curt
- * Incorporated some HUD tweaks from Michelle America.
- * Tweaked the sky's sunset/rise colors.
- * Other misc. tweaks.
- *
- * Revision 1.6  1998/02/07 15:29:32  curt
- * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
- * <chotchkiss@namg.us.anritsu.com>
- *
- * Revision 1.5  1998/01/27 00:47:48  curt
- * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
- * system and commandline/config file processing code.
- *
- * Revision 1.4  1998/01/26 15:54:28  curt
- * Added a "skirt" to try to help hide gaps between scenery and sky.  This will
- * have to be revisited in the future.
- *
- * Revision 1.3  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 18:40:17  curt
- * Tons of little changes to clean up the code and to remove fatal errors
- * when building with the c++ compiler.
- *
- * Revision 1.1  1998/01/07 03:16:19  curt
- * Moved from .../Src/Scenery/ to .../Src/Astro/
- *
- * Revision 1.11  1997/12/30 22:22:38  curt
- * Further integration of event manager.
- *
- * Revision 1.10  1997/12/30 20:47:53  curt
- * Integrated new event manager with subsystem initializations.
- *
- * Revision 1.9  1997/12/30 13:06:57  curt
- * A couple lighting tweaks ...
- *
- * Revision 1.8  1997/12/23 04:58:38  curt
- * Tweaked the sky coloring a bit to build in structures to allow finer rgb
- * control.
- *
- * Revision 1.7  1997/12/22 23:45:48  curt
- * First stab at sunset/sunrise sky glow effects.
- *
- * Revision 1.6  1997/12/22 04:14:34  curt
- * Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
- *
- * Revision 1.5  1997/12/19 23:34:59  curt
- * Lot's of tweaking with sky rendering and lighting.
- *
- * Revision 1.4  1997/12/19 16:45:02  curt
- * Working on scene rendering order and options.
- *
- * Revision 1.3  1997/12/18 23:32:36  curt
- * First stab at sky dome actually starting to look reasonable. :-)
- *
- * Revision 1.2  1997/12/18 04:07:03  curt
- * Worked on properly translating and positioning the sky dome.
- *
- * Revision 1.1  1997/12/17 23:14:30  curt
- * Initial revision.
- * Begin work on rendering the sky. (Rather than just using a clear screen.)
- *
- */
diff --git a/Astro/sky.cxx b/Astro/sky.cxx
new file mode 100644 (file)
index 0000000..df6c640
--- /dev/null
@@ -0,0 +1,426 @@
+/**************************************************************************
+ * sky.c -- model sky with an upside down "bowl"
+ *
+ * Written by Curtis Olson, started December 1997.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#include <config.h>
+
+#ifdef HAVE_WINDOWS_H
+#  include <windows.h>
+#endif
+
+#include <math.h>
+
+#include <GL/glut.h>
+#include <XGL/xgl.h>
+
+#include <Aircraft/aircraft.h>
+#include <Flight/flight.h>
+#include <Include/fg_constants.h>
+#include <Main/views.hxx>
+#include <Math/fg_random.h>
+#include <Time/event.h>
+#include <Time/fg_time.h>
+
+#include "sky.hxx"
+
+
+/*
+#include <Include/general.h>
+*/
+
+/* in meters of course */
+#define CENTER_ELEV   25000.0
+
+#define INNER_RADIUS  50000.0
+#define INNER_ELEV    20000.0
+
+#define MIDDLE_RADIUS 70000.0
+#define MIDDLE_ELEV    8000.0
+
+#define OUTER_RADIUS  80000.0
+#define OUTER_ELEV        0.0
+
+#define BOTTOM_RADIUS 50000.0
+#define BOTTOM_ELEV   -2000.0
+
+
+static float inner_vertex[12][3];
+static float middle_vertex[12][3];
+static float outer_vertex[12][3];
+static float bottom_vertex[12][3];
+
+static float inner_color[12][4];
+static float middle_color[12][4];
+static float outer_color[12][4];
+
+
+/* Calculate the sky structure vertices */
+void fgSkyVerticesInit( void ) {
+    float theta;
+    int i;
+
+    printf("  Generating the sky dome vertices.\n");
+
+    for ( i = 0; i < 12; i++ ) {
+       theta = (i * 30.0) * DEG_TO_RAD;
+       
+       inner_vertex[i][0] = cos(theta) * INNER_RADIUS;
+       inner_vertex[i][1] = sin(theta) * INNER_RADIUS;
+       inner_vertex[i][2] = INNER_ELEV;
+       
+       /* printf("    %.2f %.2f\n", cos(theta) * INNER_RADIUS, 
+              sin(theta) * INNER_RADIUS); */
+
+       middle_vertex[i][0] = cos((double)theta) * MIDDLE_RADIUS;
+       middle_vertex[i][1] = sin((double)theta) * MIDDLE_RADIUS;
+       middle_vertex[i][2] = MIDDLE_ELEV;
+           
+       outer_vertex[i][0] = cos((double)theta) * OUTER_RADIUS;
+       outer_vertex[i][1] = sin((double)theta) * OUTER_RADIUS;
+       outer_vertex[i][2] = OUTER_ELEV;
+           
+       bottom_vertex[i][0] = cos((double)theta) * BOTTOM_RADIUS;
+       bottom_vertex[i][1] = sin((double)theta) * BOTTOM_RADIUS;
+       bottom_vertex[i][2] = BOTTOM_ELEV;
+    }
+}
+
+
+/* (Re)calculate the sky colors at each vertex */
+void fgSkyColorsInit( void ) {
+    struct fgLIGHT *l;
+    float sun_angle, diff;
+    float outer_param[3], outer_amt[3], outer_diff[3];
+    float middle_param[3], middle_amt[3], middle_diff[3];
+    int i, j;
+
+    l = &cur_light_params;
+
+    printf("  Generating the sky colors for each vertex.\n");
+
+    /* setup for the possibility of sunset effects */
+    sun_angle = l->sun_angle * RAD_TO_DEG;
+    printf("  Sun angle in degrees = %.2f\n", sun_angle);
+
+    if ( (sun_angle > 80.0) && (sun_angle < 100.0) ) {
+       /* 0.0 - 0.4 */
+       outer_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 25.0;
+       outer_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 35.0;
+       outer_param[2] = 0.0;
+
+       middle_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 20.0;
+       middle_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 40.0;
+       middle_param[2] = 0.0;
+
+       outer_diff[0] = outer_param[0] / 6.0;
+       outer_diff[1] = outer_param[1] / 6.0;
+       outer_diff[2] = outer_param[2] / 6.0;
+
+       middle_diff[0] = middle_param[0] / 6.0;
+       middle_diff[1] = middle_param[1] / 6.0;
+       middle_diff[2] = middle_param[2] / 6.0;
+    } else {
+       outer_param[0] = outer_param[1] = outer_param[2] = 0.0;
+       middle_param[0] = middle_param[1] = middle_param[2] = 0.0;
+
+       outer_diff[0] = outer_diff[1] = outer_diff[2] = 0.0;
+       middle_diff[0] = middle_diff[1] = middle_diff[2] = 0.0;
+    }
+    /* printf("  outer_red_param = %.2f  outer_red_diff = %.2f\n", 
+          outer_red_param, outer_red_diff); */
+
+    /* calculate transition colors between sky and fog */
+    for ( j = 0; j < 3; j++ ) {
+       outer_amt[j] = outer_param[j];
+       middle_amt[j] = middle_param[j];
+    }
+
+    for ( i = 0; i < 6; i++ ) {
+       for ( j = 0; j < 3; j++ ) {
+           diff = l->sky_color[j] - l->fog_color[j];
+
+           inner_color[i][j] = l->sky_color[j] - diff * 0.3;
+           middle_color[i][j] = l->sky_color[j] - diff * 0.9 + middle_amt[j];
+           outer_color[i][j] = l->fog_color[j] + outer_amt[j];
+
+           if ( middle_color[i][j] > 1.00 ) { middle_color[i][j] = 1.00; }
+           if ( middle_color[i][j] < 0.10 ) { middle_color[i][j] = 0.10; }
+           if ( outer_color[i][j] > 1.00 ) { outer_color[i][j] = 1.00; }
+           if ( outer_color[i][j] < 0.10 ) { outer_color[i][j] = 0.10; }
+       }
+       inner_color[i][3] = middle_color[i][3] = outer_color[i][3] = 
+           l->sky_color[3];
+
+       for ( j = 0; j < 3; j++ ) {
+           outer_amt[j] -= outer_diff[j];
+           middle_amt[j] -= middle_diff[j];
+       }
+
+       /*
+       printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i, inner_color[i][0],
+              inner_color[i][1], inner_color[i][2], inner_color[i][3]);
+       printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i, 
+              middle_color[i][0], middle_color[i][1], middle_color[i][2], 
+              middle_color[i][3]);
+       printf("outer_color[%d] = %.2f %.2f %.2f %.2f\n", i, 
+              outer_color[i][0], outer_color[i][1], outer_color[i][2], 
+              outer_color[i][3]);
+       */
+    }
+
+    for ( j = 0; j < 3; j++ ) {
+       outer_amt[j] = 0.0;
+       middle_amt[j] = 0.0;
+    }
+
+    for ( i = 6; i < 12; i++ ) {
+
+       for ( j = 0; j < 3; j++ ) {
+           diff = l->sky_color[j] - l->fog_color[j];
+
+           inner_color[i][j] = l->sky_color[j] - diff * 0.3;
+           middle_color[i][j] = l->sky_color[j] - diff * 0.9 + middle_amt[j];
+           outer_color[i][j] = l->fog_color[j] + outer_amt[j];
+
+           if ( middle_color[i][j] > 1.00 ) { middle_color[i][j] = 1.00; }
+           if ( middle_color[i][j] < 0.10 ) { middle_color[i][j] = 0.10; }
+           if ( outer_color[i][j] > 1.00 ) { outer_color[i][j] = 1.00; }
+           if ( outer_color[i][j] < 0.15 ) { outer_color[i][j] = 0.15; }
+       }
+       inner_color[i][3] = middle_color[i][3] = outer_color[i][3] = 
+           l->sky_color[3];
+
+       for ( j = 0; j < 3; j++ ) {
+           outer_amt[j] += outer_diff[j];
+           middle_amt[j] += middle_diff[j];
+       }
+
+       /*
+       printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i, inner_color[i][0],
+              inner_color[i][1], inner_color[i][2], inner_color[i][3]);
+       printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i, 
+              middle_color[i][0], middle_color[i][1], middle_color[i][2], 
+              middle_color[i][3]);
+       printf("outer_color[%d] = %.2f %.2f %.2f %.2f\n", i, 
+              outer_color[i][0], outer_color[i][1], outer_color[i][2], 
+              outer_color[i][3]);
+       */
+    }
+}
+
+
+/* Initialize the sky structure and colors */
+void fgSkyInit( void ) {
+    printf("Initializing the sky\n");
+
+    fgSkyVerticesInit();
+
+    /* regester fgSkyColorsInit() as an event to be run periodically */
+    fgEventRegister("fgSkyColorsInit()", fgSkyColorsInit, 
+                   FG_EVENT_READY, 30000);
+}
+
+
+/* Draw the Sky */
+void fgSkyRender( void ) {
+    fgFLIGHT *f;
+    struct fgLIGHT *l;
+    struct fgVIEW *v;
+    float /* inner_color[4], middle_color[4], diff, */ east_dot, dot, angle;
+    int i;
+
+    f = current_aircraft.flight;
+    l = &cur_light_params;
+    v = &current_view;
+
+    /* printf("Rendering the sky.\n"); */
+
+    xglPushMatrix();
+
+    /* calculate the angle between v->surface_to_sun and
+     * v->surface_east.  We do this so we can sort out the acos()
+     * ambiguity.  I wish I could think of a more efficient way ... :-( */
+    east_dot = MAT3_DOT_PRODUCT(v->surface_to_sun, v->surface_east);
+    /* printf("  East dot product = %.2f\n", east_dot); */
+
+    /* calculate the angle between v->surface_to_sun and
+     * v->surface_south.  this is how much we have to rotate the sky
+     * for it to align with the sun */
+    dot = MAT3_DOT_PRODUCT(v->surface_to_sun, v->surface_south);
+    /* printf("  Dot product = %.2f\n", dot); */
+    if ( east_dot >= 0 ) {
+       angle = acos(dot);
+    } else {
+       angle = -acos(dot);
+    }
+    /*printf("  Sky needs to rotate = %.3f rads = %.1f degrees.\n", 
+          angle, angle * RAD_TO_DEG); */
+
+    /* Translate to view position */
+    xglTranslatef( v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z );
+    /* printf("  Translated to %.2f %.2f %.2f\n", 
+          v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z ); */
+
+    /* Rotate to proper orientation */
+    /* printf("  lon = %.2f  lat = %.2f\n", FG_Longitude * RAD_TO_DEG,
+          FG_Latitude * RAD_TO_DEG); */
+    xglRotatef( FG_Longitude * RAD_TO_DEG, 0.0, 0.0, 1.0 );
+    xglRotatef( 90.0 - FG_Latitude * RAD_TO_DEG, 0.0, 1.0, 0.0 );
+    xglRotatef( angle * RAD_TO_DEG, 0.0, 0.0, 1.0 );
+
+    /* Draw inner/center section of sky*/
+    xglBegin( GL_TRIANGLE_FAN );
+    xglColor4fv(l->sky_color);
+    xglVertex3f(0.0, 0.0, CENTER_ELEV);
+    for ( i = 0; i < 12; i++ ) {
+       xglColor4fv( inner_color[i] );
+       xglVertex3fv( inner_vertex[i] );
+    }
+    xglColor4fv( inner_color[0] );
+    xglVertex3fv( inner_vertex[0] );
+    xglEnd();
+
+    /* Draw the middle ring */
+    xglBegin( GL_TRIANGLE_STRIP );
+    for ( i = 0; i < 12; i++ ) {
+       xglColor4fv( middle_color[i] );
+       xglVertex3fv( middle_vertex[i] );
+       xglColor4fv( inner_color[i] );
+       xglVertex3fv( inner_vertex[i] );
+    }
+    xglColor4fv( middle_color[0] );
+    /* xglColor4f(1.0, 0.0, 0.0, 1.0); */
+    xglVertex3fv( middle_vertex[0] );
+    xglColor4fv( inner_color[0] );
+    /* xglColor4f(1.0, 0.0, 0.0, 1.0); */
+    xglVertex3fv( inner_vertex[0] );
+    xglEnd();
+
+    /* Draw the outer ring */
+    xglBegin( GL_TRIANGLE_STRIP );
+    for ( i = 0; i < 12; i++ ) {
+       xglColor4fv( outer_color[i] );
+       xglVertex3fv( outer_vertex[i] );
+       xglColor4fv( middle_color[i] );
+       xglVertex3fv( middle_vertex[i] );
+    }
+    xglColor4fv( outer_color[0] );
+    xglVertex3fv( outer_vertex[0] );
+    xglColor4fv( middle_color[0] );
+    xglVertex3fv( middle_vertex[0] );
+    xglEnd();
+
+    /* Draw the bottom skirt */
+    xglBegin( GL_TRIANGLE_STRIP );
+    for ( i = 0; i < 12; i++ ) {
+       xglColor4fv( l->fog_color );
+       xglVertex3fv( bottom_vertex[i] );
+       xglColor4fv( outer_color[i] );
+       xglVertex3fv( outer_vertex[i] );
+    }
+    xglColor4fv( l->fog_color );
+    xglVertex3fv( bottom_vertex[0] );
+    xglColor4fv( outer_color[0] );
+    xglVertex3fv( outer_vertex[0] );
+    xglEnd();
+
+    xglPopMatrix();
+}
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:21:32  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.9  1998/04/03 21:52:50  curt
+ * Converting to Gnu autoconf system.
+ *
+ * Revision 1.8  1998/03/09 22:47:25  curt
+ * Incorporated Durk's updates.
+ *
+ * Revision 1.7  1998/02/19 13:05:49  curt
+ * Incorporated some HUD tweaks from Michelle America.
+ * Tweaked the sky's sunset/rise colors.
+ * Other misc. tweaks.
+ *
+ * Revision 1.6  1998/02/07 15:29:32  curt
+ * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * Revision 1.5  1998/01/27 00:47:48  curt
+ * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
+ * system and commandline/config file processing code.
+ *
+ * Revision 1.4  1998/01/26 15:54:28  curt
+ * Added a "skirt" to try to help hide gaps between scenery and sky.  This will
+ * have to be revisited in the future.
+ *
+ * Revision 1.3  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 18:40:17  curt
+ * Tons of little changes to clean up the code and to remove fatal errors
+ * when building with the c++ compiler.
+ *
+ * Revision 1.1  1998/01/07 03:16:19  curt
+ * Moved from .../Src/Scenery/ to .../Src/Astro/
+ *
+ * Revision 1.11  1997/12/30 22:22:38  curt
+ * Further integration of event manager.
+ *
+ * Revision 1.10  1997/12/30 20:47:53  curt
+ * Integrated new event manager with subsystem initializations.
+ *
+ * Revision 1.9  1997/12/30 13:06:57  curt
+ * A couple lighting tweaks ...
+ *
+ * Revision 1.8  1997/12/23 04:58:38  curt
+ * Tweaked the sky coloring a bit to build in structures to allow finer rgb
+ * control.
+ *
+ * Revision 1.7  1997/12/22 23:45:48  curt
+ * First stab at sunset/sunrise sky glow effects.
+ *
+ * Revision 1.6  1997/12/22 04:14:34  curt
+ * Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
+ *
+ * Revision 1.5  1997/12/19 23:34:59  curt
+ * Lot's of tweaking with sky rendering and lighting.
+ *
+ * Revision 1.4  1997/12/19 16:45:02  curt
+ * Working on scene rendering order and options.
+ *
+ * Revision 1.3  1997/12/18 23:32:36  curt
+ * First stab at sky dome actually starting to look reasonable. :-)
+ *
+ * Revision 1.2  1997/12/18 04:07:03  curt
+ * Worked on properly translating and positioning the sky dome.
+ *
+ * Revision 1.1  1997/12/17 23:14:30  curt
+ * Initial revision.
+ * Begin work on rendering the sky. (Rather than just using a clear screen.)
+ *
+ */
diff --git a/Astro/sky.h b/Astro/sky.h
deleted file mode 100644 (file)
index 0656986..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/**************************************************************************
- * sky.h -- model sky with an upside down "bowl"
- *
- * Written by Curtis Olson, started December 1997.
- *
- * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#ifndef _SKY_H
-#define _SKY_H
-
-
-#ifdef __cplusplus                                                          
-extern "C" {                            
-#endif                                   
-
-
-/* (Re)generate the display list */
-void fgSkyInit( void );
-
-/* (Re)calculate the sky colors at each vertex */
-void fgSkyColorsInit( void );
-
-/* Draw the Sky */
-void fgSkyRender( void );
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _SKY_H */
-
-
-/* $Log$
-/* Revision 1.4  1998/04/21 17:02:32  curt
-/* Prepairing for C++ integration.
-/*
- * Revision 1.3  1998/01/22 02:59:28  curt
- * Changed #ifdef FILE_H to #ifdef _FILE_H
- *
- * Revision 1.2  1998/01/19 18:40:17  curt
- * Tons of little changes to clean up the code and to remove fatal errors
- * when building with the c++ compiler.
- *
- * Revision 1.1  1998/01/07 03:16:19  curt
- * Moved from .../Src/Scenery/ to .../Src/Astro/
- *
- * Revision 1.2  1997/12/22 23:45:49  curt
- * First stab at sunset/sunrise sky glow effects.
- *
- * Revision 1.1  1997/12/17 23:14:31  curt
- * Initial revision.
- * Begin work on rendering the sky. (Rather than just using a clear screen.)
- *
- */
diff --git a/Astro/sky.hxx b/Astro/sky.hxx
new file mode 100644 (file)
index 0000000..3b8e463
--- /dev/null
@@ -0,0 +1,73 @@
+/**************************************************************************
+ * sky.hxx -- model sky with an upside down "bowl"
+ *
+ * Written by Curtis Olson, started December 1997.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#ifndef _SKY_HXX
+#define _SKY_HXX
+
+
+#ifndef __cplusplus                                                          
+# error This library requires C++
+#endif                                   
+
+
+/* (Re)generate the display list */
+void fgSkyInit( void );
+
+/* (Re)calculate the sky colors at each vertex */
+void fgSkyColorsInit( void );
+
+/* Draw the Sky */
+void fgSkyRender( void );
+
+
+#endif /* _SKY_HXX */
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:21:33  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.4  1998/04/21 17:02:32  curt
+ * Prepairing for C++ integration.
+ *
+ * Revision 1.3  1998/01/22 02:59:28  curt
+ * Changed #ifdef FILE_H to #ifdef _FILE_H
+ *
+ * Revision 1.2  1998/01/19 18:40:17  curt
+ * Tons of little changes to clean up the code and to remove fatal errors
+ * when building with the c++ compiler.
+ *
+ * Revision 1.1  1998/01/07 03:16:19  curt
+ * Moved from .../Src/Scenery/ to .../Src/Astro/
+ *
+ * Revision 1.2  1997/12/22 23:45:49  curt
+ * First stab at sunset/sunrise sky glow effects.
+ *
+ * Revision 1.1  1997/12/17 23:14:31  curt
+ * Initial revision.
+ * Begin work on rendering the sky. (Rather than just using a clear screen.)
+ *
+ */
diff --git a/Astro/stars.c b/Astro/stars.c
deleted file mode 100644 (file)
index a71f30e..0000000
+++ /dev/null
@@ -1,372 +0,0 @@
-/**************************************************************************
- * stars.c -- data structures and routines for managing and rendering stars.
- *
- * Written by Curtis Olson, started August 1997.
- *
- * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#include <config.h>
-
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#endif
-
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-
-#include <Astro/orbits.h>
-#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 <Main/views.h>
-#include <Time/fg_time.h>
-
-#define EpochStart           (631065600)
-#define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
-
-
-/* Define four structures, each with varying amounts of stars */
-/* static */  GLint stars[FG_STAR_LEVELS];
-
-
-/* Initialize the Star Management Subsystem */
-int fgStarsInit( void ) {
-    FILE *fd;
-    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;
-
-    fgPrintf( FG_ASTRO, FG_INFO, "Initializing stars\n");
-
-    g = &general;
-
-    /* build the full path name to the stars data base file */
-    path[0] = '\0';
-    strcat(path, g->root_dir);
-    strcat(path, "/Scenery/");
-    strcat(path, "Stars.dat");
-
-    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);
-
-       if ( (fd = fopen(path, "r")) == NULL ) {
-           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 );
-
-       /* read in each line of the file */
-       count = 0;
-       while ( (fgets(line, 256, fd) != NULL) && (count < max_stars) ) {
-           front = line;
-
-           /* printf("  Read line = %s", front); */
-
-           /* advance to first non-whitespace character */
-           while ( (front[0] == ' ') || (front[0] == '\t') ) {
-               front++;
-           }
-
-           /* printf("  Line length (after trimming) = %d\n", strlen(front));*/
-
-           if ( front[0] == '#' ) {
-               /* comment */
-           } else if ( strlen(front) <= 1 ) {
-               /* blank line */
-           } else {
-               /* star data line */
-
-               /* get name */
-               end = front;
-               while ( end[0] != ',' ) {
-                   end++;
-               }
-               end[0] = '\0';
-               strcpy(name, front);
-               front = end;
-               front++;
-
-               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, "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;
-
-               /* 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);
-               /* printf("  Found star: %d %s, %.3f %.3f %.3f\n", count,
-                  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++;
-           } //  valid line
-
-       } /* while */
-
-       fclose(fd);
-
-       xglEnd();
-
-       /*
-       xglBegin(GL_LINE_LOOP);
-        xglColor3f(1.0, 0.0, 0.0);
-       xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
-                   50000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
-                   50000.0 * sin(decl_save-0.2) );
-       xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save-0.2),
-                   50000.0 * sin(ra_save+0.2) * cos(decl_save-0.2),
-                   50000.0 * sin(decl_save-0.2) );
-       xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save+0.2),
-                   50000.0 * sin(ra_save+0.2) * cos(decl_save+0.2),
-                   50000.0 * sin(decl_save+0.2) );
-       xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
-                   50000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
-                   50000.0 * sin(decl_save+0.2) );
-       xglEnd();
-       */
-
-       /*
-       xglBegin(GL_LINE_LOOP);
-        xglColor3f(0.0, 1.0, 0.0);
-       xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
-                   50000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
-                   50000.0 * sin(decl_save1-0.2) );
-       xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1-0.2),
-                   50000.0 * sin(ra_save1+0.2) * cos(decl_save1-0.2),
-                   50000.0 * sin(decl_save1-0.2) );
-       xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1+0.2),
-                   50000.0 * sin(ra_save1+0.2) * cos(decl_save1+0.2),
-                   50000.0 * sin(decl_save1+0.2) );
-       xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
-                   50000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
-                   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 ) {
-    fgFLIGHT *f;
-    struct fgVIEW *v;
-    struct fgLIGHT *l;
-    struct fgTIME *t;
-    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 */
-
-    /* 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 ( l->sun_angle > (FG_PI_2 + 7.25 * DEG_TO_RAD ) ) {
-           i = 0;
-       } else if ( l->sun_angle > (FG_PI_2 + 6.50 * DEG_TO_RAD ) ) {
-           i = 1;
-       } else if ( l->sun_angle > (FG_PI_2 + 5.75 * DEG_TO_RAD ) ) {
-           i = 2;
-       } else {
-           i = 3;
-       }
-
-       /* printf("RENDERING STARS = %d (night)\n", i); */
-
-       xglCallList(stars[i]);
-    } else {
-       /* printf("not RENDERING STARS (day)\n"); */
-    }
-}
-
-
-/* $Log$
-/* 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.
- *
- * Revision 1.3  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 18:40:18  curt
- * Tons of little changes to clean up the code and to remove fatal errors
- * when building with the c++ compiler.
- *
- * Revision 1.1  1998/01/07 03:16:20  curt
- * Moved from .../Src/Scenery/ to .../Src/Astro/
- *
- * Revision 1.24  1997/12/30 22:22:39  curt
- * Further integration of event manager.
- *
- * Revision 1.23  1997/12/30 20:47:53  curt
- * Integrated new event manager with subsystem initializations.
- *
- * Revision 1.22  1997/12/30 16:36:53  curt
- * Merged in Durk's changes ...
- *
- * Revision 1.21  1997/12/19 23:35:00  curt
- * Lot's of tweaking with sky rendering and lighting.
- *
- * 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.
- *
- * Revision 1.8  1997/09/16 22:14:52  curt
- * Tweaked time of day lighting equations.  Don't draw stars during the day.
- *
- * Revision 1.7  1997/09/16 15:50:31  curt
- * Working on star alignment and time issues.
- *
- * Revision 1.6  1997/09/05 14:17:31  curt
- * More tweaking with stars.
- *
- * Revision 1.5  1997/09/05 01:35:59  curt
- * Working on getting stars right.
- *
- * Revision 1.4  1997/09/04 02:17:38  curt
- * Shufflin' stuff.
- *
- * Revision 1.3  1997/08/29 17:55:28  curt
- * Worked on properly aligning the stars.
- *
- * Revision 1.2  1997/08/27 21:32:30  curt
- * Restructured view calculation code.  Added stars.
- *
- * Revision 1.1  1997/08/27 03:34:48  curt
- * Initial revision.
- *
- */
diff --git a/Astro/stars.cxx b/Astro/stars.cxx
new file mode 100644 (file)
index 0000000..d163923
--- /dev/null
@@ -0,0 +1,376 @@
+/**************************************************************************
+ * stars.c -- data structures and routines for managing and rendering stars.
+ *
+ * Written by Curtis Olson, started August 1997.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#include <config.h>
+
+#ifdef HAVE_WINDOWS_H
+#  include <windows.h>
+#endif
+
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#include <GL/glut.h>
+#include <XGL/xgl.h>
+
+#include <Aircraft/aircraft.h>
+#include <Debug/fg_debug.h>
+#include <Include/fg_constants.h>
+#include <Include/general.h>
+#include <Main/views.hxx>
+#include <Time/fg_time.h>
+
+#include "orbits.hxx"
+#include "planets.hxx"
+#include "stars.hxx"
+
+
+#define EpochStart           (631065600)
+#define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
+
+
+/* Define four structures, each with varying amounts of stars */
+/* static */  GLint stars[FG_STAR_LEVELS];
+
+
+/* Initialize the Star Management Subsystem */
+int fgStarsInit( void ) {
+    FILE *fd;
+    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;
+
+    fgPrintf( FG_ASTRO, FG_INFO, "Initializing stars\n");
+
+    g = &general;
+
+    /* build the full path name to the stars data base file */
+    path[0] = '\0';
+    strcat(path, g->root_dir);
+    strcat(path, "/Scenery/");
+    strcat(path, "Stars.dat");
+
+    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);
+
+       if ( (fd = fopen(path, "r")) == NULL ) {
+           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 );
+
+       /* read in each line of the file */
+       count = 0;
+       while ( (fgets(line, 256, fd) != NULL) && (count < max_stars) ) {
+           front = line;
+
+           /* printf("  Read line = %s", front); */
+
+           /* advance to first non-whitespace character */
+           while ( (front[0] == ' ') || (front[0] == '\t') ) {
+               front++;
+           }
+
+           /* printf("  Line length (after trimming) = %d\n", strlen(front));*/
+
+           if ( front[0] == '#' ) {
+               /* comment */
+           } else if ( strlen(front) <= 1 ) {
+               /* blank line */
+           } else {
+               /* star data line */
+
+               /* get name */
+               end = front;
+               while ( end[0] != ',' ) {
+                   end++;
+               }
+               end[0] = '\0';
+               strcpy(name, front);
+               front = end;
+               front++;
+
+               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, "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;
+
+               /* 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);
+               /* printf("  Found star: %d %s, %.3f %.3f %.3f\n", count,
+                  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++;
+           } //  valid line
+
+       } /* while */
+
+       fclose(fd);
+
+       xglEnd();
+
+       /*
+       xglBegin(GL_LINE_LOOP);
+        xglColor3f(1.0, 0.0, 0.0);
+       xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
+                   50000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
+                   50000.0 * sin(decl_save-0.2) );
+       xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save-0.2),
+                   50000.0 * sin(ra_save+0.2) * cos(decl_save-0.2),
+                   50000.0 * sin(decl_save-0.2) );
+       xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save+0.2),
+                   50000.0 * sin(ra_save+0.2) * cos(decl_save+0.2),
+                   50000.0 * sin(decl_save+0.2) );
+       xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
+                   50000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
+                   50000.0 * sin(decl_save+0.2) );
+       xglEnd();
+       */
+
+       /*
+       xglBegin(GL_LINE_LOOP);
+        xglColor3f(0.0, 1.0, 0.0);
+       xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
+                   50000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
+                   50000.0 * sin(decl_save1-0.2) );
+       xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1-0.2),
+                   50000.0 * sin(ra_save1+0.2) * cos(decl_save1-0.2),
+                   50000.0 * sin(decl_save1-0.2) );
+       xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1+0.2),
+                   50000.0 * sin(ra_save1+0.2) * cos(decl_save1+0.2),
+                   50000.0 * sin(decl_save1+0.2) );
+       xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
+                   50000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
+                   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 ) {
+    fgFLIGHT *f;
+    struct fgVIEW *v;
+    struct fgLIGHT *l;
+    struct fgTIME *t;
+    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 */
+
+    /* 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 ( l->sun_angle > (FG_PI_2 + 7.25 * DEG_TO_RAD ) ) {
+           i = 0;
+       } else if ( l->sun_angle > (FG_PI_2 + 6.50 * DEG_TO_RAD ) ) {
+           i = 1;
+       } else if ( l->sun_angle > (FG_PI_2 + 5.75 * DEG_TO_RAD ) ) {
+           i = 2;
+       } else {
+           i = 3;
+       }
+
+       /* printf("RENDERING STARS = %d (night)\n", i); */
+
+       xglCallList(stars[i]);
+    } else {
+       /* printf("not RENDERING STARS (day)\n"); */
+    }
+}
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:21:34  curt
+/* C++ - ifing the code a bit.
+/*
+ * 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.
+ *
+ * Revision 1.3  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 18:40:18  curt
+ * Tons of little changes to clean up the code and to remove fatal errors
+ * when building with the c++ compiler.
+ *
+ * Revision 1.1  1998/01/07 03:16:20  curt
+ * Moved from .../Src/Scenery/ to .../Src/Astro/
+ *
+ * Revision 1.24  1997/12/30 22:22:39  curt
+ * Further integration of event manager.
+ *
+ * Revision 1.23  1997/12/30 20:47:53  curt
+ * Integrated new event manager with subsystem initializations.
+ *
+ * Revision 1.22  1997/12/30 16:36:53  curt
+ * Merged in Durk's changes ...
+ *
+ * Revision 1.21  1997/12/19 23:35:00  curt
+ * Lot's of tweaking with sky rendering and lighting.
+ *
+ * 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.
+ *
+ * Revision 1.8  1997/09/16 22:14:52  curt
+ * Tweaked time of day lighting equations.  Don't draw stars during the day.
+ *
+ * Revision 1.7  1997/09/16 15:50:31  curt
+ * Working on star alignment and time issues.
+ *
+ * Revision 1.6  1997/09/05 14:17:31  curt
+ * More tweaking with stars.
+ *
+ * Revision 1.5  1997/09/05 01:35:59  curt
+ * Working on getting stars right.
+ *
+ * Revision 1.4  1997/09/04 02:17:38  curt
+ * Shufflin' stuff.
+ *
+ * Revision 1.3  1997/08/29 17:55:28  curt
+ * Worked on properly aligning the stars.
+ *
+ * Revision 1.2  1997/08/27 21:32:30  curt
+ * Restructured view calculation code.  Added stars.
+ *
+ * Revision 1.1  1997/08/27 03:34:48  curt
+ * Initial revision.
+ *
+ */
diff --git a/Astro/stars.h b/Astro/stars.h
deleted file mode 100644 (file)
index c4247ab..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/**************************************************************************
- * stars.h -- data structures and routines for managing and rendering stars.
- *
- * Written by Curtis Olson, started August 1997.
- *
- * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#ifndef _STARS_H
-#define _STARS_H
-
-
-#ifdef __cplusplus                                                          
-extern "C" {                            
-#endif                                   
-
-
-#define FG_MAX_STARS 500
-#define FG_STAR_LEVELS 4         /* how many star transitions */
-#define FG_MIN_STAR_MAG 0.738750 /* magnitude of weakest star we'll display */
-
-/* Initialize the Star Management Subsystem */
-int fgStarsInit( void );
-
-/* Draw the Stars */
-void fgStarsRender( void );
-extern struct OrbElements pltOrbElements[9];
-extern struct fgTIME cur_time_params;
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _STARS_H */
-
-
-/* $Log$
-/* Revision 1.5  1998/04/21 17:02:33  curt
-/* Prepairing for C++ integration.
-/*
- * Revision 1.4  1998/02/12 21:59:39  curt
- * Incorporated code changes contributed by Charlie Hotchkiss
- * <chotchkiss@namg.us.anritsu.com>
- *
- * Revision 1.3  1998/01/22 02:59:28  curt
- * Changed #ifdef FILE_H to #ifdef _FILE_H
- *
- * Revision 1.2  1998/01/19 18:40:18  curt
- * Tons of little changes to clean up the code and to remove fatal errors
- * when building with the c++ compiler.
- *
- * Revision 1.1  1998/01/07 03:16:20  curt
- * Moved from .../Src/Scenery/ to .../Src/Astro/
- *
- * Revision 1.6  1997/10/25 03:18:29  curt
- * Incorporated sun, moon, and planet position and rendering code contributed
- * by Durk Talsma.
- *
- * Revision 1.5  1997/09/18 16:20:09  curt
- * At dusk/dawn add/remove stars in stages.
- *
- * Revision 1.4  1997/09/05 01:36:00  curt
- * Working on getting stars right.
- *
- * Revision 1.3  1997/08/29 17:55:28  curt
- * Worked on properly aligning the stars.
- *
- * Revision 1.2  1997/08/27 21:32:30  curt
- * Restructured view calculation code.  Added stars.
- *
- * Revision 1.1  1997/08/27 03:34:50  curt
- * Initial revision.
- *
- */
diff --git a/Astro/stars.hxx b/Astro/stars.hxx
new file mode 100644 (file)
index 0000000..e38d8f0
--- /dev/null
@@ -0,0 +1,92 @@
+/**************************************************************************
+ * stars.hxx -- data structures and routines for managing and rendering stars.
+ *
+ * Written by Curtis Olson, started August 1997.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#ifndef _STARS_HXX
+#define _STARS_HXX
+
+
+#ifndef __cplusplus                                                          
+# error This library requires C++
+#endif                                   
+
+
+#define FG_MAX_STARS 500
+#define FG_STAR_LEVELS 4         /* how many star transitions */
+#define FG_MIN_STAR_MAG 0.738750 /* magnitude of weakest star we'll display */
+
+/* Initialize the Star Management Subsystem */
+int fgStarsInit( void );
+
+/* Draw the Stars */
+void fgStarsRender( void );
+extern struct OrbElements pltOrbElements[9];
+extern struct fgTIME cur_time_params;
+
+
+#endif /* _STARS_HXX */
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:21:35  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.5  1998/04/21 17:02:33  curt
+ * Prepairing for C++ integration.
+ *
+ * Revision 1.4  1998/02/12 21:59:39  curt
+ * Incorporated code changes contributed by Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * Revision 1.3  1998/01/22 02:59:28  curt
+ * Changed #ifdef FILE_H to #ifdef _FILE_H
+ *
+ * Revision 1.2  1998/01/19 18:40:18  curt
+ * Tons of little changes to clean up the code and to remove fatal errors
+ * when building with the c++ compiler.
+ *
+ * Revision 1.1  1998/01/07 03:16:20  curt
+ * Moved from .../Src/Scenery/ to .../Src/Astro/
+ *
+ * Revision 1.6  1997/10/25 03:18:29  curt
+ * Incorporated sun, moon, and planet position and rendering code contributed
+ * by Durk Talsma.
+ *
+ * Revision 1.5  1997/09/18 16:20:09  curt
+ * At dusk/dawn add/remove stars in stages.
+ *
+ * Revision 1.4  1997/09/05 01:36:00  curt
+ * Working on getting stars right.
+ *
+ * Revision 1.3  1997/08/29 17:55:28  curt
+ * Worked on properly aligning the stars.
+ *
+ * Revision 1.2  1997/08/27 21:32:30  curt
+ * Restructured view calculation code.  Added stars.
+ *
+ * Revision 1.1  1997/08/27 03:34:50  curt
+ * Initial revision.
+ *
+ */
diff --git a/Astro/sun.c b/Astro/sun.c
deleted file mode 100644 (file)
index 645a7d6..0000000
+++ /dev/null
@@ -1,271 +0,0 @@
-/**************************************************************************
- * sun.c
- *
- * Written 1997 by Durk Talsma, started October, 1997.  For the flight gear
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#include <config.h>
-#ifdef HAVE_WINDOWS_H                                           
-#  include <windows.h>                                           
-#endif                                                               
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-
-#include <Astro/orbits.h>
-#include <Astro/sun.h>
-#include <Debug/fg_debug.h>
-#include <Include/fg_constants.h>
-#include <Main/views.h>
-#include <Time/fg_time.h>
-#include <Time/sunpos.h>
-
-GLint sun_obj = 0;
-
-static struct CelestialCoord sunPos;
-
-fgSUNPOS solarPosition;
-
-void fgCalcSunPos(struct OrbElements params)
-{
-    double EccAnom, xv, yv, v, r;
-
-    /* calculate the eccentric anomaly */
-    EccAnom = fgCalcEccAnom(params.M, params.e);
-
-    /* calculate the Suns distance (r) and its true anomaly (v) */
-    xv = cos(EccAnom) - params.e;
-    yv = sqrt(1.0 - params.e*params.e) * sin(EccAnom);
-    v = atan2(yv, xv);
-    r = sqrt(xv*xv + yv*yv);
-
-    /* calculate the the Sun's true longitude (lonsun) */
-    solarPosition.lonSun = v + params.w;
-
-    /* convert true longitude and distance to ecliptic rectangular
-      geocentric coordinates (xs, ys) */
-    solarPosition.xs = r * cos (solarPosition.lonSun);
-    solarPosition.ys = r * sin (solarPosition.lonSun);
-    solarPosition.dist = r;
-    /* return solarPosition; */
-}
-
-
-struct CelestialCoord fgCalculateSun (struct OrbElements params, 
-                                     struct fgTIME t)
-{
-    struct CelestialCoord result;
-    double xe, ye, ze, ecl, actTime;
-
-    /* calculate the angle between ecliptic and equatorial coordinate
-     * system */
-    actTime = fgCalcActTime (t);
-    ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime); // Angle now in Rads
-
-    /* calculate the sun's ecliptic position */
-    fgCalcSunPos (params);
-
-    /* convert ecliptic coordinates to equatorial rectangular
-     * geocentric coordinates */
-    xe = solarPosition.xs;
-    ye = solarPosition.ys * cos (ecl);
-    ze = solarPosition.ys * sin (ecl);
-
-    /* and finally... Calulate Right Ascention and Declination */
-    result.RightAscension = atan2 (ye, xe);
-    result.Declination = atan2 (ze, sqrt (xe * xe + ye * ye));
-    return result;
-}
-
-
-/* Initialize the Sun */
-void fgSunInit( void ) {
-    struct fgLIGHT *l;
-    struct fgTIME *t;
-    struct fgVIEW *v;  
-    float xSun, ySun, zSun;
-
-    /* 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");
-
-    // Calculate basic sun position
-    fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params);
-    sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params);
-
-    // Calculate additional sun position parameters based on the above
-    // position that are needed by other parts of FG
-    fgUpdateSunPos();
-
-    fgPrintf( FG_ASTRO, FG_INFO,
-             "Sun found at %f (ra), %f (dec)\n",
-             sunPos.RightAscension, 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 (sun_obj) {
-       xglDeleteLists(sun_obj, 1);
-    }
-
-    /* printf("First time through, creating sun display list\n"); */
-
-    sun_obj = xglGenLists(1);
-    xglNewList(sun_obj, GL_COMPILE );
-
-
-    t = &cur_time_params;
-    v = &current_view;
-    l = &cur_light_params;
-
-    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;
-
-    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.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);
-
-    xglPushMatrix();
-    xglTranslatef(xSun, ySun, zSun);
-    xglScalef(1400, 1400, 1400);
-    xglColor3f(amb[0], amb[1], amb[2]); 
-    glutSolidSphere(1.0, 10, 10);
-    xglPopMatrix();
-    xglEndList();
-}
-
-
-/* Draw the Sun */
-void fgSunRender( void ) {
-    xglCallList(sun_obj);
-}
-
-
-/* $Log$
-/* Revision 1.10  1998/04/18 04:13:58  curt
-/* Moved fg_debug.c to it's own library.
-/*
- * Revision 1.9  1998/04/03 21:52:51  curt
- * Converting to Gnu autoconf system.
- *
- * Revision 1.8  1998/03/09 22:47:25  curt
- * Incorporated Durk's updates.
- *
- * Revision 1.7  1998/02/23 19:07:56  curt
- * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
- * calculation code between sun display, and other FG sections that use this
- * for things like lighting.
- *
- * Revision 1.6  1998/02/12 21:59:39  curt
- * Incorporated code changes contributed by Charlie Hotchkiss
- * <chotchkiss@namg.us.anritsu.com>
- *
- * 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.2  1998/01/19 18:40:18  curt
- * Tons of little changes to clean up the code and to remove fatal errors
- * when building with the c++ compiler.
- *
- * Revision 1.1  1998/01/07 03:16:20  curt
- * Moved from .../Src/Scenery/ to .../Src/Astro/
- *
- * Revision 1.12  1998/01/05 18:44:36  curt
- * Add an option to advance/decrease time from keyboard.
- *
- * Revision 1.11  1997/12/30 23:09:40  curt
- * Worked on winding problem without luck, so back to calling glFrontFace()
- * 3 times for each scenery area.
- *
- * 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 {}"
- *
- * Revision 1.3  1997/12/09 05:11:56  curt
- * Working on tweaking lighting.
- *
- * Revision 1.2  1997/11/25 19:25:39  curt
- * Changes to integrate Durk's moon/sun code updates + clean up.
- *
- * Revision 1.1  1997/10/25 03:16:11  curt
- * Initial revision of code contributed by Durk Talsma.
- *
- */
-
-
-
-
-
diff --git a/Astro/sun.cxx b/Astro/sun.cxx
new file mode 100644 (file)
index 0000000..039953d
--- /dev/null
@@ -0,0 +1,276 @@
+/**************************************************************************
+ * sun.c
+ *
+ * Written 1997 by Durk Talsma, started October, 1997.  For the flight gear
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#include <config.h>
+#ifdef HAVE_WINDOWS_H                                           
+#  include <windows.h>                                           
+#endif                                                               
+#include <GL/glut.h>
+#include <XGL/xgl.h>
+
+#include <Debug/fg_debug.h>
+#include <Include/fg_constants.h>
+#include <Main/views.hxx>
+#include <Time/fg_time.h>
+#include <Time/sunpos.hxx>
+
+#include "orbits.hxx"
+#include "sun.hxx"
+
+
+GLint sun_obj = 0;
+
+static struct CelestialCoord sunPos;
+
+fgSUNPOS solarPosition;
+
+void fgCalcSunPos(struct OrbElements params)
+{
+    double EccAnom, xv, yv, v, r;
+
+    /* calculate the eccentric anomaly */
+    EccAnom = fgCalcEccAnom(params.M, params.e);
+
+    /* calculate the Suns distance (r) and its true anomaly (v) */
+    xv = cos(EccAnom) - params.e;
+    yv = sqrt(1.0 - params.e*params.e) * sin(EccAnom);
+    v = atan2(yv, xv);
+    r = sqrt(xv*xv + yv*yv);
+
+    /* calculate the the Sun's true longitude (lonsun) */
+    solarPosition.lonSun = v + params.w;
+
+    /* convert true longitude and distance to ecliptic rectangular
+      geocentric coordinates (xs, ys) */
+    solarPosition.xs = r * cos (solarPosition.lonSun);
+    solarPosition.ys = r * sin (solarPosition.lonSun);
+    solarPosition.dist = r;
+    /* return solarPosition; */
+}
+
+
+struct CelestialCoord fgCalculateSun (struct OrbElements params, 
+                                     struct fgTIME t)
+{
+    struct CelestialCoord result;
+    double xe, ye, ze, ecl, actTime;
+
+    /* calculate the angle between ecliptic and equatorial coordinate
+     * system */
+    actTime = fgCalcActTime (t);
+    ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime); // Angle now in Rads
+
+    /* calculate the sun's ecliptic position */
+    fgCalcSunPos (params);
+
+    /* convert ecliptic coordinates to equatorial rectangular
+     * geocentric coordinates */
+    xe = solarPosition.xs;
+    ye = solarPosition.ys * cos (ecl);
+    ze = solarPosition.ys * sin (ecl);
+
+    /* and finally... Calulate Right Ascention and Declination */
+    result.RightAscension = atan2 (ye, xe);
+    result.Declination = atan2 (ze, sqrt (xe * xe + ye * ye));
+    return result;
+}
+
+
+/* Initialize the Sun */
+void fgSunInit( void ) {
+    struct fgLIGHT *l;
+    struct fgTIME *t;
+    struct fgVIEW *v;  
+    float xSun, ySun, zSun;
+
+    /* 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");
+
+    // Calculate basic sun position
+    fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params);
+    sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params);
+
+    // Calculate additional sun position parameters based on the above
+    // position that are needed by other parts of FG
+    fgUpdateSunPos();
+
+    fgPrintf( FG_ASTRO, FG_INFO,
+             "Sun found at %f (ra), %f (dec)\n",
+             sunPos.RightAscension, 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 (sun_obj) {
+       xglDeleteLists(sun_obj, 1);
+    }
+
+    /* printf("First time through, creating sun display list\n"); */
+
+    sun_obj = xglGenLists(1);
+    xglNewList(sun_obj, GL_COMPILE );
+
+
+    t = &cur_time_params;
+    v = &current_view;
+    l = &cur_light_params;
+
+    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;
+
+    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.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);
+
+    xglPushMatrix();
+    xglTranslatef(xSun, ySun, zSun);
+    xglScalef(1400, 1400, 1400);
+    xglColor3f(amb[0], amb[1], amb[2]); 
+    glutSolidSphere(1.0, 10, 10);
+    xglPopMatrix();
+    xglEndList();
+}
+
+
+/* Draw the Sun */
+void fgSunRender( void ) {
+    xglCallList(sun_obj);
+}
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:21:36  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.10  1998/04/18 04:13:58  curt
+ * Moved fg_debug.c to it's own library.
+ *
+ * Revision 1.9  1998/04/03 21:52:51  curt
+ * Converting to Gnu autoconf system.
+ *
+ * Revision 1.8  1998/03/09 22:47:25  curt
+ * Incorporated Durk's updates.
+ *
+ * Revision 1.7  1998/02/23 19:07:56  curt
+ * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
+ * calculation code between sun display, and other FG sections that use this
+ * for things like lighting.
+ *
+ * Revision 1.6  1998/02/12 21:59:39  curt
+ * Incorporated code changes contributed by Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * 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.2  1998/01/19 18:40:18  curt
+ * Tons of little changes to clean up the code and to remove fatal errors
+ * when building with the c++ compiler.
+ *
+ * Revision 1.1  1998/01/07 03:16:20  curt
+ * Moved from .../Src/Scenery/ to .../Src/Astro/
+ *
+ * Revision 1.12  1998/01/05 18:44:36  curt
+ * Add an option to advance/decrease time from keyboard.
+ *
+ * Revision 1.11  1997/12/30 23:09:40  curt
+ * Worked on winding problem without luck, so back to calling glFrontFace()
+ * 3 times for each scenery area.
+ *
+ * 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 {}"
+ *
+ * Revision 1.3  1997/12/09 05:11:56  curt
+ * Working on tweaking lighting.
+ *
+ * Revision 1.2  1997/11/25 19:25:39  curt
+ * Changes to integrate Durk's moon/sun code updates + clean up.
+ *
+ * Revision 1.1  1997/10/25 03:16:11  curt
+ * Initial revision of code contributed by Durk Talsma.
+ *
+ */
+
+
+
+
+
diff --git a/Astro/sun.h b/Astro/sun.h
deleted file mode 100644 (file)
index b9f6f0b..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/**************************************************************************
- * sun.h
- *
- * Written 1997 by Durk Talsma, started October, 1997.  For the flight gear
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#ifndef _SUN_H
-#define _SUN_H
-
-
-#ifdef __cplusplus                                                          
-extern "C" {                            
-#endif                                   
-
-
-extern fgSUNPOS solarPosition;
-
-
-void fgCalcSunPos (struct OrbElements sunParams);
-extern struct OrbElements pltOrbElements[9];
-
-/* Initialize the Sun */
-void fgSunInit( void );
-
-/* Draw the Sun */
-void fgSunRender( void );
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _SUN_H */
-
-
-/* $Log$
-/* Revision 1.6  1998/04/21 17:02:33  curt
-/* Prepairing for C++ integration.
-/*
- * Revision 1.5  1998/03/09 22:47:26  curt
- * Incorporated Durk's updates.
- *
- * Revision 1.4  1998/02/23 19:07:57  curt
- * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
- * calculation code between sun display, and other FG sections that use this
- * for things like lighting.
- *
- * Revision 1.3  1998/01/22 02:59:29  curt
- * Changed #ifdef FILE_H to #ifdef _FILE_H
- *
- * Revision 1.2  1998/01/19 18:40:19  curt
- * Tons of little changes to clean up the code and to remove fatal errors
- * when building with the c++ compiler.
- *
- * Revision 1.1  1998/01/07 03:16:21  curt
- * Moved from .../Src/Scenery/ to .../Src/Astro/
- *
- * Revision 1.3  1997/12/11 04:43:56  curt
- * Fixed sun vector and lighting problems.  I thing the moon is now lit
- * correctly.
- *
- * Revision 1.2  1997/11/25 19:25:39  curt
- * Changes to integrate Durk's moon/sun code updates + clean up.
- *
- * Revision 1.1  1997/10/25 03:16:12  curt
- * Initial revision of code contributed by Durk Talsma.
- *
- */
diff --git a/Astro/sun.hxx b/Astro/sun.hxx
new file mode 100644 (file)
index 0000000..6a6f3ba
--- /dev/null
@@ -0,0 +1,88 @@
+/**************************************************************************
+ * sun.hxx
+ *
+ * Written 1997 by Durk Talsma, started October, 1997.  For the flight gear
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#ifndef _SUN_HXX
+#define _SUN_HXX
+
+
+#ifndef __cplusplus                                                          
+# error This library requires C++
+#endif                                   
+
+
+extern fgSUNPOS solarPosition;
+
+
+void fgCalcSunPos (struct OrbElements sunParams);
+extern struct OrbElements pltOrbElements[9];
+
+
+/* Initialize the Sun */
+void fgSunInit( void );
+
+
+/* Draw the Sun */
+void fgSunRender( void );
+
+
+#endif /* _SUN_HXX */
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:21:37  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.6  1998/04/21 17:02:33  curt
+ * Prepairing for C++ integration.
+ *
+ * Revision 1.5  1998/03/09 22:47:26  curt
+ * Incorporated Durk's updates.
+ *
+ * Revision 1.4  1998/02/23 19:07:57  curt
+ * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
+ * calculation code between sun display, and other FG sections that use this
+ * for things like lighting.
+ *
+ * Revision 1.3  1998/01/22 02:59:29  curt
+ * Changed #ifdef FILE_H to #ifdef _FILE_H
+ *
+ * Revision 1.2  1998/01/19 18:40:19  curt
+ * Tons of little changes to clean up the code and to remove fatal errors
+ * when building with the c++ compiler.
+ *
+ * Revision 1.1  1998/01/07 03:16:21  curt
+ * Moved from .../Src/Scenery/ to .../Src/Astro/
+ *
+ * Revision 1.3  1997/12/11 04:43:56  curt
+ * Fixed sun vector and lighting problems.  I thing the moon is now lit
+ * correctly.
+ *
+ * Revision 1.2  1997/11/25 19:25:39  curt
+ * Changes to integrate Durk's moon/sun code updates + clean up.
+ *
+ * Revision 1.1  1997/10/25 03:16:12  curt
+ * Initial revision of code contributed by Durk Talsma.
+ *
+ */
index b54572ee407447d41ad444b88afb6e31cfc88bf3..99c4b628743d6bf7dcc5588f2e0f20e09b27b344 100644 (file)
 #ifndef _AUTOPILOT_H
 #define _AUTOPILOT_H
                        
+
 #include <Aircraft/aircraft.h>
 #include <Flight/flight.h>
 #include <Controls/controls.h>
                        
                        
+#ifdef __cplusplus                                                          
+extern "C" {                            
+#endif                                   
+
 
 typedef struct {
                int Mode ; // the current mode the AP is operating in
@@ -50,5 +55,10 @@ int fgAPRun( void );
 void fgAPSetMode( int mode);
 
 
+#ifdef __cplusplus
+}
 #endif
-               
\ No newline at end of file
+
+
+#endif // _AUTOPILOT_H
+               
index eefe9d3c5714a7ec6bf4ed1fb7887325d033cdbe..abcfc2a668c3489c2b6a6ead0d497366ef94ba4d 100644 (file)
 #define _COCKPIT_H
 
 
+#include <Cockpit/hud.h>
+
+
 #ifdef __cplusplus                                                          
 extern "C" {                            
 #endif                                   
 
 
-#include <Cockpit/hud.h>
-
-
 // And in the future (near future i hope).
 // #include <Cockpit/panel.h>
 
@@ -60,9 +60,12 @@ void fgCockpitUpdate( void );
 
 
 /* $Log$
-/* Revision 1.7  1998/04/21 17:02:34  curt
-/* Prepairing for C++ integration.
+/* Revision 1.8  1998/04/22 13:26:19  curt
+/* C++ - ifing the code a bit.
 /*
+ * Revision 1.7  1998/04/21 17:02:34  curt
+ * Prepairing for C++ integration.
+ *
  * Revision 1.6  1998/02/07 15:29:33  curt
  * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
  * <chotchkiss@namg.us.anritsu.com>
index 4858180462fffbb3c52f59401d5739e373c1a363..2abce93ed4ebddfc953094a1ba7aec7d97fd1efb 100644 (file)
 #define _CONTROLS_H
 
 
+#include <Include/fg_limits.h>
+
+
 #ifdef __cplusplus                                                          
 extern "C" {                            
 #endif                                   
 
 
-#include <Include/fg_limits.h>
-
-
 /* Define a structure containing the control parameters */
 
 typedef struct {
@@ -92,9 +92,12 @@ void fgThrottleSet(int engine, double pos);
 
 
 /* $Log$
-/* Revision 1.13  1998/04/21 17:02:35  curt
-/* Prepairing for C++ integration.
+/* Revision 1.14  1998/04/22 13:26:19  curt
+/* C++ - ifing the code a bit.
 /*
+ * Revision 1.13  1998/04/21 17:02:35  curt
+ * Prepairing for C++ integration.
+ *
  * Revision 1.12  1998/02/09 22:56:48  curt
  * Removed "depend" files from cvs control.  Other minor make tweaks.
  *
index 3ae17f8d890bdb7130d026d6881463152c407659..04087fb17f3bf9b792c29ab28ecc5344878c4c96 100644 (file)
 #define _FLIGHT_H
 
 
+#include <Flight/Slew/slew.h>
+
+
 #ifdef __cplusplus                                                          
 extern "C" {                            
 #endif                                   
 
 
-#include <Flight/Slew/slew.h>
-/* #include <Flight/LaRCsim/ls_interface.h> */
-
-
 /* Define the various supported flight models (most not yet implemented) */
 #define FG_LARCSIM     0   /* The only one that is currently implemented */
 #define FG_ACM         1
@@ -411,10 +410,13 @@ int fgFlightModelUpdate(int model, fgFLIGHT *f, int multiloop);
 
 
 /* $Log$
-/* Revision 1.15  1998/04/21 16:59:33  curt
-/* Integrated autopilot.
-/* Prepairing for C++ integration.
+/* Revision 1.16  1998/04/22 13:26:20  curt
+/* C++ - ifing the code a bit.
 /*
+ * Revision 1.15  1998/04/21 16:59:33  curt
+ * Integrated autopilot.
+ * Prepairing for C++ integration.
+ *
  * Revision 1.14  1998/02/07 15:29:37  curt
  * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
  * <chotchkiss@namg.us.anritsu.com>
index 3c9d0c6ed2f8a33ce3dd933bc630c5d2df7ae837..276afb9390d23d637b8aeac08fd896b2e5b29aba 100644 (file)
 #define _JOYSTICK_H
 
 
+#ifdef __cplusplus                                                          
+extern "C" {                            
+#endif                                   
+
+
 int fgJoystickInit( int joy_num );
 int fgJoystickRead( double *joy_x, double *joy_y, int *joy_b1, int *joy_b2 );
 
 
+#ifdef __cplusplus
+}
+#endif
+
+
 #endif /* _JOYSTICK_H */
 
 
 /* $Log$
-/* Revision 1.2  1998/01/22 02:59:36  curt
-/* Changed #ifdef FILE_H to #ifdef _FILE_H
+/* Revision 1.3  1998/04/22 13:26:21  curt
+/* C++ - ifing the code a bit.
 /*
+ * Revision 1.2  1998/01/22 02:59:36  curt
+ * Changed #ifdef FILE_H to #ifdef _FILE_H
+ *
  * Revision 1.1  1997/08/29 18:06:55  curt
  * Initial revision.
  *
index fadd161c96f456063487f4d8ad6a9795d4f1dde9..575d02ab76f6db7a968c13815e5e90b20c62b9a1 100644 (file)
@@ -6,8 +6,8 @@ libScenery_la_SOURCES = \
        obj.c obj.h \
        scenery.c scenery.h \
        texload.c texload.h \
-       tilecache.c tilecache.h \
-       tilemgr.c tilemgr.h
+       tilecache.cxx tilecache.hxx \
+       tilemgr.cxx tilemgr.hxx
 
 INCLUDES += \
        -I$(top_builddir) \
index c4f45f80b0ab6f76675163904bb9a730670f3a76..f6ced03c838f55818f4e2ac8da40b1d6cf92cdc9 100644 (file)
@@ -78,8 +78,8 @@ libScenery_la_SOURCES = \
        obj.c obj.h \
        scenery.c scenery.h \
        texload.c texload.h \
-       tilecache.c tilecache.h \
-       tilemgr.c tilemgr.h
+       tilecache.cxx tilecache.hxx \
+       tilemgr.cxx tilemgr.hxx
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
 CONFIG_HEADER = ../../Include/config.h
 CONFIG_CLEAN_FILES = 
@@ -98,6 +98,10 @@ libScenery_la_LDFLAGS =
 libScenery_la_LIBADD = 
 libScenery_la_OBJECTS =  obj.lo scenery.lo texload.lo tilecache.lo \
 tilemgr.lo
+CXXFLAGS = @CXXFLAGS@
+CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
+CXXLINK = $(LIBTOOL) --mode=link $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@
 CFLAGS = @CFLAGS@
 COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
@@ -111,13 +115,14 @@ TAR = tar
 GZIP = --best
 DEP_FILES =  .deps/obj.P .deps/scenery.P .deps/texload.P \
 .deps/tilecache.P .deps/tilemgr.P
+CXXMKDEP = $(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
 SOURCES = $(libScenery_la_SOURCES)
 OBJECTS = $(libScenery_la_OBJECTS)
 
 all: Makefile $(LTLIBRARIES)
 
 .SUFFIXES:
-.SUFFIXES: .S .c .lo .o .s
+.SUFFIXES: .S .c .cxx .lo .o .s
 $(srcdir)/Makefile.in: @MAINT@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
        cd $(top_srcdir) && $(AUTOMAKE) --gnu Simulator/Scenery/Makefile
 
@@ -184,7 +189,11 @@ distclean-libtool:
 maintainer-clean-libtool:
 
 libScenery.la: $(libScenery_la_OBJECTS) $(libScenery_la_DEPENDENCIES)
-       $(LINK) -rpath $(libdir) $(libScenery_la_LDFLAGS) $(libScenery_la_OBJECTS) $(libScenery_la_LIBADD) $(LIBS)
+       $(CXXLINK) -rpath $(libdir) $(libScenery_la_LDFLAGS) $(libScenery_la_OBJECTS) $(libScenery_la_LIBADD) $(LIBS)
+.cxx.o:
+       $(CXXCOMPILE) -c $<
+.cxx.lo:
+       $(LTCXXCOMPILE) -c $<
 
 tags: TAGS
 
@@ -251,6 +260,17 @@ maintainer-clean-depend:
        @-sed -e 's/^\([^:]*\)\.o:/\1.lo \1.o:/' \
          < .deps/$(*F).p > .deps/$(*F).P
        @-rm -f .deps/$(*F).p
+
+%.o: %.cxx
+       @echo '$(CXXCOMPILE) -c $<'; \
+       $(CXXCOMPILE) -Wp,-MD,.deps/$(*F).P -c $<
+
+%.lo: %.cxx
+       @echo '$(LTCXXCOMPILE) -c $<'; \
+       $(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).p -c $<
+       @-sed -e 's/^\([^:]*\)\.o:/\1.lo \1.o:/' \
+         < .deps/$(*F).p > .deps/$(*F).P
+       @-rm -f .deps/$(*F).p
 info:
 dvi:
 check: all
index 3edee359432940f79a6352751b92118a00ead43c..0c1374b2dfd51164aa74d41cf4529b726da968f6 100644 (file)
@@ -96,7 +96,7 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
     double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
     GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
     GLint tile;
-    gzFile *f;
+    gzFile f;
     int first, ncount, vncount, n1, n2, n3, n4;
     static int use_per_vertex_norms = 1;
     int winding;
@@ -398,9 +398,12 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
 
 
 /* $Log$
-/* Revision 1.27  1998/04/18 04:13:17  curt
-/* Added zlib on the fly decompression support for loading scenery objects.
+/* Revision 1.28  1998/04/22 13:22:44  curt
+/* C++ - ifing the code a bit.
 /*
+ * Revision 1.27  1998/04/18 04:13:17  curt
+ * Added zlib on the fly decompression support for loading scenery objects.
+ *
  * Revision 1.26  1998/04/03 22:11:36  curt
  * Converting to Gnu autoconf system.
  *
index 9d8fdb2d5f1f5307c7053f0cc36d1f9da2b77a25..aa601c3d82146b9b89f23b80185351387766bdcd 100644 (file)
 #define _OBJ_H
 
 
-#ifdef __cplusplus                                                          
-extern "C" {                            
-#endif                                   
-
-
 #include <config.h>
 
 #ifdef HAVE_WINDOWS_H
@@ -44,6 +39,11 @@ extern "C" {
 #include <Include/fg_types.h>
 
 
+#ifdef __cplusplus                                                          
+extern "C" {                            
+#endif                                   
+
+
 /* Load a .obj file and generate the GL call list */
 GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius);
 
@@ -57,9 +57,12 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius);
 
 
 /* $Log$
-/* Revision 1.8  1998/04/21 17:02:43  curt
-/* Prepairing for C++ integration.
+/* Revision 1.9  1998/04/22 13:22:45  curt
+/* C++ - ifing the code a bit.
 /*
+ * Revision 1.8  1998/04/21 17:02:43  curt
+ * Prepairing for C++ integration.
+ *
  * Revision 1.7  1998/04/03 22:11:37  curt
  * Converting to Gnu autoconf system.
  *
index 09b1d98e07fec822bafaaf25d8e4e3b2ac6d6f6f..2bd1e184f21bf6a8feb949d4fe904a39e21fd09c 100644 (file)
 #define _SCENERY_H
 
 
+#include <Include/fg_types.h>
+
+
 #ifdef __cplusplus                                                          
 extern "C" {                            
 #endif                                   
 
 
-#include <Include/fg_types.h>
-
-
 /* Define a structure containing global scenery parameters */
 struct fgSCENERY {
     /* number of terrain data points to skip */
@@ -76,9 +76,12 @@ void fgSceneryRender( void );
 
 
 /* $Log$
-/* Revision 1.19  1998/04/21 17:02:43  curt
-/* Prepairing for C++ integration.
+/* Revision 1.20  1998/04/22 13:22:45  curt
+/* C++ - ifing the code a bit.
 /*
+ * Revision 1.19  1998/04/21 17:02:43  curt
+ * Prepairing for C++ integration.
+ *
  * Revision 1.18  1998/03/14 00:30:51  curt
  * Beginning initial terrain texturing experiments.
  *
index 348f45014a1b3e4aa8792d989764d74bc913bc4c..3581102729955aa83555fe4c84a3bc481131889b 100644 (file)
 #define _TEXLOAD_H
 
 
+#include <GL/glut.h>
+
+
 #ifdef __cplusplus                                                          
 extern "C" {                            
 #endif                                   
 
 
-#include <GL/glut.h>
-
 extern GLubyte *read_alpha_texture(char *name, int *width, int *height);
 extern GLubyte * read_rgb_texture(char *name, int *width, int *height);
 
diff --git a/Scenery/tilecache.c b/Scenery/tilecache.c
deleted file mode 100644 (file)
index 4669a4e..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-/**************************************************************************
- * tilecache.c -- routines to handle scenery tile caching
- *
- * Written by Curtis Olson, started January 1998.
- *
- * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#include <config.h>
-
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#endif
-
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-
-#include <Include/general.h>
-
-#include <Bucket/bucketutils.h>
-#include <Debug/fg_debug.h>
-#include <Main/views.h>
-#include <Scenery/obj.h>
-#include <Scenery/tilecache.h>
-
-
-/* tile cache */
-struct fgTILE tile_cache[FG_TILE_CACHE_SIZE];
-
-
-/* Initialize the tile cache subsystem */
-void fgTileCacheInit( void ) {
-    int i;
-
-    fgPrintf(FG_TERRAIN, FG_INFO, "Initializing the tile cache.\n");
-
-    for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
-       tile_cache[i].used = 0;
-    }
-}
-
-
-/* Search for the specified "bucket" in the cache */
-int fgTileCacheExists( struct fgBUCKET *p ) {
-    int i;
-
-    for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
-       if ( tile_cache[i].tile_bucket.lon == p->lon ) {
-           if ( tile_cache[i].tile_bucket.lat == p->lat ) {
-               if ( tile_cache[i].tile_bucket.x == p->x ) {
-                   if ( tile_cache[i].tile_bucket.y == p->y ) {
-                       fgPrintf( FG_TERRAIN, FG_DEBUG, 
-                                 "TILE EXISTS in cache ... index = %d\n", i );
-                       return( i );
-                   }
-               }
-           }
-       }
-    }
-    
-    return( -1 );
-}
-
-
-/* Fill in a tile cache entry with real data for the specified bucket */
-void fgTileCacheEntryFillIn( int index, struct fgBUCKET *p ) {
-    fgGENERAL *g;
-    char base_path[256];
-    char file_name[256];
-
-    g = &general;
-
-    /* Mark this cache entry as used */
-    tile_cache[index].used = 1;
-
-    /* Update the bucket */
-    tile_cache[index].tile_bucket.lon = p->lon;
-    tile_cache[index].tile_bucket.lat = p->lat;
-    tile_cache[index].tile_bucket.x = p->x;
-    tile_cache[index].tile_bucket.y = p->y;
-
-    /* Load the appropriate area and get the display list pointer */
-    fgBucketGenBasePath(p, base_path);
-    sprintf(file_name, "%s/Scenery/%s/%ld.obj", g->root_dir, 
-           base_path, fgBucketGenIndex(p));
-    tile_cache[index].display_list = 
-       fgObjLoad(file_name, &tile_cache[index].local_ref,
-                 &tile_cache[index].bounding_radius);    
-}
-
-
-/* Free a tile cache entry */
-void fgTileCacheEntryFree( int index ) {
-    /* Mark this cache entry as un-used */
-    tile_cache[index].used = 0;
-
-    /* Update the bucket */
-    fgPrintf( FG_TERRAIN, FG_DEBUG, 
-             "FREEING TILE = (%d %d %d %d)\n",
-             tile_cache[index].tile_bucket.lon, 
-             tile_cache[index].tile_bucket.lat, 
-             tile_cache[index].tile_bucket.x,
-             tile_cache[index].tile_bucket.y );
-
-    /* Load the appropriate area and get the display list pointer */
-    if ( tile_cache[index].display_list >= 0 ) {
-       xglDeleteLists( tile_cache[index].display_list, 1 );
-    }
-}
-
-
-/* Return info for a tile cache entry */
-void fgTileCacheEntryInfo( int index, GLint *display_list, 
-                          struct fgCartesianPoint *local_ref ) {
-    *display_list = tile_cache[index].display_list;
-    /* fgPrintf(FG_TERRAIN, FG_DEBUG, "Display list = %d\n", *display_list); */
-
-    local_ref->x = tile_cache[index].local_ref.x;
-    local_ref->y = tile_cache[index].local_ref.y;
-    local_ref->z = tile_cache[index].local_ref.z;
-}
-
-
-/* Return index of next available slot in tile cache */
-int fgTileCacheNextAvail( void ) {
-    struct fgVIEW *v;
-    int i;
-    float dx, dy, dz, max, med, min, tmp;
-    float dist, max_dist;
-    int max_index;
-    
-    v = &current_view;
-
-    max_dist = 0.0;
-    max_index = 0;
-
-    for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
-       if ( tile_cache[i].used == 0 ) {
-           return(i);
-       } else {
-           /* calculate approximate distance from view point */
-           fgPrintf( FG_TERRAIN, FG_DEBUG,
-                     "DIST Abs view pos = %.4f, %.4f, %.4f\n", 
-                     v->abs_view_pos.x, v->abs_view_pos.y, v->abs_view_pos.z );
-           fgPrintf( FG_TERRAIN, FG_DEBUG,
-                     "    ref point = %.4f, %.4f, %.4f\n", 
-                     tile_cache[i].local_ref.x, tile_cache[i].local_ref.y,
-                     tile_cache[i].local_ref.z);
-
-           dx = fabs(tile_cache[i].local_ref.x - v->abs_view_pos.x);
-           dy = fabs(tile_cache[i].local_ref.y - v->abs_view_pos.y);
-           dz = fabs(tile_cache[i].local_ref.z - v->abs_view_pos.z);
-
-           max = dx; med = dy; min = dz;
-           if ( max < med ) {
-               tmp = max; max = med; med = tmp;
-           }
-           if ( max < min ) {
-               tmp = max; max = min; min = tmp;
-           }
-           dist = max + (med + min) / 4;
-
-           fgPrintf( FG_TERRAIN, FG_DEBUG, "    distance = %.2f\n", dist);
-
-           if ( dist > max_dist ) {
-               max_dist = dist;
-               max_index = i;
-           }
-       }
-    }
-
-    /* If we made it this far, then there were no open cache entries.
-     * We will instead free the furthest cache entry and return it's
-     * index. */
-    
-    fgTileCacheEntryFree( max_index );
-    return( max_index );
-}
-
-
-/* $Log$
-/* Revision 1.11  1998/04/18 04:14:07  curt
-/* Moved fg_debug.c to it's own library.
-/*
- * Revision 1.10  1998/04/14 02:23:17  curt
- * Code reorganizations.  Added a Lib/ directory for more general libraries.
- *
- * Revision 1.9  1998/04/08 23:30:07  curt
- * Adopted Gnu automake/autoconf system.
- *
- * Revision 1.8  1998/04/03 22:11:38  curt
- * Converting to Gnu autoconf system.
- *
- * Revision 1.7  1998/02/01 03:39:55  curt
- * Minor tweaks.
- *
- * Revision 1.6  1998/01/31 00:43:26  curt
- * Added MetroWorks patches from Carmen Volpe.
- *
- * Revision 1.5  1998/01/29 00:51:39  curt
- * First pass at tile cache, dynamic tile loading and tile unloading now works.
- *
- * Revision 1.4  1998/01/27 03:26:43  curt
- * Playing with new fgPrintf command.
- *
- * Revision 1.3  1998/01/27 00:48:03  curt
- * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
- * system and commandline/config file processing code.
- *
- * Revision 1.2  1998/01/26 15:55:24  curt
- * Progressing on building dynamic scenery system.
- *
- * Revision 1.1  1998/01/24 00:03:29  curt
- * Initial revision.
- *
- */
-
-
diff --git a/Scenery/tilecache.cxx b/Scenery/tilecache.cxx
new file mode 100644 (file)
index 0000000..61fb092
--- /dev/null
@@ -0,0 +1,240 @@
+/**************************************************************************
+ * tilecache.c -- routines to handle scenery tile caching
+ *
+ * Written by Curtis Olson, started January 1998.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#include <config.h>
+
+#ifdef HAVE_WINDOWS_H
+#  include <windows.h>
+#endif
+
+#include <GL/glut.h>
+#include <XGL/xgl.h>
+
+#include <Include/general.h>
+
+#include <Bucket/bucketutils.h>
+#include <Debug/fg_debug.h>
+#include <Main/views.hxx>
+
+#include "obj.h"
+#include "tilecache.hxx"
+
+
+/* tile cache */
+struct fgTILE tile_cache[FG_TILE_CACHE_SIZE];
+
+
+/* Initialize the tile cache subsystem */
+void fgTileCacheInit( void ) {
+    int i;
+
+    fgPrintf(FG_TERRAIN, FG_INFO, "Initializing the tile cache.\n");
+
+    for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
+       tile_cache[i].used = 0;
+    }
+}
+
+
+/* Search for the specified "bucket" in the cache */
+int fgTileCacheExists( struct fgBUCKET *p ) {
+    int i;
+
+    for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
+       if ( tile_cache[i].tile_bucket.lon == p->lon ) {
+           if ( tile_cache[i].tile_bucket.lat == p->lat ) {
+               if ( tile_cache[i].tile_bucket.x == p->x ) {
+                   if ( tile_cache[i].tile_bucket.y == p->y ) {
+                       fgPrintf( FG_TERRAIN, FG_DEBUG, 
+                                 "TILE EXISTS in cache ... index = %d\n", i );
+                       return( i );
+                   }
+               }
+           }
+       }
+    }
+    
+    return( -1 );
+}
+
+
+/* Fill in a tile cache entry with real data for the specified bucket */
+void fgTileCacheEntryFillIn( int index, struct fgBUCKET *p ) {
+    fgGENERAL *g;
+    char base_path[256];
+    char file_name[256];
+
+    g = &general;
+
+    /* Mark this cache entry as used */
+    tile_cache[index].used = 1;
+
+    /* Update the bucket */
+    tile_cache[index].tile_bucket.lon = p->lon;
+    tile_cache[index].tile_bucket.lat = p->lat;
+    tile_cache[index].tile_bucket.x = p->x;
+    tile_cache[index].tile_bucket.y = p->y;
+
+    /* Load the appropriate area and get the display list pointer */
+    fgBucketGenBasePath(p, base_path);
+    sprintf(file_name, "%s/Scenery/%s/%ld.obj", g->root_dir, 
+           base_path, fgBucketGenIndex(p));
+    tile_cache[index].display_list = 
+       fgObjLoad(file_name, &tile_cache[index].local_ref,
+                 &tile_cache[index].bounding_radius);    
+}
+
+
+/* Free a tile cache entry */
+void fgTileCacheEntryFree( int index ) {
+    /* Mark this cache entry as un-used */
+    tile_cache[index].used = 0;
+
+    /* Update the bucket */
+    fgPrintf( FG_TERRAIN, FG_DEBUG, 
+             "FREEING TILE = (%d %d %d %d)\n",
+             tile_cache[index].tile_bucket.lon, 
+             tile_cache[index].tile_bucket.lat, 
+             tile_cache[index].tile_bucket.x,
+             tile_cache[index].tile_bucket.y );
+
+    /* Load the appropriate area and get the display list pointer */
+    if ( tile_cache[index].display_list >= 0 ) {
+       xglDeleteLists( tile_cache[index].display_list, 1 );
+    }
+}
+
+
+/* Return info for a tile cache entry */
+void fgTileCacheEntryInfo( int index, GLint *display_list, 
+                          struct fgCartesianPoint *local_ref ) {
+    *display_list = tile_cache[index].display_list;
+    /* fgPrintf(FG_TERRAIN, FG_DEBUG, "Display list = %d\n", *display_list); */
+
+    local_ref->x = tile_cache[index].local_ref.x;
+    local_ref->y = tile_cache[index].local_ref.y;
+    local_ref->z = tile_cache[index].local_ref.z;
+}
+
+
+/* Return index of next available slot in tile cache */
+int fgTileCacheNextAvail( void ) {
+    struct fgVIEW *v;
+    int i;
+    float dx, dy, dz, max, med, min, tmp;
+    float dist, max_dist;
+    int max_index;
+    
+    v = &current_view;
+
+    max_dist = 0.0;
+    max_index = 0;
+
+    for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
+       if ( tile_cache[i].used == 0 ) {
+           return(i);
+       } else {
+           /* calculate approximate distance from view point */
+           fgPrintf( FG_TERRAIN, FG_DEBUG,
+                     "DIST Abs view pos = %.4f, %.4f, %.4f\n", 
+                     v->abs_view_pos.x, v->abs_view_pos.y, v->abs_view_pos.z );
+           fgPrintf( FG_TERRAIN, FG_DEBUG,
+                     "    ref point = %.4f, %.4f, %.4f\n", 
+                     tile_cache[i].local_ref.x, tile_cache[i].local_ref.y,
+                     tile_cache[i].local_ref.z);
+
+           dx = fabs(tile_cache[i].local_ref.x - v->abs_view_pos.x);
+           dy = fabs(tile_cache[i].local_ref.y - v->abs_view_pos.y);
+           dz = fabs(tile_cache[i].local_ref.z - v->abs_view_pos.z);
+
+           max = dx; med = dy; min = dz;
+           if ( max < med ) {
+               tmp = max; max = med; med = tmp;
+           }
+           if ( max < min ) {
+               tmp = max; max = min; min = tmp;
+           }
+           dist = max + (med + min) / 4;
+
+           fgPrintf( FG_TERRAIN, FG_DEBUG, "    distance = %.2f\n", dist);
+
+           if ( dist > max_dist ) {
+               max_dist = dist;
+               max_index = i;
+           }
+       }
+    }
+
+    /* If we made it this far, then there were no open cache entries.
+     * We will instead free the furthest cache entry and return it's
+     * index. */
+    
+    fgTileCacheEntryFree( max_index );
+    return( max_index );
+}
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:22:46  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.11  1998/04/18 04:14:07  curt
+ * Moved fg_debug.c to it's own library.
+ *
+ * Revision 1.10  1998/04/14 02:23:17  curt
+ * Code reorganizations.  Added a Lib/ directory for more general libraries.
+ *
+ * Revision 1.9  1998/04/08 23:30:07  curt
+ * Adopted Gnu automake/autoconf system.
+ *
+ * Revision 1.8  1998/04/03 22:11:38  curt
+ * Converting to Gnu autoconf system.
+ *
+ * Revision 1.7  1998/02/01 03:39:55  curt
+ * Minor tweaks.
+ *
+ * Revision 1.6  1998/01/31 00:43:26  curt
+ * Added MetroWorks patches from Carmen Volpe.
+ *
+ * Revision 1.5  1998/01/29 00:51:39  curt
+ * First pass at tile cache, dynamic tile loading and tile unloading now works.
+ *
+ * Revision 1.4  1998/01/27 03:26:43  curt
+ * Playing with new fgPrintf command.
+ *
+ * Revision 1.3  1998/01/27 00:48:03  curt
+ * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
+ * system and commandline/config file processing code.
+ *
+ * Revision 1.2  1998/01/26 15:55:24  curt
+ * Progressing on building dynamic scenery system.
+ *
+ * Revision 1.1  1998/01/24 00:03:29  curt
+ * Initial revision.
+ *
+ */
+
+
diff --git a/Scenery/tilecache.h b/Scenery/tilecache.h
deleted file mode 100644 (file)
index 10c204b..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/**************************************************************************
- * tilecache.h -- routines to handle scenery tile caching
- *
- * Written by Curtis Olson, started January 1998.
- *
- * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#ifndef _TILECACHE_H
-#define _TILECACHE_H
-
-
-#ifdef __cplusplus                                                          
-extern "C" {                            
-#endif                                   
-
-
-#include <config.h>
-
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#endif
-
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-
-#include <Bucket/bucketutils.h>
-#include <Include/fg_types.h>
-
-/* For best results ... i.e. to avoid tile load problems and blank areas
- *
- * FG_TILE_CACHE_SIZE >= FG_LOCAL_X_Y + 2*max(FG_LOCAL_X, FG_LOCAL_Y) + 1 */
-#define FG_TILE_CACHE_SIZE 100
-
-
-/* Tile cache record */
-struct fgTILE {
-    struct fgBUCKET tile_bucket;
-    GLint display_list;
-    struct fgCartesianPoint local_ref;
-    double bounding_radius;
-    int used;
-    int priority;
-};
-
-/* tile cache */
-extern struct fgTILE tile_cache[FG_TILE_CACHE_SIZE];
-
-
-/* Initialize the tile cache subsystem */
-void fgTileCacheInit( void );
-
-/* Search for the specified "bucket" in the cache */
-int fgTileCacheExists( struct fgBUCKET *p );
-
-/* Return index of next available slot in tile cache */
-int fgTileCacheNextAvail( void );
-
-/* Fill in a tile cache entry with real data for the specified bucket */
-void fgTileCacheEntryFillIn( int index, struct fgBUCKET *p );
-
-/* Return info for a tile cache entry */
-void fgTileCacheEntryInfo( int index, GLint *display_list, 
-                          struct fgCartesianPoint *local_ref );
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _TILECACHE_H */
-
-
-/* $Log$
-/* Revision 1.10  1998/04/21 17:02:45  curt
-/* Prepairing for C++ integration.
-/*
- * Revision 1.9  1998/04/14 02:23:17  curt
- * Code reorganizations.  Added a Lib/ directory for more general libraries.
- *
- * Revision 1.8  1998/04/08 23:30:08  curt
- * Adopted Gnu automake/autoconf system.
- *
- * Revision 1.7  1998/04/03 22:11:38  curt
- * Converting to Gnu autoconf system.
- *
- * Revision 1.6  1998/02/18 15:07:10  curt
- * Tweaks to build with SGI OpenGL (and therefor hopefully other accelerated
- * drivers will work.)
- *
- * Revision 1.5  1998/02/16 13:39:45  curt
- * Miscellaneous weekend tweaks.  Fixed? a cache problem that caused whole
- * tiles to occasionally be missing.
- *
- * Revision 1.4  1998/01/31 00:43:27  curt
- * Added MetroWorks patches from Carmen Volpe.
- *
- * Revision 1.3  1998/01/29 00:51:40  curt
- * First pass at tile cache, dynamic tile loading and tile unloading now works.
- *
- * Revision 1.2  1998/01/27 00:48:04  curt
- * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
- * system and commandline/config file processing code.
- *
- * Revision 1.1  1998/01/24 00:03:29  curt
- * Initial revision.
- *
- */
-
-
diff --git a/Scenery/tilecache.hxx b/Scenery/tilecache.hxx
new file mode 100644 (file)
index 0000000..5f8c41d
--- /dev/null
@@ -0,0 +1,127 @@
+/**************************************************************************
+ * tilecache.h -- routines to handle scenery tile caching
+ *
+ * Written by Curtis Olson, started January 1998.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#ifndef _TILECACHE_H
+#define _TILECACHE_H
+
+
+#ifndef __cplusplus                                                          
+# error This library requires C++
+#endif                                   
+
+
+#include <config.h>
+
+#ifdef HAVE_WINDOWS_H
+#  include <windows.h>
+#endif
+
+#include <GL/glut.h>
+#include <XGL/xgl.h>
+
+#include <Bucket/bucketutils.h>
+#include <Include/fg_types.h>
+
+/* For best results ... i.e. to avoid tile load problems and blank areas
+ *
+ * FG_TILE_CACHE_SIZE >= FG_LOCAL_X_Y + 2*max(FG_LOCAL_X, FG_LOCAL_Y) + 1 */
+#define FG_TILE_CACHE_SIZE 100
+
+
+/* Tile cache record */
+struct fgTILE {
+    struct fgBUCKET tile_bucket;
+    GLint display_list;
+    struct fgCartesianPoint local_ref;
+    double bounding_radius;
+    int used;
+    int priority;
+};
+
+/* tile cache */
+extern struct fgTILE tile_cache[FG_TILE_CACHE_SIZE];
+
+
+/* Initialize the tile cache subsystem */
+void fgTileCacheInit( void );
+
+/* Search for the specified "bucket" in the cache */
+int fgTileCacheExists( struct fgBUCKET *p );
+
+/* Return index of next available slot in tile cache */
+int fgTileCacheNextAvail( void );
+
+/* Fill in a tile cache entry with real data for the specified bucket */
+void fgTileCacheEntryFillIn( int index, struct fgBUCKET *p );
+
+/* Return info for a tile cache entry */
+void fgTileCacheEntryInfo( int index, GLint *display_list, 
+                          struct fgCartesianPoint *local_ref );
+
+
+#endif /* _TILECACHE_H */
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:22:47  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.10  1998/04/21 17:02:45  curt
+ * Prepairing for C++ integration.
+ *
+ * Revision 1.9  1998/04/14 02:23:17  curt
+ * Code reorganizations.  Added a Lib/ directory for more general libraries.
+ *
+ * Revision 1.8  1998/04/08 23:30:08  curt
+ * Adopted Gnu automake/autoconf system.
+ *
+ * Revision 1.7  1998/04/03 22:11:38  curt
+ * Converting to Gnu autoconf system.
+ *
+ * Revision 1.6  1998/02/18 15:07:10  curt
+ * Tweaks to build with SGI OpenGL (and therefor hopefully other accelerated
+ * drivers will work.)
+ *
+ * Revision 1.5  1998/02/16 13:39:45  curt
+ * Miscellaneous weekend tweaks.  Fixed? a cache problem that caused whole
+ * tiles to occasionally be missing.
+ *
+ * Revision 1.4  1998/01/31 00:43:27  curt
+ * Added MetroWorks patches from Carmen Volpe.
+ *
+ * Revision 1.3  1998/01/29 00:51:40  curt
+ * First pass at tile cache, dynamic tile loading and tile unloading now works.
+ *
+ * Revision 1.2  1998/01/27 00:48:04  curt
+ * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
+ * system and commandline/config file processing code.
+ *
+ * Revision 1.1  1998/01/24 00:03:29  curt
+ * Initial revision.
+ *
+ */
+
+
diff --git a/Scenery/tilemgr.c b/Scenery/tilemgr.c
deleted file mode 100644 (file)
index a692bd8..0000000
+++ /dev/null
@@ -1,313 +0,0 @@
-/* -*- Mode: C++ -*-
- *
- * tilemgr.c -- routines to handle dynamic management of scenery tiles
- *
- * Written by Curtis Olson, started January 1998.
- *
- * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#include <config.h>
-
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#endif
-
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-
-#include <Scenery/scenery.h>
-#include <Scenery/obj.h>
-#include <Scenery/tilecache.h>
-
-#include <Aircraft/aircraft.h>
-#include <Bucket/bucketutils.h>
-#include <Debug/fg_debug.h>
-#include <Include/fg_constants.h>
-#include <Include/fg_types.h>
-
-
-#define FG_LOCAL_X           7   /* should be odd */
-#define FG_LOCAL_Y           7   /* should be odd */
-#define FG_LOCAL_X_Y         49  /* At least FG_LOCAL_X times FG_LOCAL_Y */
-
-
-/* closest (potentially viewable) tiles, centered on current tile.
- * This is an array of pointers to cache indexes. */
-int tiles[FG_LOCAL_X_Y];
-
-
-/* Initialize the Tile Manager subsystem */
-int fgTileMgrInit( void ) {
-    fgPrintf( FG_TERRAIN, FG_INFO, "Initializing Tile Manager subsystem.\n");
-    return 1;
-}
-
-
-/* load a tile */
-void fgTileMgrLoadTile( struct fgBUCKET *p, int *index) {
-    fgPrintf( FG_TERRAIN, FG_DEBUG, "Updating for bucket %d %d %d %d\n", 
-          p->lon, p->lat, p->x, p->y);
-    
-    /* if not in cache, load tile into the next available slot */
-    if ( (*index = fgTileCacheExists(p)) < 0 ) {
-       *index = fgTileCacheNextAvail();
-       fgTileCacheEntryFillIn(*index, p);
-    }
-
-    fgPrintf( FG_TERRAIN, FG_DEBUG, "Selected cache index of %d\n", *index);
-}
-
-
-/* given the current lon/lat, fill in the array of local chunks.  If
- * the chunk isn't already in the cache, then read it from disk. */
-int fgTileMgrUpdate( void ) {
-    fgFLIGHT *f;
-    struct fgBUCKET p1, p2;
-    static struct fgBUCKET p_last = {-1000, 0, 0, 0};
-    int i, j, dw, dh;
-
-    f = current_aircraft.flight;
-
-    fgBucketFind(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p1);
-    dw = FG_LOCAL_X / 2;
-    dh = FG_LOCAL_Y / 2;
-
-    if ( (p1.lon == p_last.lon) && (p1.lat == p_last.lat) &&
-        (p1.x == p_last.x) && (p1.y == p_last.y) ) {
-       /* same bucket as last time */
-       fgPrintf( FG_TERRAIN, FG_DEBUG, "Same bucket as last time\n");
-    } else if ( p_last.lon == -1000 ) {
-       /* First time through, initialize the system and load all
-         * relavant tiles */
-
-       fgPrintf( FG_TERRAIN, FG_DEBUG, "First time through ... \n");
-       fgPrintf( FG_TERRAIN, FG_DEBUG, "Updating Tile list for %d,%d %d,%d\n",
-                 p1.lon, p1.lat, p1.x, p1.y);
-
-       /* wipe tile cache */
-       fgTileCacheInit();
-
-       /* build the local area list and update cache */
-       for ( j = 0; j < FG_LOCAL_Y; j++ ) {
-           for ( i = 0; i < FG_LOCAL_X; i++ ) {
-               fgBucketOffset(&p1, &p2, i - dw, j - dh);
-               fgTileMgrLoadTile(&p2, &tiles[(j*FG_LOCAL_Y) + i]);
-           }
-       }
-    } else {
-       /* We've moved to a new bucket, we need to scroll our
-         * structures, and load in the new tiles */
-
-       /* CURRENTLY THIS ASSUMES WE CAN ONLY MOVE TO ADJACENT TILES.
-           AT ULTRA HIGH SPEEDS THIS ASSUMPTION MAY NOT BE VALID IF
-           THE AIRCRAFT CAN SKIP A TILE IN A SINGLE ITERATION. */
-
-       if ( (p1.lon > p_last.lon) ||
-            ( (p1.lon == p_last.lon) && (p1.x > p_last.x) ) ) {
-           for ( j = 0; j < FG_LOCAL_Y; j++ ) {
-               /* scrolling East */
-               for ( i = 0; i < FG_LOCAL_X - 1; i++ ) {
-                   tiles[(j*FG_LOCAL_Y) + i] = tiles[(j*FG_LOCAL_Y) + i + 1];
-               }
-               /* load in new column */
-               fgBucketOffset(&p_last, &p2, dw + 1, j - dh);
-               fgTileMgrLoadTile(&p2, &tiles[(j*FG_LOCAL_Y) + FG_LOCAL_X - 1]);
-           }
-       } else if ( (p1.lon < p_last.lon) ||
-                   ( (p1.lon == p_last.lon) && (p1.x < p_last.x) ) ) {
-           for ( j = 0; j < FG_LOCAL_Y; j++ ) {
-               /* scrolling West */
-               for ( i = FG_LOCAL_X - 1; i > 0; i-- ) {
-                   tiles[(j*FG_LOCAL_Y) + i] = tiles[(j*FG_LOCAL_Y) + i - 1];
-               }
-               /* load in new column */
-               fgBucketOffset(&p_last, &p2, -dw - 1, j - dh);
-               fgTileMgrLoadTile(&p2, &tiles[(j*FG_LOCAL_Y) + 0]);
-           }
-       }
-
-       if ( (p1.lat > p_last.lat) ||
-            ( (p1.lat == p_last.lat) && (p1.y > p_last.y) ) ) {
-           for ( i = 0; i < FG_LOCAL_X; i++ ) {
-               /* scrolling North */
-               for ( j = 0; j < FG_LOCAL_Y - 1; j++ ) {
-                   tiles[(j * FG_LOCAL_Y) + i] =
-                       tiles[((j+1) * FG_LOCAL_Y) + i];
-               }
-               /* load in new column */
-               fgBucketOffset(&p_last, &p2, i - dw, dh + 1);
-               fgTileMgrLoadTile(&p2, &tiles[((FG_LOCAL_Y-1)*FG_LOCAL_Y) + i]);
-           }
-       } else if ( (p1.lat < p_last.lat) ||
-                   ( (p1.lat == p_last.lat) && (p1.y < p_last.y) ) ) {
-           for ( i = 0; i < FG_LOCAL_X; i++ ) {
-               /* scrolling South */
-               for ( j = FG_LOCAL_Y - 1; j > 0; j-- ) {
-                   tiles[(j * FG_LOCAL_Y) + i] = 
-                       tiles[((j-1) * FG_LOCAL_Y) + i];
-               }
-               /* load in new column */
-               fgBucketOffset(&p_last, &p2, i - dw, -dh - 1);
-               fgTileMgrLoadTile(&p2, &tiles[0 + i]);
-           }
-       }
-    }
-    p_last.lon = p1.lon;
-    p_last.lat = p1.lat;
-    p_last.x = p1.x;
-    p_last.y = p1.y;
-    return 1;
-}
-
-
-/* Render the local tiles */
-void fgTileMgrRender( void ) {
-    fgFLIGHT *f;
-    struct fgBUCKET p;
-    struct fgCartesianPoint local_ref;
-    GLint display_list;
-    int i;
-    int index;
-
-    f = current_aircraft.flight;
-
-    /* Find current translation offset */
-    fgBucketFind(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p);
-    index = fgTileCacheExists(&p);
-    fgTileCacheEntryInfo(index, &display_list, &scenery.next_center );
-
-    printf("Pos = (%.2f, %.2f) Current bucket = %d %d %d %d  Index = %ld\n", 
-          FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG,
-          p.lon, p.lat, p.x, p.y, fgBucketGenIndex(&p) );
-
-    for ( i = 0; i < FG_LOCAL_X_Y; i++ ) {
-       index = tiles[i];
-       /* fgPrintf( FG_TERRAIN, FG_DEBUG, "Index = %d\n", index); */
-       fgTileCacheEntryInfo(index, &display_list, &local_ref );
-
-       if ( display_list >= 0 ) {
-           xglPushMatrix();
-           /* xglTranslatef(local_ref.x - scenery.center.x,
-                         local_ref.y - scenery.center.y,
-                         local_ref.z - scenery.center.z); */
-           xglTranslatef(-scenery.center.x, -scenery.center.y, 
-                         -scenery.center.z);
-           xglCallList(display_list);
-           xglPopMatrix();
-       }
-    }
-}
-
-
-/* $Log$
-/* Revision 1.25  1998/04/18 04:14:07  curt
-/* Moved fg_debug.c to it's own library.
-/*
- * Revision 1.24  1998/04/14 02:23:18  curt
- * Code reorganizations.  Added a Lib/ directory for more general libraries.
- *
- * Revision 1.23  1998/04/08 23:30:08  curt
- * Adopted Gnu automake/autoconf system.
- *
- * Revision 1.22  1998/04/03 22:11:38  curt
- * Converting to Gnu autoconf system.
- *
- * Revision 1.21  1998/03/23 21:23:05  curt
- * Debugging output tweaks.
- *
- * Revision 1.20  1998/03/14 00:30:51  curt
- * Beginning initial terrain texturing experiments.
- *
- * Revision 1.19  1998/02/20 00:16:25  curt
- * Thursday's tweaks.
- *
- * Revision 1.18  1998/02/19 13:05:54  curt
- * Incorporated some HUD tweaks from Michelle America.
- * Tweaked the sky's sunset/rise colors.
- * Other misc. tweaks.
- *
- * Revision 1.17  1998/02/16 13:39:46  curt
- * Miscellaneous weekend tweaks.  Fixed? a cache problem that caused whole
- * tiles to occasionally be missing.
- *
- * Revision 1.16  1998/02/12 21:59:53  curt
- * Incorporated code changes contributed by Charlie Hotchkiss
- * <chotchkiss@namg.us.anritsu.com>
- *
- * Revision 1.14  1998/02/09 21:30:19  curt
- * Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
- *
- * Revision 1.13  1998/02/07 15:29:46  curt
- * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
- * <chotchkiss@namg.us.anritsu.com>
- *
- * Revision 1.12  1998/02/01 03:39:55  curt
- * Minor tweaks.
- *
- * Revision 1.11  1998/01/31 00:43:27  curt
- * Added MetroWorks patches from Carmen Volpe.
- *
- * Revision 1.10  1998/01/29 00:51:40  curt
- * First pass at tile cache, dynamic tile loading and tile unloading now works.
- *
- * Revision 1.9  1998/01/27 03:26:44  curt
- * Playing with new fgPrintf command.
- *
- * Revision 1.8  1998/01/27 00:48:04  curt
- * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
- * system and commandline/config file processing code.
- *
- * Revision 1.7  1998/01/26 15:55:25  curt
- * Progressing on building dynamic scenery system.
- *
- * Revision 1.6  1998/01/24 00:03:30  curt
- * Initial revision.
- *
- * Revision 1.5  1998/01/19 19:27:18  curt
- * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
- * This should simplify things tremendously.
- *
- * Revision 1.4  1998/01/19 18:40:38  curt
- * Tons of little changes to clean up the code and to remove fatal errors
- * when building with the c++ compiler.
- *
- * Revision 1.3  1998/01/13 00:23:11  curt
- * Initial changes to support loading and management of scenery tiles.  Note,
- * there's still a fair amount of work left to be done.
- *
- * Revision 1.2  1998/01/08 02:22:27  curt
- * Continue working on basic features.
- *
- * Revision 1.1  1998/01/07 23:50:51  curt
- * "area" renamed to "tile"
- *
- * Revision 1.2  1998/01/07 03:29:29  curt
- * Given an arbitrary lat/lon, we can now:
- *   generate a unique index for the chunk containing the lat/lon
- *   generate a path name to the chunk file
- *   build a list of the indexes of all the nearby areas.
- *
- * Revision 1.1  1998/01/07 02:05:48  curt
- * Initial revision.
- * */
-
-
diff --git a/Scenery/tilemgr.cxx b/Scenery/tilemgr.cxx
new file mode 100644 (file)
index 0000000..eca8fee
--- /dev/null
@@ -0,0 +1,316 @@
+/* -*- Mode: C++ -*-
+ *
+ * tilemgr.c -- routines to handle dynamic management of scenery tiles
+ *
+ * Written by Curtis Olson, started January 1998.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#include <config.h>
+
+#ifdef HAVE_WINDOWS_H
+#  include <windows.h>
+#endif
+
+#include <GL/glut.h>
+#include <XGL/xgl.h>
+
+#include <Scenery/scenery.h>
+#include <Scenery/obj.h>
+#include <Scenery/tilecache.hxx>
+
+#include <Aircraft/aircraft.h>
+#include <Bucket/bucketutils.h>
+#include <Debug/fg_debug.h>
+#include <Include/fg_constants.h>
+#include <Include/fg_types.h>
+
+
+#define FG_LOCAL_X           7   /* should be odd */
+#define FG_LOCAL_Y           7   /* should be odd */
+#define FG_LOCAL_X_Y         49  /* At least FG_LOCAL_X times FG_LOCAL_Y */
+
+
+/* closest (potentially viewable) tiles, centered on current tile.
+ * This is an array of pointers to cache indexes. */
+int tiles[FG_LOCAL_X_Y];
+
+
+/* Initialize the Tile Manager subsystem */
+int fgTileMgrInit( void ) {
+    fgPrintf( FG_TERRAIN, FG_INFO, "Initializing Tile Manager subsystem.\n");
+    return 1;
+}
+
+
+/* load a tile */
+void fgTileMgrLoadTile( struct fgBUCKET *p, int *index) {
+    fgPrintf( FG_TERRAIN, FG_DEBUG, "Updating for bucket %d %d %d %d\n", 
+          p->lon, p->lat, p->x, p->y);
+    
+    /* if not in cache, load tile into the next available slot */
+    if ( (*index = fgTileCacheExists(p)) < 0 ) {
+       *index = fgTileCacheNextAvail();
+       fgTileCacheEntryFillIn(*index, p);
+    }
+
+    fgPrintf( FG_TERRAIN, FG_DEBUG, "Selected cache index of %d\n", *index);
+}
+
+
+/* given the current lon/lat, fill in the array of local chunks.  If
+ * the chunk isn't already in the cache, then read it from disk. */
+int fgTileMgrUpdate( void ) {
+    fgFLIGHT *f;
+    struct fgBUCKET p1, p2;
+    static struct fgBUCKET p_last = {-1000, 0, 0, 0};
+    int i, j, dw, dh;
+
+    f = current_aircraft.flight;
+
+    fgBucketFind(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p1);
+    dw = FG_LOCAL_X / 2;
+    dh = FG_LOCAL_Y / 2;
+
+    if ( (p1.lon == p_last.lon) && (p1.lat == p_last.lat) &&
+        (p1.x == p_last.x) && (p1.y == p_last.y) ) {
+       /* same bucket as last time */
+       fgPrintf( FG_TERRAIN, FG_DEBUG, "Same bucket as last time\n");
+    } else if ( p_last.lon == -1000 ) {
+       /* First time through, initialize the system and load all
+         * relavant tiles */
+
+       fgPrintf( FG_TERRAIN, FG_DEBUG, "First time through ... \n");
+       fgPrintf( FG_TERRAIN, FG_DEBUG, "Updating Tile list for %d,%d %d,%d\n",
+                 p1.lon, p1.lat, p1.x, p1.y);
+
+       /* wipe tile cache */
+       fgTileCacheInit();
+
+       /* build the local area list and update cache */
+       for ( j = 0; j < FG_LOCAL_Y; j++ ) {
+           for ( i = 0; i < FG_LOCAL_X; i++ ) {
+               fgBucketOffset(&p1, &p2, i - dw, j - dh);
+               fgTileMgrLoadTile(&p2, &tiles[(j*FG_LOCAL_Y) + i]);
+           }
+       }
+    } else {
+       /* We've moved to a new bucket, we need to scroll our
+         * structures, and load in the new tiles */
+
+       /* CURRENTLY THIS ASSUMES WE CAN ONLY MOVE TO ADJACENT TILES.
+           AT ULTRA HIGH SPEEDS THIS ASSUMPTION MAY NOT BE VALID IF
+           THE AIRCRAFT CAN SKIP A TILE IN A SINGLE ITERATION. */
+
+       if ( (p1.lon > p_last.lon) ||
+            ( (p1.lon == p_last.lon) && (p1.x > p_last.x) ) ) {
+           for ( j = 0; j < FG_LOCAL_Y; j++ ) {
+               /* scrolling East */
+               for ( i = 0; i < FG_LOCAL_X - 1; i++ ) {
+                   tiles[(j*FG_LOCAL_Y) + i] = tiles[(j*FG_LOCAL_Y) + i + 1];
+               }
+               /* load in new column */
+               fgBucketOffset(&p_last, &p2, dw + 1, j - dh);
+               fgTileMgrLoadTile(&p2, &tiles[(j*FG_LOCAL_Y) + FG_LOCAL_X - 1]);
+           }
+       } else if ( (p1.lon < p_last.lon) ||
+                   ( (p1.lon == p_last.lon) && (p1.x < p_last.x) ) ) {
+           for ( j = 0; j < FG_LOCAL_Y; j++ ) {
+               /* scrolling West */
+               for ( i = FG_LOCAL_X - 1; i > 0; i-- ) {
+                   tiles[(j*FG_LOCAL_Y) + i] = tiles[(j*FG_LOCAL_Y) + i - 1];
+               }
+               /* load in new column */
+               fgBucketOffset(&p_last, &p2, -dw - 1, j - dh);
+               fgTileMgrLoadTile(&p2, &tiles[(j*FG_LOCAL_Y) + 0]);
+           }
+       }
+
+       if ( (p1.lat > p_last.lat) ||
+            ( (p1.lat == p_last.lat) && (p1.y > p_last.y) ) ) {
+           for ( i = 0; i < FG_LOCAL_X; i++ ) {
+               /* scrolling North */
+               for ( j = 0; j < FG_LOCAL_Y - 1; j++ ) {
+                   tiles[(j * FG_LOCAL_Y) + i] =
+                       tiles[((j+1) * FG_LOCAL_Y) + i];
+               }
+               /* load in new column */
+               fgBucketOffset(&p_last, &p2, i - dw, dh + 1);
+               fgTileMgrLoadTile(&p2, &tiles[((FG_LOCAL_Y-1)*FG_LOCAL_Y) + i]);
+           }
+       } else if ( (p1.lat < p_last.lat) ||
+                   ( (p1.lat == p_last.lat) && (p1.y < p_last.y) ) ) {
+           for ( i = 0; i < FG_LOCAL_X; i++ ) {
+               /* scrolling South */
+               for ( j = FG_LOCAL_Y - 1; j > 0; j-- ) {
+                   tiles[(j * FG_LOCAL_Y) + i] = 
+                       tiles[((j-1) * FG_LOCAL_Y) + i];
+               }
+               /* load in new column */
+               fgBucketOffset(&p_last, &p2, i - dw, -dh - 1);
+               fgTileMgrLoadTile(&p2, &tiles[0 + i]);
+           }
+       }
+    }
+    p_last.lon = p1.lon;
+    p_last.lat = p1.lat;
+    p_last.x = p1.x;
+    p_last.y = p1.y;
+    return 1;
+}
+
+
+/* Render the local tiles */
+void fgTileMgrRender( void ) {
+    fgFLIGHT *f;
+    struct fgBUCKET p;
+    struct fgCartesianPoint local_ref;
+    GLint display_list;
+    int i;
+    int index;
+
+    f = current_aircraft.flight;
+
+    /* Find current translation offset */
+    fgBucketFind(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p);
+    index = fgTileCacheExists(&p);
+    fgTileCacheEntryInfo(index, &display_list, &scenery.next_center );
+
+    printf("Pos = (%.2f, %.2f) Current bucket = %d %d %d %d  Index = %ld\n", 
+          FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG,
+          p.lon, p.lat, p.x, p.y, fgBucketGenIndex(&p) );
+
+    for ( i = 0; i < FG_LOCAL_X_Y; i++ ) {
+       index = tiles[i];
+       /* fgPrintf( FG_TERRAIN, FG_DEBUG, "Index = %d\n", index); */
+       fgTileCacheEntryInfo(index, &display_list, &local_ref );
+
+       if ( display_list >= 0 ) {
+           xglPushMatrix();
+           /* xglTranslatef(local_ref.x - scenery.center.x,
+                         local_ref.y - scenery.center.y,
+                         local_ref.z - scenery.center.z); */
+           xglTranslatef(-scenery.center.x, -scenery.center.y, 
+                         -scenery.center.z);
+           xglCallList(display_list);
+           xglPopMatrix();
+       }
+    }
+}
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:22:48  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.25  1998/04/18 04:14:07  curt
+ * Moved fg_debug.c to it's own library.
+ *
+ * Revision 1.24  1998/04/14 02:23:18  curt
+ * Code reorganizations.  Added a Lib/ directory for more general libraries.
+ *
+ * Revision 1.23  1998/04/08 23:30:08  curt
+ * Adopted Gnu automake/autoconf system.
+ *
+ * Revision 1.22  1998/04/03 22:11:38  curt
+ * Converting to Gnu autoconf system.
+ *
+ * Revision 1.21  1998/03/23 21:23:05  curt
+ * Debugging output tweaks.
+ *
+ * Revision 1.20  1998/03/14 00:30:51  curt
+ * Beginning initial terrain texturing experiments.
+ *
+ * Revision 1.19  1998/02/20 00:16:25  curt
+ * Thursday's tweaks.
+ *
+ * Revision 1.18  1998/02/19 13:05:54  curt
+ * Incorporated some HUD tweaks from Michelle America.
+ * Tweaked the sky's sunset/rise colors.
+ * Other misc. tweaks.
+ *
+ * Revision 1.17  1998/02/16 13:39:46  curt
+ * Miscellaneous weekend tweaks.  Fixed? a cache problem that caused whole
+ * tiles to occasionally be missing.
+ *
+ * Revision 1.16  1998/02/12 21:59:53  curt
+ * Incorporated code changes contributed by Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * Revision 1.14  1998/02/09 21:30:19  curt
+ * Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
+ *
+ * Revision 1.13  1998/02/07 15:29:46  curt
+ * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * Revision 1.12  1998/02/01 03:39:55  curt
+ * Minor tweaks.
+ *
+ * Revision 1.11  1998/01/31 00:43:27  curt
+ * Added MetroWorks patches from Carmen Volpe.
+ *
+ * Revision 1.10  1998/01/29 00:51:40  curt
+ * First pass at tile cache, dynamic tile loading and tile unloading now works.
+ *
+ * Revision 1.9  1998/01/27 03:26:44  curt
+ * Playing with new fgPrintf command.
+ *
+ * Revision 1.8  1998/01/27 00:48:04  curt
+ * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
+ * system and commandline/config file processing code.
+ *
+ * Revision 1.7  1998/01/26 15:55:25  curt
+ * Progressing on building dynamic scenery system.
+ *
+ * Revision 1.6  1998/01/24 00:03:30  curt
+ * Initial revision.
+ *
+ * Revision 1.5  1998/01/19 19:27:18  curt
+ * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
+ * This should simplify things tremendously.
+ *
+ * Revision 1.4  1998/01/19 18:40:38  curt
+ * Tons of little changes to clean up the code and to remove fatal errors
+ * when building with the c++ compiler.
+ *
+ * Revision 1.3  1998/01/13 00:23:11  curt
+ * Initial changes to support loading and management of scenery tiles.  Note,
+ * there's still a fair amount of work left to be done.
+ *
+ * Revision 1.2  1998/01/08 02:22:27  curt
+ * Continue working on basic features.
+ *
+ * Revision 1.1  1998/01/07 23:50:51  curt
+ * "area" renamed to "tile"
+ *
+ * Revision 1.2  1998/01/07 03:29:29  curt
+ * Given an arbitrary lat/lon, we can now:
+ *   generate a unique index for the chunk containing the lat/lon
+ *   generate a path name to the chunk file
+ *   build a list of the indexes of all the nearby areas.
+ *
+ * Revision 1.1  1998/01/07 02:05:48  curt
+ * Initial revision.
+ * */
+
+
diff --git a/Scenery/tilemgr.h b/Scenery/tilemgr.h
deleted file mode 100644 (file)
index fb9b149..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/**************************************************************************
- * tilemgr.h -- routines to handle dynamic management of scenery tiles
- *
- * Written by Curtis Olson, started January 1998.
- *
- * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- * (Log is kept at end of this file)
- **************************************************************************/
-
-
-#ifndef _TILEMGR_H
-#define _TILEMGR_H
-
-
-#ifdef __cplusplus                                                          
-extern "C" {                            
-#endif                                   
-
-
-/* Initialize the Tile Manager subsystem */
-int fgTileMgrInit( void );
-
-
-/* given the current lon/lat, fill in the array of local chunks.  If
- * the chunk isn't already in the cache, then read it from disk. */
-int fgTileMgrUpdate( void );
-
-
-/* Render the local tiles --- hack, hack, hack */
-void fgTileMgrRender( void );
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _TILEMGR_H */
-
-
-/* $Log$
-/* Revision 1.6  1998/04/21 17:02:45  curt
-/* Prepairing for C++ integration.
-/*
- * Revision 1.5  1998/02/12 21:59:53  curt
- * Incorporated code changes contributed by Charlie Hotchkiss
- * <chotchkiss@namg.us.anritsu.com>
- *
- * Revision 1.4  1998/01/22 02:59:42  curt
- * Changed #ifdef FILE_H to #ifdef _FILE_H
- *
- * Revision 1.3  1998/01/19 18:40:38  curt
- * Tons of little changes to clean up the code and to remove fatal errors
- * when building with the c++ compiler.
- *
- * Revision 1.2  1998/01/13 00:23:11  curt
- * Initial changes to support loading and management of scenery tiles.  Note,
- * there's still a fair amount of work left to be done.
- *
- * Revision 1.1  1998/01/07 23:50:51  curt
- * "area" renamed to "tile"
- *
- * */
-
-
diff --git a/Scenery/tilemgr.hxx b/Scenery/tilemgr.hxx
new file mode 100644 (file)
index 0000000..5616df9
--- /dev/null
@@ -0,0 +1,79 @@
+/**************************************************************************
+ * tilemgr.hxx -- routines to handle dynamic management of scenery tiles
+ *
+ * Written by Curtis Olson, started January 1998.
+ *
+ * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ * (Log is kept at end of this file)
+ **************************************************************************/
+
+
+#ifndef _TILEMGR_HXX
+#define _TILEMGR_HXX
+
+
+#ifndef __cplusplus                                                          
+# error This library requires C++
+#endif                                   
+
+
+/* Initialize the Tile Manager subsystem */
+int fgTileMgrInit( void );
+
+
+/* given the current lon/lat, fill in the array of local chunks.  If
+ * the chunk isn't already in the cache, then read it from disk. */
+int fgTileMgrUpdate( void );
+
+
+/* Render the local tiles --- hack, hack, hack */
+void fgTileMgrRender( void );
+
+
+#endif /* _TILEMGR_HXX */
+
+
+/* $Log$
+/* Revision 1.1  1998/04/22 13:22:49  curt
+/* C++ - ifing the code a bit.
+/*
+ * Revision 1.6  1998/04/21 17:02:45  curt
+ * Prepairing for C++ integration.
+ *
+ * Revision 1.5  1998/02/12 21:59:53  curt
+ * Incorporated code changes contributed by Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * Revision 1.4  1998/01/22 02:59:42  curt
+ * Changed #ifdef FILE_H to #ifdef _FILE_H
+ *
+ * Revision 1.3  1998/01/19 18:40:38  curt
+ * Tons of little changes to clean up the code and to remove fatal errors
+ * when building with the c++ compiler.
+ *
+ * Revision 1.2  1998/01/13 00:23:11  curt
+ * Initial changes to support loading and management of scenery tiles.  Note,
+ * there's still a fair amount of work left to be done.
+ *
+ * Revision 1.1  1998/01/07 23:50:51  curt
+ * "area" renamed to "tile"
+ *
+ * */
+
+