From 1b14d433419fa0c9e2fbe5cc3c53990a289b968a Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 16 May 1997 15:51:13 +0000 Subject: [PATCH 001/123] Initial revision. From 0c270d61d85e818fefdb5be155c79e0b743c347c Mon Sep 17 00:00:00 2001 From: curt Date: Sat, 25 Oct 1997 03:16:08 +0000 Subject: [PATCH 002/123] Initial revision of code contributed by Durk Talsma. --- Scenery/moon.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++ Scenery/moon.h | 54 +++++++++++++++ Scenery/orbits.c | 170 +++++++++++++++++++++++++++++++++++++++++++++ Scenery/orbits.h | 85 +++++++++++++++++++++++ Scenery/planets.c | 91 ++++++++++++++++++++++++ Scenery/planets.h | 41 +++++++++++ Scenery/sun.c | 61 +++++++++++++++++ Scenery/sun.h | 40 +++++++++++ 8 files changed, 713 insertions(+) create mode 100644 Scenery/moon.c create mode 100644 Scenery/moon.h create mode 100644 Scenery/orbits.c create mode 100644 Scenery/orbits.h create mode 100644 Scenery/planets.c create mode 100644 Scenery/planets.h create mode 100644 Scenery/sun.c create mode 100644 Scenery/sun.h diff --git a/Scenery/moon.c b/Scenery/moon.c new file mode 100644 index 00000000..9b10b3c1 --- /dev/null +++ b/Scenery/moon.c @@ -0,0 +1,171 @@ +/************************************************************************** + * moon.c + * + * 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 +#include + +#include "orbits.h" +#include "moon.h" + +#include "../Time/fg_time.h" +#include "../GLUT/views.h" +/* #include "../Aircraft/aircraft.h"*/ +#include "../general.h" + + +static GLint moon; + +struct CelestialCoord fgCalculateMoon(struct OrbElements params, + struct OrbElements sunParams, + struct fgTIME t) +{ + struct CelestialCoord + result; + + double + eccAnom, ecl, lonecl, latecl, actTime, + xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze, + Ls, Lm, D, F; + + /* calculate the angle between ecliptic and equatorial coordinate system */ + actTime = fgCalcActTime(t); + ecl = fgDegToRad(23.4393 - 3.563E-7 * actTime); // in radians of course + + /* calculate the eccentric anomaly */ + eccAnom = fgCalcEccAnom(params.M, params.e); + + /* calculate the moon's distance (d) 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 */ + Ls = sunParams.M + sunParams.w; + Lm = params.M + params.w + params.N; + D = Lm - Ls; + F = Lm - params.N; + + lonecl += fgDegToRad( + - 1.274 * sin (params.M - 2*D) // the Evection + + 0.658 * sin (2 * D) // the Variation + - 0.186 * sin (sunParams.M) // the yearly variation + - 0.059 * sin (2*params.M - 2*D) + - 0.057 * sin (params.M - 2*D + sunParams.M) + + 0.053 * sin (params.M + 2*D) + + 0.046 * sin (2*D - sunParams.M) + + 0.041 * sin (params.M - sunParams.M) + - 0.035 * sin (D) // the Parallactic Equation + - 0.031 * sin (params.M + sunParams.M) + - 0.015 * sin (2*F - 2*D) + + 0.011 * sin (params.M - 4*D) + ); /* Pheeuuwwww */ + latecl += fgDegToRad( + - 0.173 * sin (F - 2*D) + - 0.055 * sin (params.M - F - 2*D) + - 0.046 * sin (params.M + F - 2*D) + + 0.033 * sin (F + 2*D) + + 0.017 * sin (2 * params.M + F) + ); /* Yep */ + + 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); + + result.RightAscension = atan2(ye, xe); + result.Declination = atan2(ze, sqrt(xe*xe + ye*ye)); + + return result; +} + + +void fgMoonInit() +{ + struct CelestialCoord + moonPos; + + moon = glGenLists(1); + glNewList(moon, GL_COMPILE ); + glBegin( GL_POINTS ); + moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], cur_time_params); + printf("Moon found at %f (ra), %f (dec)\n", moonPos.RightAscension, moonPos.Declination); + /* give the moon a temporary color, for testing purposes */ + glColor3f( 0.0, 1.0, 0.0); + glVertex3f( 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination), + 190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination), + 190000.0 * sin(moonPos.Declination) ); + glEnd(); + glEndList(); +} + +void fgMoonRender() +{ + double angle; + static double warp = 0; + struct VIEW *v; + struct fgTIME *t; + + t = &cur_time_params; + v = ¤t_view; + + + glDisable( GL_FOG ); + glDisable( GL_LIGHTING ); + glPushMatrix(); + glTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z ); + angle = t->gst * 15.0; /* 15 degrees per hour rotation */ + /* warp += 1.0; */ + /* warp = 15.0; */ + warp = 0.0; + glRotatef( (angle+warp), 0.0, 0.0, -1.0 ); + printf("Rotating moon by %.2f degrees + %.2f degrees\n",angle,warp); + + glCallList(moon); + + glPopMatrix(); + glEnable( GL_LIGHTING ); + glEnable( GL_FOG ); +} + + +/* $Log$ +/* Revision 1.1 1997/10/25 03:16:08 curt +/* Initial revision of code contributed by Durk Talsma. +/* + */ diff --git a/Scenery/moon.h b/Scenery/moon.h new file mode 100644 index 00000000..c43f6dca --- /dev/null +++ b/Scenery/moon.h @@ -0,0 +1,54 @@ +/************************************************************************** + * 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_ + + +#include "orbits.h" + +#include "../Time/fg_time.h" + + + /* Initialize the Moon Display management Subsystem */ +void fgMoonInit(); + +/* Draw the Stars */ + +void fgMoonRender(); +struct CelestialCoord fgCalculateMoon(struct OrbElements Params, + struct OrbElements sunParams, + struct fgTIME t); + +extern struct OrbElements pltOrbElements[9]; + + +#endif /* _MOON_H_ */ + + +/* $Log$ +/* Revision 1.1 1997/10/25 03:16:09 curt +/* Initial revision of code contributed by Durk Talsma. +/* + */ diff --git a/Scenery/orbits.c b/Scenery/orbits.c new file mode 100644 index 00000000..9440b756 --- /dev/null +++ b/Scenery/orbits.c @@ -0,0 +1,170 @@ +/************************************************************************** + * 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 + +#include "orbits.h" + +#include "../general.h" +#include "../Time/fg_time.h" + + +struct OrbElements pltOrbElements[9]; + + +double fgCalcActTime(struct fgTIME t) +{ + double + actTime, UT; + int year; + + /* a hack. This one introduces the 2000 problem into the program */ + year = t.gmt->tm_year + 1900; + + /* calculate the actual time */ + actTime = 367 * year - 7 * + (year + (t.gmt->tm_mon + 9) / 12) / 4 + 275 * + t.gmt->tm_mon / 9 + t.gmt->tm_mday - 730530; + + UT = t.gmt->tm_hour + ((double) t.gmt->tm_min / 60); + /*printf("UT = %f\n", UT); */ + actTime += (UT / 24.0); + printf("current day = %f\t", actTime); + printf("GMT = %d, %d, %d, %d, %d, %d\n", year, t.gmt->tm_mon, t.gmt->tm_mday, + t.gmt->tm_hour, t.gmt->tm_min, t.gmt->tm_sec); + return actTime; +} + +/* convert degrees to radians */ +double fgDegToRad(double angle) +{ + return (angle * PIOVER180); +} + +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 = abs(E0 - E1); + E0 = E1; + } + while (diff > fgDegToRad(0.001)); + return E0; + } + return eccAnom; +} + + + +void fgReadOrbElements(struct OrbElements *dest, FILE *src) +{ + char line[256]; + int i,j; + j = 0; + do + { + 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); +} + + +void fgSolarSystemInit(struct fgTIME t) +{ + struct GENERAL *g; + char path[80]; + int i; + FILE *data; + + /* 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 ) + { + printf("Cannot open data file: '%s'\n", path); + return; + } + printf("reading datafile %s", path); + + /* for all the objects... */ + for (i = 0; i < 9; i ++) + { + /* ...read from the data file ... */ + fgReadOrbElements(&pltOrbElements[i], data); + /* ...and calculate the actual values */ + fgSolarSystemUpdate(&pltOrbElements[i], t); + } + +} + + +void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t) +{ + double + actTime; + + actTime = fgCalcActTime(t); + + /* calculate the actual orbital elements */ + planet->M = fgDegToRad(planet->MFirst + (planet->MSec * actTime)); // angle in radians + planet->w = fgDegToRad(planet->wFirst + (planet->wSec * actTime)); // angle in radians + planet->N = fgDegToRad(planet->NFirst + (planet->NSec * actTime)); // angle in radians + planet->i = fgDegToRad(planet->iFirst + (planet->iSec * actTime)); // angle in radians + planet->e = planet->eFirst + (planet->eSec * actTime); + planet->a = planet->aFirst + (planet->aSec * actTime); +} + + +/* $Log$ +/* Revision 1.1 1997/10/25 03:16:10 curt +/* Initial revision of code contributed by Durk Talsma. +/* + */ diff --git a/Scenery/orbits.h b/Scenery/orbits.h new file mode 100644 index 00000000..2ce03b12 --- /dev/null +++ b/Scenery/orbits.h @@ -0,0 +1,85 @@ +/************************************************************************** + * 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 + + +#include +#include + +#include "../Time/fg_time.h" + + + +#define STANDARDEPOCH 2000 +#define PIOVER180 1.74532925199433E-002 + +struct SunPos { + double xs; + double ys; +}; + +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 fgDegToRad(double angle); +double fgCalcEccAnom(double M, double e); +double fgCalcActTime(struct fgTIME t); + +void fgReadOrbElements(struct OrbElements *dest, FILE *src); +void fgSolarSystemInit(struct fgTIME t); +void fgSolarSystemUpdate(struct OrbElements *planets, struct fgTIME t); + + +#endif /* ORBITS_H */ + + +/* $Log$ +/* Revision 1.1 1997/10/25 03:16:10 curt +/* Initial revision of code contributed by Durk Talsma. +/* + */ diff --git a/Scenery/planets.c b/Scenery/planets.c new file mode 100644 index 00000000..9f7911a0 --- /dev/null +++ b/Scenery/planets.c @@ -0,0 +1,91 @@ +/************************************************************************** + * 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 "../Time/fg_time.h" +#include "orbits.h" +#include "planets.h" +#include "sun.h" + + +struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, + struct OrbElements sun, + struct fgTIME t) +{ + struct CelestialCoord + result; + + struct SunPos + SolarPosition; + + double + eccAnom, r, v, ecl, actTime, + xv, yv, xh, yh, zh, xg, yg, zg, xe, ye, ze; + + actTime = fgCalcActTime(t); + /* calculate the angle between ecliptic and equatorial coordinate system */ + ecl = fgDegToRad(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 ecleptic longitude and latitude */ + + /* + lonecl = atan2(yh, xh); + latecl = atan2(zh, sqrt ( xh*xh + yh*yh)); + */ + /* calculate the solar position */ + + SolarPosition = fgCalcSunPos(sun); + 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)); + return result; +} + + +/* $Log$ +/* Revision 1.1 1997/10/25 03:16:10 curt +/* Initial revision of code contributed by Durk Talsma. +/* + */ diff --git a/Scenery/planets.h b/Scenery/planets.h new file mode 100644 index 00000000..e0ce0541 --- /dev/null +++ b/Scenery/planets.h @@ -0,0 +1,41 @@ +/************************************************************************** + * 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 + + +struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, + struct OrbElements sun, + struct fgTIME t); + +#endif /* PLANETS_H */ + + +/* $Log$ +/* Revision 1.1 1997/10/25 03:16:11 curt +/* Initial revision of code contributed by Durk Talsma. +/* + */ diff --git a/Scenery/sun.c b/Scenery/sun.c new file mode 100644 index 00000000..6f1a213f --- /dev/null +++ b/Scenery/sun.c @@ -0,0 +1,61 @@ +/************************************************************************** + * 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 "../Time/fg_time.h" +#include "orbits.h" + +struct SunPos fgCalcSunPos(struct OrbElements params) +{ + double + EccAnom, lonSun, + xv, yv, v, r; + struct SunPos + solarPosition; + + /* 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 Suns true longitude (lonsun) */ + lonSun = v + params.w; + + /* convert true longitude and distance to ecliptic rectangular geocentric + coordinates (xs, ys) */ + solarPosition.xs = r * cos(lonSun); + solarPosition.ys = r * sin(lonSun); + return solarPosition; +} + + +/* $Log$ +/* Revision 1.1 1997/10/25 03:16:11 curt +/* Initial revision of code contributed by Durk Talsma. +/* + */ diff --git a/Scenery/sun.h b/Scenery/sun.h new file mode 100644 index 00000000..5082a67c --- /dev/null +++ b/Scenery/sun.h @@ -0,0 +1,40 @@ +/************************************************************************** + * 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 + + +struct SunPos fgCalcSunPos(struct OrbElements sunParams); + + +#endif /* SUN_H */ + + +/* $Log$ +/* Revision 1.1 1997/10/25 03:16:12 curt +/* Initial revision of code contributed by Durk Talsma. +/* + */ From 3c35a317d49cecd55bc90e8f21c07a2e0ef000d1 Mon Sep 17 00:00:00 2001 From: curt Date: Sat, 25 Oct 1997 03:24:21 +0000 Subject: [PATCH 003/123] Incorporated sun, moon, and star positioning code contributed by Durk Talsma. --- Scenery/moon.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Scenery/moon.h b/Scenery/moon.h index c43f6dca..b23ae4e3 100644 --- a/Scenery/moon.h +++ b/Scenery/moon.h @@ -35,8 +35,8 @@ void fgMoonInit(); /* Draw the Stars */ - void fgMoonRender(); + struct CelestialCoord fgCalculateMoon(struct OrbElements Params, struct OrbElements sunParams, struct fgTIME t); @@ -48,7 +48,10 @@ extern struct OrbElements pltOrbElements[9]; /* $Log$ -/* Revision 1.1 1997/10/25 03:16:09 curt -/* Initial revision of code contributed by Durk Talsma. +/* 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. + * */ From 5730a47b00186a7ccb66bbac57bae2b5a7b9488f Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 28 Oct 1997 21:00:20 +0000 Subject: [PATCH 004/123] Changing to new terrain format. --- Scenery/moon.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Scenery/moon.c b/Scenery/moon.c index 9b10b3c1..859563a5 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -26,8 +26,8 @@ #include "orbits.h" #include "moon.h" +#include "../Main/views.h" #include "../Time/fg_time.h" -#include "../GLUT/views.h" /* #include "../Aircraft/aircraft.h"*/ #include "../general.h" @@ -165,7 +165,10 @@ void fgMoonRender() /* $Log$ -/* Revision 1.1 1997/10/25 03:16:08 curt -/* Initial revision of code contributed by Durk Talsma. +/* Revision 1.2 1997/10/28 21:00:21 curt +/* Changing to new terrain format. /* + * Revision 1.1 1997/10/25 03:16:08 curt + * Initial revision of code contributed by Durk Talsma. + * */ From b6f07f3058b3fd680df4419ea784c52eac5db467 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 25 Nov 1997 19:25:27 +0000 Subject: [PATCH 005/123] Changes to integrate Durk's moon/sun code updates + clean up. --- Scenery/moon.c | 218 +++++++++++++++++++++++++++++++++++------------ Scenery/moon.h | 13 ++- Scenery/orbits.c | 19 +++-- Scenery/sun.c | 154 +++++++++++++++++++++++++++++++-- Scenery/sun.h | 15 +++- 5 files changed, 348 insertions(+), 71 deletions(-) diff --git a/Scenery/moon.c b/Scenery/moon.c index 859563a5..56788d65 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -1,5 +1,6 @@ /************************************************************************** * 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 @@ -26,13 +27,123 @@ #include "orbits.h" #include "moon.h" +#include "../general.h" #include "../Main/views.h" #include "../Time/fg_time.h" -/* #include "../Aircraft/aircraft.h"*/ -#include "../general.h" + +struct CelestialCoord + moonPos; + +float xMoon, yMoon, zMoon; + +/* +static GLfloat vdata[12][3] = +{ + {-X, 0.0, Z }, { X, 0.0, Z }, {-X, 0.0, -Z}, {X, 0.0, -Z }, + { 0.0, Z, X }, { 0.0, Z, -X}, {0.0, -Z, -X}, {0.0, -Z, -X}, + { Z, X, 0.0 }, { -Z, X, 0.0}, {Z, -X, 0.0 }, {-Z, -X, 0.0} +}; + +static GLuint tindices[20][3] = +{ + {0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1}, + {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3}, + {7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6}, + {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} +};*/ + +GLint moon; + +/* ------------------------------------------------------------- + This section contains the code that generates a yellow + Icosahedron. It's under development... (of Course) +______________________________________________________________*/ +/* +void NormalizeVector(float v[3]) +{ + GLfloat d = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + if (d == 0.0) + { + printf("zero length vector\n"); + return; + } + v[0] /= d; + v[1] /= d; + v[2] /= d; +} + +void drawTriangle(float *v1, float *v2, float *v3) +{ + glBegin(GL_POLYGON); + //glBegin(GL_POINTS); + glNormal3fv(v1); + glVertex3fv(v1); + glNormal3fv(v2); + glVertex3fv(v2); + glNormal3fv(v3); + glVertex3fv(v3); + glEnd(); +} + +void subdivide(float *v1, float *v2, float *v3, long depth) +{ + GLfloat v12[3], v23[3], v31[3]; + GLint i; + + if (!depth) + { + drawTriangle(v1, v2, v3); + return; + } + for (i = 0; i < 3; i++) + { + v12[i] = (v1[i] + v2[i]); + v23[i] = (v2[i] + v3[i]); + v31[i] = (v3[i] + v1[i]); + } + NormalizeVector(v12); + NormalizeVector(v23); + NormalizeVector(v31); + subdivide(v1, v12, v31, depth - 1); + subdivide(v2, v23, v12, depth - 1); + subdivide(v3, v31, v23, depth - 1); + subdivide(v12, v23, v31,depth - 1); + +} */ +/* +void display(void) +{ + int i; + glClear(GL_COLOR_BUFFER_BIT); + glPushMatrix(); + glRotatef(spin, 0.0, 0.0, 0.0); + glColor3f(1.0, 1.0, 0.0); +// glBegin(GL_LINE_LOOP); + for (i = 0; i < 20; i++) + { + + //glVertex3fv(&vdata[tindices[i][0]][0]); + //glVertex3fv(&vdata[tindices[i][1]][0]); + //glVertex3fv(&vdata[tindices[i][2]][0]); + + subdivide(&vdata[tindices[i][0]][0], + &vdata[tindices[i][1]][0], + &vdata[tindices[i][2]][0], 3); -static GLint moon; + } +// glEnd(); + // glFlush(); + glPopMatrix(); + glutSwapBuffers(); +} */ + +/* -------------------------------------------------------------- + + 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, @@ -42,7 +153,7 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, result; double - eccAnom, ecl, lonecl, latecl, actTime, + eccAnom, ecl, lonecl, latecl, actTime, xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze, Ls, Lm, D, F; @@ -54,7 +165,7 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, eccAnom = fgCalcEccAnom(params.M, params.e); /* calculate the moon's distance (d) and true anomaly (v) */ - xv = params.a * ( cos(eccAnom) - params.e); + 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); @@ -75,7 +186,7 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, F = Lm - params.N; lonecl += fgDegToRad( - - 1.274 * sin (params.M - 2*D) // the Evection + - 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) @@ -97,9 +208,10 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, ); /* Yep */ r += ( - - 0.58 * cos(params.M - 2*D) + - 0.58 * cos(params.M - 2*D) - 0.46 * cos(2*D) - ); + ); /* Ok! */ + xg = r * cos(lonecl) * cos(latecl); yg = r * sin(lonecl) * cos(latecl); zg = r * sin(latecl); @@ -108,67 +220,63 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, ye = yg * cos(ecl) - zg * sin(ecl); ze = yg * sin(ecl) + zg * cos(ecl); - result.RightAscension = atan2(ye, xe); + result.RightAscension = atan2(ye, xe); result.Declination = atan2(ze, sqrt(xe*xe + ye*ye)); - return result; } void fgMoonInit() { - struct CelestialCoord - moonPos; +// int i; +// moon = glGenLists(1); +// glNewList(moon, GL_COMPILE ); - moon = glGenLists(1); - glNewList(moon, GL_COMPILE ); - glBegin( GL_POINTS ); + fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params); moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], cur_time_params); + #ifdef DEBUG printf("Moon found at %f (ra), %f (dec)\n", moonPos.RightAscension, moonPos.Declination); - /* give the moon a temporary color, for testing purposes */ - glColor3f( 0.0, 1.0, 0.0); - glVertex3f( 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination), - 190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination), - 190000.0 * sin(moonPos.Declination) ); - glEnd(); - glEndList(); -} + #endif + glColor3f(1.0, 1.0, 0.0); -void fgMoonRender() -{ - double angle; - static double warp = 0; - struct VIEW *v; - struct fgTIME *t; + /* xMoon = 90000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination); + yMoon = 90000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); + zMoon = 90000.0 * sin(moonPos.Declination); */ - t = &cur_time_params; - v = ¤t_view; + xMoon = 60000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination); + yMoon = 60000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); + zMoon = 60000.0 * sin(moonPos.Declination); +// glPushMatrix(); +// glBegin(GL_TRIANGLES); + /* + for (i = 0; i < 20; i++) + subdivide(&vdata[tindices[i][0]][0], + &vdata[tindices[i][1]][0], + &vdata[tindices[i][2]][0], 3);*/ +// glutSolidSphere(1.0, 25, 25); - glDisable( GL_FOG ); - glDisable( GL_LIGHTING ); - glPushMatrix(); - glTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z ); - angle = t->gst * 15.0; /* 15 degrees per hour rotation */ - /* warp += 1.0; */ - /* warp = 15.0; */ - warp = 0.0; - glRotatef( (angle+warp), 0.0, 0.0, -1.0 ); - printf("Rotating moon by %.2f degrees + %.2f degrees\n",angle,warp); - - glCallList(moon); - - glPopMatrix(); - glEnable( GL_LIGHTING ); - glEnable( GL_FOG ); +// glEnd(); +// glPopMatrix(); +// glEndList(); } -/* $Log$ -/* Revision 1.2 1997/10/28 21:00:21 curt -/* Changing to new terrain format. -/* - * Revision 1.1 1997/10/25 03:16:08 curt - * Initial revision of code contributed by Durk Talsma. - * - */ +/* Draw the moon */ +void fgMoonRender() { + GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 }; + + /* set lighting parameters */ + glLightfv(GL_LIGHT0, GL_AMBIENT, color ); + glLightfv(GL_LIGHT0, GL_DIFFUSE, color ); + glMaterialfv(GL_FRONT, GL_AMBIENT, fgClearColor); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color); + + glPushMatrix(); + glTranslatef(xMoon, yMoon, zMoon); + glScalef(1400, 1400, 1400); + /* glutSolidSphere(1.0, 25, 25); */ + glutSolidSphere(1.0, 15, 15); + glPopMatrix(); +} + diff --git a/Scenery/moon.h b/Scenery/moon.h index b23ae4e3..8c0ae98b 100644 --- a/Scenery/moon.h +++ b/Scenery/moon.h @@ -29,6 +29,10 @@ #include "orbits.h" #include "../Time/fg_time.h" +#include + +#define X .525731112119133606 +#define Z .850650808352039932 /* Initialize the Moon Display management Subsystem */ @@ -42,15 +46,18 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements Params, struct fgTIME t); extern struct OrbElements pltOrbElements[9]; - +extern GLfloat fgClearColor[4]; #endif /* _MOON_H_ */ /* $Log$ -/* Revision 1.2 1997/10/25 03:24:23 curt -/* Incorporated sun, moon, and star positioning code contributed by Durk Talsma. +/* 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/Scenery/orbits.c b/Scenery/orbits.c index 9440b756..c2618561 100644 --- a/Scenery/orbits.c +++ b/Scenery/orbits.c @@ -43,17 +43,21 @@ double fgCalcActTime(struct fgTIME t) /* a hack. This one introduces the 2000 problem into the program */ year = t.gmt->tm_year + 1900; - /* calculate the actual time */ + /* calculate the actual time, rember to add 1 to tm_mon! */ actTime = 367 * year - 7 * - (year + (t.gmt->tm_mon + 9) / 12) / 4 + 275 * - t.gmt->tm_mon / 9 + t.gmt->tm_mday - 730530; + (year + ((t.gmt->tm_mon+1) + 9) / 12) / 4 + 275 * + (t.gmt->tm_mon+1) / 9 + t.gmt->tm_mday - 730530; UT = t.gmt->tm_hour + ((double) t.gmt->tm_min / 60); /*printf("UT = %f\n", UT); */ actTime += (UT / 24.0); + #define DEBUG 1 + #ifdef DEBUG + printf("Actual Time:\n"); printf("current day = %f\t", actTime); printf("GMT = %d, %d, %d, %d, %d, %d\n", year, t.gmt->tm_mon, t.gmt->tm_mday, t.gmt->tm_hour, t.gmt->tm_min, t.gmt->tm_sec); + #endif return actTime; } @@ -132,7 +136,9 @@ void fgSolarSystemInit(struct fgTIME t) printf("Cannot open data file: '%s'\n", path); return; } + #ifdef DEBUG printf("reading datafile %s", path); + #endif /* for all the objects... */ for (i = 0; i < 9; i ++) @@ -164,7 +170,10 @@ void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t) /* $Log$ -/* Revision 1.1 1997/10/25 03:16:10 curt -/* Initial revision of code contributed by Durk Talsma. +/* 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/Scenery/sun.c b/Scenery/sun.c index 6f1a213f..92e022f6 100644 --- a/Scenery/sun.c +++ b/Scenery/sun.c @@ -22,9 +22,18 @@ * (Log is kept at end of this file) **************************************************************************/ - +#include #include "../Time/fg_time.h" +#include "../Main/views.h" #include "orbits.h" +#include "sun.h" + +GLint sun; + +static struct CelestialCoord + sunPos; + +float xSun, ySun, zSun; struct SunPos fgCalcSunPos(struct OrbElements params) { @@ -38,24 +47,157 @@ struct SunPos fgCalcSunPos(struct OrbElements params) EccAnom = fgCalcEccAnom(params.M, params.e); /* calculate the Suns distance (r) and its true anomaly (v) */ - xv = cos(EccAnom) - params.e; + 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 Suns true longitude (lonsun) */ + /* calculate the the Sun's true longitude (lonsun) */ lonSun = v + params.w; /* convert true longitude and distance to ecliptic rectangular geocentric - coordinates (xs, ys) */ + coordinates (xs, ys) */ solarPosition.xs = r * cos(lonSun); solarPosition.ys = r * sin(lonSun); return solarPosition; } +struct CelestialCoord fgCalculateSun(struct OrbElements params, struct fgTIME t) +{ + struct CelestialCoord + result; + struct SunPos + SolarPosition; + double + xe, ye, ze, ecl, actTime; + + /* calculate the angle between ecliptic and equatorial coordinate system */ + actTime = fgCalcActTime(t); + ecl = fgDegToRad(23.4393 - 3.563E-7 * actTime); // Angle now in Rads + + /* calculate the sun's ecliptic position */ + SolarPosition = 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() +{ +// int i; +// sun = glGenLists(1); +// glNewList(sun, GL_COMPILE ); +// glBegin( GL_POINTS ); + fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params); + sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params); + #ifdef DEBUG + printf("Sun found at %f (ra), %f (dec)\n", sunPos.RightAscension, sunPos.Declination); + #endif + /* give the moon a temporary color, for testing purposes */ +// glColor3f( 0.0, 1.0, 0.0); +// glVertex3f( 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination), + // 190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination), +// 190000.0 * sin(moonPos.Declination) ); + //glVertex3f(0.0, 0.0, 0.0); +// glEnd(); +// glColor3f(1.0, 1.0, 1.0); + //xMoon = 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination); + //yMoon = 190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); + //zMoon = 190000.0 * sin(moonPos.Declination); + xSun = 60000.0 * cos(sunPos.RightAscension) * cos(sunPos.Declination); + ySun = 60000.0 * sin(sunPos.RightAscension) * cos(sunPos.Declination); + zSun = 60000.0 * sin(sunPos.Declination); + +// glPushMatrix(); +// glTranslatef(x, y, z); +// glScalef(16622.8, 16622.8, 16622.8); +// glBegin(GL_TRIANGLES); +// for (i = 0; i < 20; i++) +// subdivide(&vdata[tindices[i][0]][0], +// &vdata[tindices[i][1]][0], +// &vdata[tindices[i][2]][0], 3); +// glutSolidSphere(1.0, 25, 25); + +// glEnd(); + //glPopMatrix(); +// glEndList(); +} + + +/* Draw the Sun */ +void fgSunRender() { + struct VIEW *v; + struct fgTIME *t; + GLfloat color[4] = { 0.85, 0.65, 0.05, 1.0 }; + /* double x_2, x_4, x_8, x_10; */ + /* GLfloat ambient; */ + /* GLfloat amb[3], diff[3]; */ + + + t = &cur_time_params; + v = ¤t_view; + + /* x_2 = t->sun_angle * t->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.50 + ((ambient * 6.66) - 1.6); + amb[1] = 0.00 + ((ambient * 6.66) - 1.6); + amb[2] = 0.00 + ((ambient * 6.66) - 1.6); + amb[3] = 0.00; +#ifdef DEBUG + printf("Color of the sun: %f, %f, %f\n" + "Ambient value : %f\n" + "Sun Angle : %f\n" , amb[0], amb[1], amb[2], ambient, t->sun_angle); +#endif + diff[0] = 0.0; + diff[1] = 0.0; + diff[2] = 0.0; + diff[3] = 0.0; */ + + /* set lighting parameters */ + /* glLightfv(GL_LIGHT0, GL_AMBIENT, color ); + glLightfv(GL_LIGHT0, GL_DIFFUSE, color ); + glMaterialfv(GL_FRONT, GL_AMBIENT, amb); + glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); */ + + glDisable( GL_LIGHTING ); + glPushMatrix(); + glTranslatef(xSun, ySun, zSun); + glScalef(1400, 1400, 1400); + glColor3fv( color ); + /* glutSolidSphere(1.0, 25, 25); */ + glutSolidSphere(1.0, 10, 10); + //glCallList(sun); + glPopMatrix(); + glEnable( GL_LIGHTING ); +} + + /* $Log$ -/* Revision 1.1 1997/10/25 03:16:11 curt -/* Initial revision of code contributed by Durk Talsma. +/* 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/Scenery/sun.h b/Scenery/sun.h index 5082a67c..fe06244f 100644 --- a/Scenery/sun.h +++ b/Scenery/sun.h @@ -28,13 +28,24 @@ struct SunPos fgCalcSunPos(struct OrbElements sunParams); +extern struct OrbElements pltOrbElements[9]; +extern GLfloat fgClearColor[4]; + +/* Initialize the Sun */ +void fgSunInit(); + +/* Draw the Sun */ +void fgSunRender(); #endif /* SUN_H */ /* $Log$ -/* Revision 1.1 1997/10/25 03:16:12 curt -/* Initial revision of code contributed by Durk Talsma. +/* 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. + * */ From 8feb45fa729529f575c68baa1cace3cb31524adb Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 25 Nov 1997 23:20:22 +0000 Subject: [PATCH 006/123] Initial revision. --- Scenery/astro.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++ Scenery/astro.h | 55 +++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 Scenery/astro.c create mode 100644 Scenery/astro.h diff --git a/Scenery/astro.c b/Scenery/astro.c new file mode 100644 index 00000000..a9534696 --- /dev/null +++ b/Scenery/astro.c @@ -0,0 +1,125 @@ +/************************************************************************** + * astro.c + * + * Written by Durk Talsma. Started November 1997, for use with 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 +#include +#include +#include + +#include + +#include "astro.h" +#include "moon.h" +#include "orbits.h" +#include "planets.h" +#include "stars.h" +#include "sun.h" + +#include "../constants.h" +#include "../general.h" + +#include "../Main/views.h" +#include "../Aircraft/aircraft.h" +#include "../Time/fg_time.h" + +static double prevUpdate = 0; + + +/* Initialize Astronomical Objects */ +void fgAstroInit() { + struct fgTIME *t; + t = &cur_time_params; + + /* Initialize the orbital elements of sun, moon and mayor planets */ + fgSolarSystemInit(*t); + + /* Intialize the moon's position */ + fgMoonInit(); + + /* Initialize the sun's position */ + fgSunInit(); + + /* Initialize the Stars subsystem */ + fgStarsInit(); +} + + +/* Render Astronomical Objects */ +void fgAstroRender() { + struct FLIGHT *f; + struct VIEW *v; + struct fgTIME *t; + double angle; + + f = ¤t_aircraft.flight; + t = &cur_time_params; + v = ¤t_view; + + /* a hack: Force sun and moon position to be updated on an hourly basis */ + if (((t->gst - prevUpdate) > 1) || (t->gst < prevUpdate)) { + prevUpdate = t->gst; + fgSunInit(); + fgMoonInit(); + } + + /* Disable fog effects */ + glDisable( GL_FOG ); + + /* reverse light direction so the moon is displayed properly */ + glLightfv( GL_LIGHT0, GL_POSITION, t->sun_vec_inv ); + + glPushMatrix(); + + /* Translate to view position */ + glTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z ); + + /* Rotate based on gst (side real time) */ + angle = t->gst * 15.041085; /* should be 15.041085, Curt thought it was 15*/ +#ifdef DEBUG + printf("Rotating astro objects by %.2f degrees\n",angle); +#endif + glRotatef( angle, 0.0, 0.0, -1.0 ); + + /* render the stars */ + fgStarsRender(); + + /* render the moon */ + fgMoonRender(); + + /* render the sun */ + fgSunRender(); + + glPopMatrix(); + + /* reenable fog effects */ + glEnable( GL_FOG ); +} + + +/* $Log$ +/* Revision 1.1 1997/11/25 23:20:22 curt +/* Initial revision. +/* + */ diff --git a/Scenery/astro.h b/Scenery/astro.h new file mode 100644 index 00000000..c273d1a8 --- /dev/null +++ b/Scenery/astro.h @@ -0,0 +1,55 @@ +/************************************************************************** + * astro.h + * + * Written by Durk Talsma. Started November 1997, for use with 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 _ASTRO_H_ +#define _ASTRO_H_ + +#include +#include "stars.h" + +extern struct CelestialCoord + moonPos; + +extern float xMoon, yMoon, zMoon, xSun, ySun, zSun; +extern GLint moon, sun; +extern GLint stars[FG_STAR_LEVELS]; +extern GLfloat fgClearColor[4]; + + +/* Initialize Astronomical Objects */ +void fgAstroInit(); + +/* Render Astronomical objects */ +void fgAstroRender(); + + +#endif /* _ASTRO_H_ */ + + +/* $Log$ +/* Revision 1.1 1997/11/25 23:20:23 curt +/* Initial revision. +/* + */ From 9477aad95066b896ed08929b54e36b8cd1545e86 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 25 Nov 1997 23:20:44 +0000 Subject: [PATCH 007/123] Changed planets.dat Planets.dat --- Scenery/orbits.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Scenery/orbits.c b/Scenery/orbits.c index c2618561..5ed85c9f 100644 --- a/Scenery/orbits.c +++ b/Scenery/orbits.c @@ -129,7 +129,7 @@ void fgSolarSystemInit(struct fgTIME t) path[0] = '\0'; strcat(path, g->root_dir); strcat(path, "/Scenery/"); - strcat(path, "planets.dat"); + strcat(path, "Planets.dat"); if ( (data = fopen(path, "r")) == NULL ) { @@ -170,9 +170,12 @@ void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t) /* $Log$ -/* Revision 1.2 1997/11/25 19:25:36 curt -/* Changes to integrate Durk's moon/sun code updates + clean up. +/* 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. * From 268a59d0a972ae586cce8e7fb9488a7ff1b7552b Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 9 Dec 1997 04:25:25 +0000 Subject: [PATCH 008/123] Working on adding a global lighting params structure. --- Scenery/astro.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Scenery/astro.c b/Scenery/astro.c index a9534696..8ebe0623 100644 --- a/Scenery/astro.c +++ b/Scenery/astro.c @@ -69,11 +69,13 @@ void fgAstroInit() { /* Render Astronomical Objects */ void fgAstroRender() { struct FLIGHT *f; + struct fgLIGHT *l; struct VIEW *v; struct fgTIME *t; double angle; f = ¤t_aircraft.flight; + l = &cur_light_params; t = &cur_time_params; v = ¤t_view; @@ -88,7 +90,7 @@ void fgAstroRender() { glDisable( GL_FOG ); /* reverse light direction so the moon is displayed properly */ - glLightfv( GL_LIGHT0, GL_POSITION, t->sun_vec_inv ); + glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv ); glPushMatrix(); @@ -119,7 +121,10 @@ void fgAstroRender() { /* $Log$ -/* Revision 1.1 1997/11/25 23:20:22 curt -/* Initial revision. +/* Revision 1.2 1997/12/09 04:25:33 curt +/* Working on adding a global lighting params structure. /* + * Revision 1.1 1997/11/25 23:20:22 curt + * Initial revision. + * */ From 7ea54d28cdf9793e4d8a00e87a396dc1662d4ee4 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 9 Dec 1997 05:11:54 +0000 Subject: [PATCH 009/123] Working on tweaking lighting. --- Scenery/moon.c | 64 +++++++++++++++++++++++--------------------------- Scenery/sun.c | 49 ++++++++++++++++++++++++-------------- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/Scenery/moon.c b/Scenery/moon.c index 56788d65..d8c82cdd 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -31,10 +31,10 @@ #include "../Main/views.h" #include "../Time/fg_time.h" -struct CelestialCoord - moonPos; +struct CelestialCoord moonPos; float xMoon, yMoon, zMoon; +GLint moon; /* static GLfloat vdata[12][3] = @@ -52,8 +52,6 @@ static GLuint tindices[20][3] = {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} };*/ -GLint moon; - /* ------------------------------------------------------------- This section contains the code that generates a yellow Icosahedron. It's under development... (of Course) @@ -226,57 +224,53 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, } -void fgMoonInit() -{ +void fgMoonInit() { // int i; -// moon = glGenLists(1); -// glNewList(moon, GL_COMPILE ); + moon = glGenLists(1); + glNewList(moon, GL_COMPILE ); - fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params); - moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], cur_time_params); - #ifdef DEBUG - printf("Moon found at %f (ra), %f (dec)\n", moonPos.RightAscension, moonPos.Declination); - #endif - glColor3f(1.0, 1.0, 0.0); + fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params); + moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], + cur_time_params); +#ifdef DEBUG + printf("Moon found at %f (ra), %f (dec)\n", moonPos.RightAscension, + moonPos.Declination); +#endif - /* xMoon = 90000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination); - yMoon = 90000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); - zMoon = 90000.0 * sin(moonPos.Declination); */ + /* xMoon = 90000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination); + yMoon = 90000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); + zMoon = 90000.0 * sin(moonPos.Declination); */ - xMoon = 60000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination); - yMoon = 60000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); - zMoon = 60000.0 * sin(moonPos.Declination); + xMoon = 60000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination); + yMoon = 60000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); + zMoon = 60000.0 * sin(moonPos.Declination); -// glPushMatrix(); -// glBegin(GL_TRIANGLES); - /* - for (i = 0; i < 20; i++) - subdivide(&vdata[tindices[i][0]][0], - &vdata[tindices[i][1]][0], - &vdata[tindices[i][2]][0], 3);*/ -// glutSolidSphere(1.0, 25, 25); + glColor3f(1.0, 1.0, 1.0); + glutSolidSphere(1.0, 10, 10); -// glEnd(); -// glPopMatrix(); -// glEndList(); + glEndList(); } /* Draw the moon */ void fgMoonRender() { + struct fgLIGHT *l; GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 }; + l = &cur_light_params; + /* set lighting parameters */ - glLightfv(GL_LIGHT0, GL_AMBIENT, color ); + glLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_clear ); glLightfv(GL_LIGHT0, GL_DIFFUSE, color ); - glMaterialfv(GL_FRONT, GL_AMBIENT, fgClearColor); - glMaterialfv(GL_FRONT, GL_DIFFUSE, color); glPushMatrix(); glTranslatef(xMoon, yMoon, zMoon); glScalef(1400, 1400, 1400); + + /* glColor3fv(color); */ /* glutSolidSphere(1.0, 25, 25); */ - glutSolidSphere(1.0, 15, 15); + glCallList(moon); + glPopMatrix(); } diff --git a/Scenery/sun.c b/Scenery/sun.c index 92e022f6..f4ae4e9b 100644 --- a/Scenery/sun.c +++ b/Scenery/sun.c @@ -30,8 +30,7 @@ GLint sun; -static struct CelestialCoord - sunPos; +static struct CelestialCoord sunPos; float xSun, ySun, zSun; @@ -95,15 +94,20 @@ struct CelestialCoord fgCalculateSun(struct OrbElements params, struct fgTIME t) void fgSunInit() { // int i; -// sun = glGenLists(1); -// glNewList(sun, GL_COMPILE ); + + sun = glGenLists(1); + glNewList(sun, GL_COMPILE ); + // glBegin( GL_POINTS ); - fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params); - sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params); - #ifdef DEBUG - printf("Sun found at %f (ra), %f (dec)\n", sunPos.RightAscension, sunPos.Declination); - #endif - /* give the moon a temporary color, for testing purposes */ + + fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params); + sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params); +#ifdef DEBUG + printf("Sun found at %f (ra), %f (dec)\n", sunPos.RightAscension, + sunPos.Declination); +#endif + + /* give the moon a temporary color, for testing purposes */ // glColor3f( 0.0, 1.0, 0.0); // glVertex3f( 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination), // 190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination), @@ -114,6 +118,7 @@ void fgSunInit() //xMoon = 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination); //yMoon = 190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); //zMoon = 190000.0 * sin(moonPos.Declination); + xSun = 60000.0 * cos(sunPos.RightAscension) * cos(sunPos.Declination); ySun = 60000.0 * sin(sunPos.RightAscension) * cos(sunPos.Declination); zSun = 60000.0 * sin(sunPos.Declination); @@ -129,8 +134,12 @@ void fgSunInit() // glutSolidSphere(1.0, 25, 25); // glEnd(); - //glPopMatrix(); -// glEndList(); + //glPopMatrix(); + + glColor3f(0.85, 0.65, 0.05); + glutSolidSphere(1.0, 10, 10); + + glEndList(); } @@ -176,22 +185,28 @@ void fgSunRender() { glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); */ glDisable( GL_LIGHTING ); + glPushMatrix(); glTranslatef(xSun, ySun, zSun); glScalef(1400, 1400, 1400); - glColor3fv( color ); + + /* glColor3fv( color ); */ /* glutSolidSphere(1.0, 25, 25); */ - glutSolidSphere(1.0, 10, 10); - //glCallList(sun); + glCallList(sun); + glPopMatrix(); + glEnable( GL_LIGHTING ); } /* $Log$ -/* Revision 1.2 1997/11/25 19:25:39 curt -/* Changes to integrate Durk's moon/sun code updates + clean up. +/* 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. * From 5bf6d83d2d9a260f24509c864d4070e16dd9897b Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 10 Dec 1997 22:37:34 +0000 Subject: [PATCH 010/123] Prepended "fg" on the name of all global structures that didn't have it yet. i.e. "struct WEATHER {}" became "struct fgWEATHER {}" --- Scenery/astro.c | 12 ++++++++---- Scenery/orbits.c | 10 +++++++--- Scenery/sun.c | 10 +++++++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Scenery/astro.c b/Scenery/astro.c index 8ebe0623..6246a713 100644 --- a/Scenery/astro.c +++ b/Scenery/astro.c @@ -68,9 +68,9 @@ void fgAstroInit() { /* Render Astronomical Objects */ void fgAstroRender() { - struct FLIGHT *f; + struct fgFLIGHT *f; struct fgLIGHT *l; - struct VIEW *v; + struct fgVIEW *v; struct fgTIME *t; double angle; @@ -121,9 +121,13 @@ void fgAstroRender() { /* $Log$ -/* Revision 1.2 1997/12/09 04:25:33 curt -/* Working on adding a global lighting params structure. +/* Revision 1.3 1997/12/10 22:37:49 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.2 1997/12/09 04:25:33 curt + * Working on adding a global lighting params structure. + * * Revision 1.1 1997/11/25 23:20:22 curt * Initial revision. * diff --git a/Scenery/orbits.c b/Scenery/orbits.c index 5ed85c9f..4e10843a 100644 --- a/Scenery/orbits.c +++ b/Scenery/orbits.c @@ -119,7 +119,7 @@ void fgReadOrbElements(struct OrbElements *dest, FILE *src) void fgSolarSystemInit(struct fgTIME t) { - struct GENERAL *g; + struct fgGENERAL *g; char path[80]; int i; FILE *data; @@ -170,9 +170,13 @@ void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t) /* $Log$ -/* Revision 1.3 1997/11/25 23:20:44 curt -/* Changed planets.dat Planets.dat +/* 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. * diff --git a/Scenery/sun.c b/Scenery/sun.c index f4ae4e9b..9702ffed 100644 --- a/Scenery/sun.c +++ b/Scenery/sun.c @@ -145,7 +145,7 @@ void fgSunInit() /* Draw the Sun */ void fgSunRender() { - struct VIEW *v; + struct fgVIEW *v; struct fgTIME *t; GLfloat color[4] = { 0.85, 0.65, 0.05, 1.0 }; /* double x_2, x_4, x_8, x_10; */ @@ -201,9 +201,13 @@ void fgSunRender() { /* $Log$ -/* Revision 1.3 1997/12/09 05:11:56 curt -/* Working on tweaking lighting. +/* 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. * From 5b779f520055787bd7add0cc1de6b78c04723f2f Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 11 Dec 1997 04:43:53 +0000 Subject: [PATCH 011/123] Fixed sun vector and lighting problems. I thing the moon is now lit correctly. --- Scenery/astro.c | 13 +++++++------ Scenery/astro.h | 9 ++++++--- Scenery/moon.h | 9 ++++++--- Scenery/sun.h | 9 ++++++--- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Scenery/astro.c b/Scenery/astro.c index 6246a713..a9f10392 100644 --- a/Scenery/astro.c +++ b/Scenery/astro.c @@ -89,9 +89,6 @@ void fgAstroRender() { /* Disable fog effects */ glDisable( GL_FOG ); - /* reverse light direction so the moon is displayed properly */ - glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv ); - glPushMatrix(); /* Translate to view position */ @@ -121,10 +118,14 @@ void fgAstroRender() { /* $Log$ -/* Revision 1.3 1997/12/10 22:37:49 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.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/12/10 22:37:49 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.2 1997/12/09 04:25:33 curt * Working on adding a global lighting params structure. * diff --git a/Scenery/astro.h b/Scenery/astro.h index c273d1a8..a6b8ff2d 100644 --- a/Scenery/astro.h +++ b/Scenery/astro.h @@ -35,7 +35,6 @@ extern struct CelestialCoord extern float xMoon, yMoon, zMoon, xSun, ySun, zSun; extern GLint moon, sun; extern GLint stars[FG_STAR_LEVELS]; -extern GLfloat fgClearColor[4]; /* Initialize Astronomical Objects */ @@ -49,7 +48,11 @@ void fgAstroRender(); /* $Log$ -/* Revision 1.1 1997/11/25 23:20:23 curt -/* Initial revision. +/* Revision 1.2 1997/12/11 04:43:56 curt +/* Fixed sun vector and lighting problems. I thing the moon is now lit +/* correctly. /* + * Revision 1.1 1997/11/25 23:20:23 curt + * Initial revision. + * */ diff --git a/Scenery/moon.h b/Scenery/moon.h index 8c0ae98b..a8e90386 100644 --- a/Scenery/moon.h +++ b/Scenery/moon.h @@ -46,15 +46,18 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements Params, struct fgTIME t); extern struct OrbElements pltOrbElements[9]; -extern GLfloat fgClearColor[4]; #endif /* _MOON_H_ */ /* $Log$ -/* Revision 1.3 1997/11/25 19:25:35 curt -/* Changes to integrate Durk's moon/sun code updates + clean up. +/* 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. * diff --git a/Scenery/sun.h b/Scenery/sun.h index fe06244f..9d597d27 100644 --- a/Scenery/sun.h +++ b/Scenery/sun.h @@ -29,7 +29,6 @@ struct SunPos fgCalcSunPos(struct OrbElements sunParams); extern struct OrbElements pltOrbElements[9]; -extern GLfloat fgClearColor[4]; /* Initialize the Sun */ void fgSunInit(); @@ -42,9 +41,13 @@ void fgSunRender(); /* $Log$ -/* Revision 1.2 1997/11/25 19:25:39 curt -/* Changes to integrate Durk's moon/sun code updates + clean up. +/* 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. * From f711a02a6209ef0774fc82f05a17872b494e8035 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 12 Dec 1997 19:52:47 +0000 Subject: [PATCH 012/123] Working on lightling and material properties. --- Scenery/astro.c | 12 +++++++++--- Scenery/moon.c | 13 ++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Scenery/astro.c b/Scenery/astro.c index a9f10392..bf5cd5e3 100644 --- a/Scenery/astro.c +++ b/Scenery/astro.c @@ -89,6 +89,9 @@ void fgAstroRender() { /* Disable fog effects */ glDisable( GL_FOG ); + /* set the sun position */ + /* glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv );*/ + glPushMatrix(); /* Translate to view position */ @@ -118,10 +121,13 @@ void fgAstroRender() { /* $Log$ -/* 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.5 1997/12/12 19:52:54 curt +/* Working on lightling and material properties. /* + * 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/12/10 22:37:49 curt * Prepended "fg" on the name of all global structures that didn't have it yet. * i.e. "struct WEATHER {}" became "struct fgWEATHER {}" diff --git a/Scenery/moon.c b/Scenery/moon.c index d8c82cdd..f9ce58bb 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -225,10 +225,18 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, void fgMoonInit() { + struct fgLIGHT *l; + static GLfloat moon_color[4] = { 1.0, 1.0, 1.0, 1.0 }; // int i; + + l = &cur_light_params; + moon = glGenLists(1); glNewList(moon, GL_COMPILE ); + /* glMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear); + glMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */ + fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params); moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], cur_time_params); @@ -245,7 +253,6 @@ void fgMoonInit() { yMoon = 60000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); zMoon = 60000.0 * sin(moonPos.Declination); - glColor3f(1.0, 1.0, 1.0); glutSolidSphere(1.0, 10, 10); glEndList(); @@ -255,13 +262,13 @@ void fgMoonInit() { /* Draw the moon */ void fgMoonRender() { struct fgLIGHT *l; - GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat moon_color[4] = { 1.0, 1.0, 1.0, 1.0 }; l = &cur_light_params; /* set lighting parameters */ glLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_clear ); - glLightfv(GL_LIGHT0, GL_DIFFUSE, color ); + glLightfv(GL_LIGHT0, GL_DIFFUSE, moon_color ); glPushMatrix(); glTranslatef(xMoon, yMoon, zMoon); From 3304526093e90fdce328855c790703f273466b3e Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 12 Dec 1997 21:41:24 +0000 Subject: [PATCH 013/123] More light/material property tweaking ... still a ways off. --- Scenery/astro.c | 21 ++++++++++++--------- Scenery/moon.c | 15 +++++++++------ Scenery/planets.c | 11 +++++++---- Scenery/planets.h | 9 ++++++--- Scenery/sun.c | 20 ++++++++++++-------- 5 files changed, 46 insertions(+), 30 deletions(-) diff --git a/Scenery/astro.c b/Scenery/astro.c index bf5cd5e3..f742a1b5 100644 --- a/Scenery/astro.c +++ b/Scenery/astro.c @@ -55,14 +55,14 @@ void fgAstroInit() { /* Initialize the orbital elements of sun, moon and mayor planets */ fgSolarSystemInit(*t); - /* Intialize the moon's position */ - fgMoonInit(); + /* Initialize the Stars subsystem */ + fgStarsInit(); /* Initialize the sun's position */ fgSunInit(); - /* Initialize the Stars subsystem */ - fgStarsInit(); + /* Intialize the moon's position */ + fgMoonInit(); } @@ -107,12 +107,12 @@ void fgAstroRender() { /* render the stars */ fgStarsRender(); - /* render the moon */ - fgMoonRender(); - /* render the sun */ fgSunRender(); + /* render the moon */ + fgMoonRender(); + glPopMatrix(); /* reenable fog effects */ @@ -121,9 +121,12 @@ void fgAstroRender() { /* $Log$ -/* Revision 1.5 1997/12/12 19:52:54 curt -/* Working on lightling and material properties. +/* Revision 1.6 1997/12/12 21:41:27 curt +/* More light/material property tweaking ... still a ways off. /* + * Revision 1.5 1997/12/12 19:52:54 curt + * Working on lightling and material properties. + * * Revision 1.4 1997/12/11 04:43:56 curt * Fixed sun vector and lighting problems. I thing the moon is now lit * correctly. diff --git a/Scenery/moon.c b/Scenery/moon.c index f9ce58bb..2cbaf791 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -147,11 +147,11 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, struct OrbElements sunParams, struct fgTIME t) { - struct CelestialCoord - result; - + struct CelestialCoord + result; + double - eccAnom, ecl, lonecl, latecl, actTime, + eccAnom, ecl, lonecl, latecl, actTime, xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze, Ls, Lm, D, F; @@ -226,7 +226,6 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, void fgMoonInit() { struct fgLIGHT *l; - static GLfloat moon_color[4] = { 1.0, 1.0, 1.0, 1.0 }; // int i; l = &cur_light_params; @@ -262,6 +261,7 @@ void fgMoonInit() { /* Draw the moon */ void fgMoonRender() { struct fgLIGHT *l; + GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat moon_color[4] = { 1.0, 1.0, 1.0, 1.0 }; l = &cur_light_params; @@ -270,11 +270,14 @@ void fgMoonRender() { glLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_clear ); glLightfv(GL_LIGHT0, GL_DIFFUSE, moon_color ); + glMaterialfv(GL_FRONT, GL_AMBIENT, black); + glMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); + glPushMatrix(); glTranslatef(xMoon, yMoon, zMoon); glScalef(1400, 1400, 1400); - /* glColor3fv(color); */ + glColor3fv(moon_color); /* glutSolidSphere(1.0, 25, 25); */ glCallList(moon); diff --git a/Scenery/planets.c b/Scenery/planets.c index 9f7911a0..b4e2bb16 100644 --- a/Scenery/planets.c +++ b/Scenery/planets.c @@ -30,7 +30,7 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, - struct OrbElements sun, + struct OrbElements theSun, struct fgTIME t) { struct CelestialCoord @@ -70,7 +70,7 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, */ /* calculate the solar position */ - SolarPosition = fgCalcSunPos(sun); + SolarPosition = fgCalcSunPos(theSun); xg = xh + SolarPosition.xs; yg = yh + SolarPosition.ys; zg = zh; @@ -85,7 +85,10 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, /* $Log$ -/* Revision 1.1 1997/10/25 03:16:10 curt -/* Initial revision of code contributed by Durk Talsma. +/* 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/Scenery/planets.h b/Scenery/planets.h index e0ce0541..dfbc35fe 100644 --- a/Scenery/planets.h +++ b/Scenery/planets.h @@ -28,14 +28,17 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, - struct OrbElements sun, + struct OrbElements theSun, struct fgTIME t); #endif /* PLANETS_H */ /* $Log$ -/* Revision 1.1 1997/10/25 03:16:11 curt -/* Initial revision of code contributed by Durk Talsma. +/* 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/Scenery/sun.c b/Scenery/sun.c index 9702ffed..2b97740c 100644 --- a/Scenery/sun.c +++ b/Scenery/sun.c @@ -28,7 +28,7 @@ #include "orbits.h" #include "sun.h" -GLint sun; +GLint sun_obj; static struct CelestialCoord sunPos; @@ -95,8 +95,8 @@ void fgSunInit() { // int i; - sun = glGenLists(1); - glNewList(sun, GL_COMPILE ); + sun_obj = glGenLists(1); + glNewList(sun_obj, GL_COMPILE ); // glBegin( GL_POINTS ); @@ -136,7 +136,6 @@ void fgSunInit() // glEnd(); //glPopMatrix(); - glColor3f(0.85, 0.65, 0.05); glutSolidSphere(1.0, 10, 10); glEndList(); @@ -190,9 +189,11 @@ void fgSunRender() { glTranslatef(xSun, ySun, zSun); glScalef(1400, 1400, 1400); + glColor3f(0.85, 0.65, 0.05); + /* glColor3fv( color ); */ /* glutSolidSphere(1.0, 25, 25); */ - glCallList(sun); + glCallList(sun_obj); glPopMatrix(); @@ -201,10 +202,13 @@ void fgSunRender() { /* $Log$ -/* 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.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. * From 8f7a446ec862293192cebb1a4ae43569d1fec36a Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 15 Dec 1997 20:59:08 +0000 Subject: [PATCH 014/123] Misc. tweaks. --- Scenery/astro.c | 15 +++++++++------ Scenery/moon.c | 5 +++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Scenery/astro.c b/Scenery/astro.c index f742a1b5..6bd4e0d2 100644 --- a/Scenery/astro.c +++ b/Scenery/astro.c @@ -90,7 +90,7 @@ void fgAstroRender() { glDisable( GL_FOG ); /* set the sun position */ - /* glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv );*/ + glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv ); glPushMatrix(); @@ -104,15 +104,15 @@ void fgAstroRender() { #endif glRotatef( angle, 0.0, 0.0, -1.0 ); + /* render the moon */ + fgMoonRender(); + /* render the stars */ fgStarsRender(); /* render the sun */ fgSunRender(); - /* render the moon */ - fgMoonRender(); - glPopMatrix(); /* reenable fog effects */ @@ -121,9 +121,12 @@ void fgAstroRender() { /* $Log$ -/* Revision 1.6 1997/12/12 21:41:27 curt -/* More light/material property tweaking ... still a ways off. +/* Revision 1.7 1997/12/15 20:59:09 curt +/* Misc. tweaks. /* + * Revision 1.6 1997/12/12 21:41:27 curt + * More light/material property tweaking ... still a ways off. + * * Revision 1.5 1997/12/12 19:52:54 curt * Working on lightling and material properties. * diff --git a/Scenery/moon.c b/Scenery/moon.c index 2cbaf791..e72404f9 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -252,7 +252,7 @@ void fgMoonInit() { yMoon = 60000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); zMoon = 60000.0 * sin(moonPos.Declination); - glutSolidSphere(1.0, 10, 10); + glutSolidSphere(1.0, 15, 15); glEndList(); } @@ -270,7 +270,8 @@ void fgMoonRender() { glLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_clear ); glLightfv(GL_LIGHT0, GL_DIFFUSE, moon_color ); - glMaterialfv(GL_FRONT, GL_AMBIENT, black); + glMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear ); + glMaterialfv(GL_FRONT, GL_AMBIENT, moon_color ); glMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); glPushMatrix(); From b54a4d1f928c6b33c2136baf9feaa0b5e4012f45 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 15 Dec 1997 23:54:25 +0000 Subject: [PATCH 015/123] Add xgl wrappers for debugging. Generate terrain normals on the fly. --- Scenery/astro.c | 27 ++++++++++------- Scenery/moon.c | 75 ++++++++++++++++++++++++------------------------ Scenery/orbits.c | 12 +++++--- Scenery/sun.c | 68 +++++++++++++++++++++++-------------------- 4 files changed, 99 insertions(+), 83 deletions(-) diff --git a/Scenery/astro.c b/Scenery/astro.c index 6bd4e0d2..411fd6b1 100644 --- a/Scenery/astro.c +++ b/Scenery/astro.c @@ -29,6 +29,7 @@ #include #include +#include "../XGL/xgl.h" #include "astro.h" #include "moon.h" @@ -37,8 +38,8 @@ #include "stars.h" #include "sun.h" -#include "../constants.h" -#include "../general.h" +#include "../Include/constants.h" +#include "../Include/general.h" #include "../Main/views.h" #include "../Aircraft/aircraft.h" @@ -87,22 +88,22 @@ void fgAstroRender() { } /* Disable fog effects */ - glDisable( GL_FOG ); + xglDisable( GL_FOG ); /* set the sun position */ - glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv ); + xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv ); - glPushMatrix(); + xglPushMatrix(); /* Translate to view position */ - glTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z ); + xglTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z ); /* Rotate based on gst (side real time) */ angle = t->gst * 15.041085; /* should be 15.041085, Curt thought it was 15*/ #ifdef DEBUG printf("Rotating astro objects by %.2f degrees\n",angle); #endif - glRotatef( angle, 0.0, 0.0, -1.0 ); + xglRotatef( angle, 0.0, 0.0, -1.0 ); /* render the moon */ fgMoonRender(); @@ -113,17 +114,21 @@ void fgAstroRender() { /* render the sun */ fgSunRender(); - glPopMatrix(); + xglPopMatrix(); /* reenable fog effects */ - glEnable( GL_FOG ); + xglEnable( GL_FOG ); } /* $Log$ -/* Revision 1.7 1997/12/15 20:59:09 curt -/* Misc. tweaks. +/* Revision 1.8 1997/12/15 23:54:57 curt +/* Add xgl wrappers for debugging. +/* Generate terrain normals on the fly. /* + * Revision 1.7 1997/12/15 20:59:09 curt + * Misc. tweaks. + * * Revision 1.6 1997/12/12 21:41:27 curt * More light/material property tweaking ... still a ways off. * diff --git a/Scenery/moon.c b/Scenery/moon.c index e72404f9..ac97aa94 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -23,11 +23,12 @@ #include #include +#include "../XGL/xgl.h" #include "orbits.h" #include "moon.h" -#include "../general.h" +#include "../Include/general.h" #include "../Main/views.h" #include "../Time/fg_time.h" @@ -72,15 +73,15 @@ void NormalizeVector(float v[3]) void drawTriangle(float *v1, float *v2, float *v3) { - glBegin(GL_POLYGON); - //glBegin(GL_POINTS); - glNormal3fv(v1); - glVertex3fv(v1); - glNormal3fv(v2); - glVertex3fv(v2); - glNormal3fv(v3); - glVertex3fv(v3); - glEnd(); + xglBegin(GL_POLYGON); + //xglBegin(GL_POINTS); + xglNormal3fv(v1); + xglVertex3fv(v1); + xglNormal3fv(v2); + xglVertex3fv(v2); + xglNormal3fv(v3); + xglVertex3fv(v3); + xglEnd(); } void subdivide(float *v1, float *v2, float *v3, long depth) @@ -112,17 +113,17 @@ void subdivide(float *v1, float *v2, float *v3, long depth) void display(void) { int i; - glClear(GL_COLOR_BUFFER_BIT); - glPushMatrix(); - glRotatef(spin, 0.0, 0.0, 0.0); - glColor3f(1.0, 1.0, 0.0); -// glBegin(GL_LINE_LOOP); + xglClear(GL_COLOR_BUFFER_BIT); + xglPushMatrix(); + xglRotatef(spin, 0.0, 0.0, 0.0); + xglColor3f(1.0, 1.0, 0.0); +// xglBegin(GL_LINE_LOOP); for (i = 0; i < 20; i++) { - //glVertex3fv(&vdata[tindices[i][0]][0]); - //glVertex3fv(&vdata[tindices[i][1]][0]); - //glVertex3fv(&vdata[tindices[i][2]][0]); + //xglVertex3fv(&vdata[tindices[i][0]][0]); + //xglVertex3fv(&vdata[tindices[i][1]][0]); + //xglVertex3fv(&vdata[tindices[i][2]][0]); subdivide(&vdata[tindices[i][0]][0], &vdata[tindices[i][1]][0], @@ -130,9 +131,9 @@ void display(void) } -// glEnd(); - // glFlush(); - glPopMatrix(); +// xglEnd(); + // xglFlush(); + xglPopMatrix(); glutSwapBuffers(); } */ @@ -230,11 +231,11 @@ void fgMoonInit() { l = &cur_light_params; - moon = glGenLists(1); - glNewList(moon, GL_COMPILE ); + moon = xglGenLists(1); + xglNewList(moon, GL_COMPILE ); - /* glMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear); - glMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */ + /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear); + xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */ fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params); moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], @@ -254,7 +255,7 @@ void fgMoonInit() { glutSolidSphere(1.0, 15, 15); - glEndList(); + xglEndList(); } @@ -267,21 +268,21 @@ void fgMoonRender() { l = &cur_light_params; /* set lighting parameters */ - glLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_clear ); - glLightfv(GL_LIGHT0, GL_DIFFUSE, moon_color ); + xglLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_clear ); + xglLightfv(GL_LIGHT0, GL_DIFFUSE, moon_color ); - glMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear ); - glMaterialfv(GL_FRONT, GL_AMBIENT, moon_color ); - glMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); + xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear ); + xglMaterialfv(GL_FRONT, GL_AMBIENT, moon_color ); + xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); - glPushMatrix(); - glTranslatef(xMoon, yMoon, zMoon); - glScalef(1400, 1400, 1400); + xglPushMatrix(); + xglTranslatef(xMoon, yMoon, zMoon); + xglScalef(1400, 1400, 1400); - glColor3fv(moon_color); + xglColor3fv(moon_color); /* glutSolidSphere(1.0, 25, 25); */ - glCallList(moon); + xglCallList(moon); - glPopMatrix(); + xglPopMatrix(); } diff --git a/Scenery/orbits.c b/Scenery/orbits.c index 4e10843a..8ff0f182 100644 --- a/Scenery/orbits.c +++ b/Scenery/orbits.c @@ -27,7 +27,7 @@ #include "orbits.h" -#include "../general.h" +#include "../Include/general.h" #include "../Time/fg_time.h" @@ -170,10 +170,14 @@ void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t) /* $Log$ -/* 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.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 * diff --git a/Scenery/sun.c b/Scenery/sun.c index 2b97740c..e53dfbb5 100644 --- a/Scenery/sun.c +++ b/Scenery/sun.c @@ -23,6 +23,8 @@ **************************************************************************/ #include +#include "../XGL/xgl.h" + #include "../Time/fg_time.h" #include "../Main/views.h" #include "orbits.h" @@ -95,10 +97,10 @@ void fgSunInit() { // int i; - sun_obj = glGenLists(1); - glNewList(sun_obj, GL_COMPILE ); + sun_obj = xglGenLists(1); + xglNewList(sun_obj, GL_COMPILE ); -// glBegin( GL_POINTS ); +// xglBegin( GL_POINTS ); fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params); sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params); @@ -108,13 +110,13 @@ void fgSunInit() #endif /* give the moon a temporary color, for testing purposes */ -// glColor3f( 0.0, 1.0, 0.0); -// glVertex3f( 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination), +// xglColor3f( 0.0, 1.0, 0.0); +// xglVertex3f( 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination), // 190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination), // 190000.0 * sin(moonPos.Declination) ); - //glVertex3f(0.0, 0.0, 0.0); -// glEnd(); -// glColor3f(1.0, 1.0, 1.0); + //xglVertex3f(0.0, 0.0, 0.0); +// xglEnd(); +// xglColor3f(1.0, 1.0, 1.0); //xMoon = 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination); //yMoon = 190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); //zMoon = 190000.0 * sin(moonPos.Declination); @@ -123,22 +125,22 @@ void fgSunInit() ySun = 60000.0 * sin(sunPos.RightAscension) * cos(sunPos.Declination); zSun = 60000.0 * sin(sunPos.Declination); -// glPushMatrix(); -// glTranslatef(x, y, z); -// glScalef(16622.8, 16622.8, 16622.8); -// glBegin(GL_TRIANGLES); +// xglPushMatrix(); +// xglTranslatef(x, y, z); +// xglScalef(16622.8, 16622.8, 16622.8); +// xglBegin(GL_TRIANGLES); // for (i = 0; i < 20; i++) // subdivide(&vdata[tindices[i][0]][0], // &vdata[tindices[i][1]][0], // &vdata[tindices[i][2]][0], 3); // glutSolidSphere(1.0, 25, 25); -// glEnd(); - //glPopMatrix(); +// xglEnd(); + //xglPopMatrix(); glutSolidSphere(1.0, 10, 10); - glEndList(); + xglEndList(); } @@ -178,33 +180,37 @@ void fgSunRender() { diff[3] = 0.0; */ /* set lighting parameters */ - /* glLightfv(GL_LIGHT0, GL_AMBIENT, color ); - glLightfv(GL_LIGHT0, GL_DIFFUSE, color ); - glMaterialfv(GL_FRONT, GL_AMBIENT, amb); - glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); */ + /* xglLightfv(GL_LIGHT0, GL_AMBIENT, color ); + xglLightfv(GL_LIGHT0, GL_DIFFUSE, color ); + xglMaterialfv(GL_FRONT, GL_AMBIENT, amb); + xglMaterialfv(GL_FRONT, GL_DIFFUSE, diff); */ - glDisable( GL_LIGHTING ); + xglDisable( GL_LIGHTING ); - glPushMatrix(); - glTranslatef(xSun, ySun, zSun); - glScalef(1400, 1400, 1400); + xglPushMatrix(); + xglTranslatef(xSun, ySun, zSun); + xglScalef(1400, 1400, 1400); - glColor3f(0.85, 0.65, 0.05); + xglColor3f(0.85, 0.65, 0.05); - /* glColor3fv( color ); */ - /* glutSolidSphere(1.0, 25, 25); */ - glCallList(sun_obj); + /* xglColor3fv( color ); */ + /* xglutSolidSphere(1.0, 25, 25); */ + xglCallList(sun_obj); - glPopMatrix(); + xglPopMatrix(); - glEnable( GL_LIGHTING ); + xglEnable( GL_LIGHTING ); } /* $Log$ -/* Revision 1.5 1997/12/12 21:41:31 curt -/* More light/material property tweaking ... still a ways off. +/* Revision 1.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 {}" From 59973397309671312c0adce43efaeb41d20c4285 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 17 Dec 1997 23:12:14 +0000 Subject: [PATCH 016/123] Fixed so moon and sun display lists aren't recreate periodically. --- Scenery/moon.c | 41 ++++++++++++++++++++---------------- Scenery/sun.c | 57 +++++++++++++++++--------------------------------- 2 files changed, 42 insertions(+), 56 deletions(-) diff --git a/Scenery/moon.c b/Scenery/moon.c index ac97aa94..203d70bf 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -34,8 +34,8 @@ struct CelestialCoord moonPos; -float xMoon, yMoon, zMoon; -GLint moon; +static float xMoon, yMoon, zMoon; +static GLint moon; /* static GLfloat vdata[12][3] = @@ -227,16 +227,11 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, void fgMoonInit() { struct fgLIGHT *l; -// int i; + static int dl_exists = 0; l = &cur_light_params; - moon = xglGenLists(1); - xglNewList(moon, GL_COMPILE ); - - /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear); - xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */ - + /* position the moon */ fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params); moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], cur_time_params); @@ -245,24 +240,34 @@ void fgMoonInit() { moonPos.Declination); #endif - /* xMoon = 90000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination); - yMoon = 90000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); - zMoon = 90000.0 * sin(moonPos.Declination); */ + if ( !dl_exists ) { + dl_exists = 1; - xMoon = 60000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination); - yMoon = 60000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); - zMoon = 60000.0 * sin(moonPos.Declination); + /* printf("First time through, creating moon display list\n"); */ - glutSolidSphere(1.0, 15, 15); + moon = xglGenLists(1); + xglNewList(moon, GL_COMPILE ); - xglEndList(); + /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear); + xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */ + + + xMoon = 60000.0 * cos(moonPos.RightAscension) * + cos(moonPos.Declination); + yMoon = 60000.0 * sin(moonPos.RightAscension) * + cos(moonPos.Declination); + zMoon = 60000.0 * sin(moonPos.Declination); + + glutSolidSphere(1.0, 15, 15); + + xglEndList(); + } } /* Draw the moon */ void fgMoonRender() { struct fgLIGHT *l; - GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat moon_color[4] = { 1.0, 1.0, 1.0, 1.0 }; l = &cur_light_params; diff --git a/Scenery/sun.c b/Scenery/sun.c index e53dfbb5..8b012c3e 100644 --- a/Scenery/sun.c +++ b/Scenery/sun.c @@ -93,14 +93,8 @@ struct CelestialCoord fgCalculateSun(struct OrbElements params, struct fgTIME t) /* Initialize the Sun */ -void fgSunInit() -{ -// int i; - - sun_obj = xglGenLists(1); - xglNewList(sun_obj, GL_COMPILE ); - -// xglBegin( GL_POINTS ); +void fgSunInit() { + static int dl_exists = 0; fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params); sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params); @@ -109,38 +103,22 @@ void fgSunInit() sunPos.Declination); #endif - /* give the moon a temporary color, for testing purposes */ -// xglColor3f( 0.0, 1.0, 0.0); -// xglVertex3f( 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination), - // 190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination), -// 190000.0 * sin(moonPos.Declination) ); - //xglVertex3f(0.0, 0.0, 0.0); -// xglEnd(); -// xglColor3f(1.0, 1.0, 1.0); - //xMoon = 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination); - //yMoon = 190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination); - //zMoon = 190000.0 * sin(moonPos.Declination); + if ( !dl_exists ) { + dl_exists = 1; - xSun = 60000.0 * cos(sunPos.RightAscension) * cos(sunPos.Declination); - ySun = 60000.0 * sin(sunPos.RightAscension) * cos(sunPos.Declination); - zSun = 60000.0 * sin(sunPos.Declination); + /* printf("First time through, creating sun display list\n"); */ -// xglPushMatrix(); -// xglTranslatef(x, y, z); -// xglScalef(16622.8, 16622.8, 16622.8); -// xglBegin(GL_TRIANGLES); -// for (i = 0; i < 20; i++) -// subdivide(&vdata[tindices[i][0]][0], -// &vdata[tindices[i][1]][0], -// &vdata[tindices[i][2]][0], 3); -// glutSolidSphere(1.0, 25, 25); + sun_obj = xglGenLists(1); + xglNewList(sun_obj, GL_COMPILE ); -// xglEnd(); - //xglPopMatrix(); + xSun = 60000.0 * cos(sunPos.RightAscension) * cos(sunPos.Declination); + ySun = 60000.0 * sin(sunPos.RightAscension) * cos(sunPos.Declination); + zSun = 60000.0 * sin(sunPos.Declination); - glutSolidSphere(1.0, 10, 10); + glutSolidSphere(1.0, 10, 10); - xglEndList(); + xglEndList(); + } } @@ -204,10 +182,13 @@ void fgSunRender() { /* $Log$ -/* Revision 1.6 1997/12/15 23:55:04 curt -/* Add xgl wrappers for debugging. -/* Generate terrain normals on the fly. +/* Revision 1.7 1997/12/17 23:12:16 curt +/* Fixed so moon and sun display lists aren't recreate periodically. /* + * Revision 1.6 1997/12/15 23:55:04 curt + * Add xgl wrappers for debugging. + * Generate terrain normals on the fly. + * * Revision 1.5 1997/12/12 21:41:31 curt * More light/material property tweaking ... still a ways off. * From e24203fb2f78a98ef004b14ecdf341927de51652 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 17 Dec 1997 23:13:45 +0000 Subject: [PATCH 017/123] Began working on rendering the sky. --- Scenery/astro.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Scenery/astro.h b/Scenery/astro.h index a6b8ff2d..4fa5150a 100644 --- a/Scenery/astro.h +++ b/Scenery/astro.h @@ -33,7 +33,7 @@ extern struct CelestialCoord moonPos; extern float xMoon, yMoon, zMoon, xSun, ySun, zSun; -extern GLint moon, sun; +/* extern GLint moon, sun; */ extern GLint stars[FG_STAR_LEVELS]; @@ -48,10 +48,13 @@ void fgAstroRender(); /* $Log$ -/* Revision 1.2 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/12/17 23:13:46 curt +/* Began working on rendering the sky. /* + * Revision 1.2 1997/12/11 04:43:56 curt + * Fixed sun vector and lighting problems. I thing the moon is now lit + * correctly. + * * Revision 1.1 1997/11/25 23:20:23 curt * Initial revision. * From 41f441bdde86d10c6187f8429170f455728d5656 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 17 Dec 1997 23:14:30 +0000 Subject: [PATCH 018/123] Initial revision. Begin work on rendering the sky. (Rather than just using a clear screen.) --- Scenery/sky.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++ Scenery/sky.h | 39 ++++++++++++ 2 files changed, 207 insertions(+) create mode 100644 Scenery/sky.c create mode 100644 Scenery/sky.h diff --git a/Scenery/sky.c b/Scenery/sky.c new file mode 100644 index 00000000..60e51f25 --- /dev/null +++ b/Scenery/sky.c @@ -0,0 +1,168 @@ +/************************************************************************** + * 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) + **************************************************************************/ + + +#ifdef WIN32 +# include +#endif + +#include +/* +#include +#include +#include +*/ + +#include +#include "../XGL/xgl.h" + +#include "sky.h" + +#include "../Time/fg_time.h" + +#include "../Include/constants.h" +#include "../Main/views.h" +/* +#include "../Include/general.h" +#include "../Aircraft/aircraft.h" +*/ + +/* in meters of course */ +#define INNER_RADIUS 50000.0 +#define INNER_ELEV 20000.0 +#define MIDDLE_RADIUS 70000.0 +#define MIDDLE_ELEV 10000.0 +#define OUTER_RADIUS 80000.0 +#define OUTER_ELEV 0.0 + + +static GLint sky; /* sky display list */ +static float sky_center[12][3]; +static float sky_middle[12][3]; +static float sky_outer[12][3]; + +/* (Re)generate the display list */ +void fgSkyInit() { + struct fgLIGHT *l; + static int dl_exists = 0; + float theta; + int i; + + l = &cur_light_params; + + if ( dl_exists ) { + xglDeleteLists(sky, 1); + } else { + dl_exists = 1; + + /* first time through, calculate sky vertices */ + for ( i = 0; i < 12; i++ ) { + theta = (i * 30.0) * DEG_TO_RAD; + + sky_center[i][0] = cos(theta) * INNER_RADIUS; + sky_center[i][1] = sin(theta) * INNER_RADIUS; + sky_center[i][2] = INNER_ELEV; + + printf(" %.2f %.2f\n", cos(theta) * INNER_RADIUS, + sin(theta) * INNER_RADIUS); + + sky_middle[i][0] = cos((double)theta) * MIDDLE_RADIUS; + sky_middle[i][1] = sin((double)theta) * MIDDLE_RADIUS; + sky_middle[i][2] = MIDDLE_ELEV; + + sky_outer[i][0] = cos((double)theta) * OUTER_RADIUS; + sky_outer[i][1] = sin((double)theta) * OUTER_RADIUS; + sky_outer[i][2] = OUTER_ELEV; + + } + } + + printf("Creating the sky\n"); + + sky = xglGenLists(1); + xglNewList(sky, GL_COMPILE ); + + /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear); + xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */ + + /* Draw inner section */ + xglBegin( GL_TRIANGLE_FAN ); + + xglVertex3f(0.0, 0.0, INNER_ELEV); + + for ( i = 0; i < 12; i++ ) { + xglVertex3fv( sky_center[i] ); + } + + xglEnd(); + + xglEndList(); +} + + +/* Draw the Sky */ +void fgSkyRender() { + struct fgVIEW *v; + /* + struct fgFLIGHT *f; + struct fgLIGHT *l; + struct fgTIME *t; + int i; + */ + + v = ¤t_view; + /* + f = ¤t_aircraft.flight; + l = &cur_light_params; + t = &cur_time_params; + */ + + /* 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) */ + + printf("Rendering the sky.\n"); + + xglDisable( GL_LIGHTING ); + + xglPushMatrix(); + + /* Translate to view position */ + xglTranslatef( v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z ); + + xglCallList( sky ); + + xglPopMatrix(); + + xglEnable( GL_LIGHTING ); +} + + +/* $Log$ +/* 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/Scenery/sky.h b/Scenery/sky.h new file mode 100644 index 00000000..4fdcc0db --- /dev/null +++ b/Scenery/sky.h @@ -0,0 +1,39 @@ +/************************************************************************** + * 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) + **************************************************************************/ + + +/* (Re)generate the display list */ +void fgSkyInit(); + +/* Draw the Sky */ +void fgSkyRender(); + + +/* $Log$ +/* 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.) +/* + */ From ad2947e407221f66fe0495b30757013916dfa1e5 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 18 Dec 1997 04:07:02 +0000 Subject: [PATCH 019/123] Worked on properly translating and positioning the sky dome. --- Scenery/sky.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Scenery/sky.c b/Scenery/sky.c index 60e51f25..046d36be 100644 --- a/Scenery/sky.c +++ b/Scenery/sky.c @@ -42,16 +42,17 @@ #include "../Time/fg_time.h" +#include "../Aircraft/aircraft.h" +#include "../Flight/flight.h" #include "../Include/constants.h" #include "../Main/views.h" /* #include "../Include/general.h" -#include "../Aircraft/aircraft.h" */ /* in meters of course */ #define INNER_RADIUS 50000.0 -#define INNER_ELEV 20000.0 +#define INNER_ELEV 8000.0 /* was 20000 */ #define MIDDLE_RADIUS 70000.0 #define MIDDLE_ELEV 10000.0 #define OUTER_RADIUS 80000.0 @@ -110,11 +111,14 @@ void fgSkyInit() { /* Draw inner section */ xglBegin( GL_TRIANGLE_FAN ); + xglColor3f(0.0, 0.0, 1.0); xglVertex3f(0.0, 0.0, INNER_ELEV); + xglColor3f(0.2, 0.2, 1.0); for ( i = 0; i < 12; i++ ) { xglVertex3fv( sky_center[i] ); } + xglVertex3fv( sky_center[0] ); xglEnd(); @@ -124,17 +128,17 @@ void fgSkyInit() { /* Draw the Sky */ void fgSkyRender() { + struct fgFLIGHT *f; struct fgVIEW *v; /* - struct fgFLIGHT *f; struct fgLIGHT *l; struct fgTIME *t; int i; */ + f = ¤t_aircraft.flight; v = ¤t_view; /* - f = ¤t_aircraft.flight; l = &cur_light_params; t = &cur_time_params; */ @@ -151,6 +155,13 @@ void fgSkyRender() { /* 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 ); */ + + 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 ); xglCallList( sky ); @@ -161,8 +172,11 @@ void fgSkyRender() { /* $Log$ -/* 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.) +/* 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.) + * */ From d289222b399156687bccbcf5408b76f50bbe9850 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 18 Dec 1997 23:32:28 +0000 Subject: [PATCH 020/123] First stab at sky dome actually starting to look reasonable. :-) --- Scenery/astro.c | 11 ++-- Scenery/sky.c | 130 ++++++++++++++++++++++++------------------------ 2 files changed, 71 insertions(+), 70 deletions(-) diff --git a/Scenery/astro.c b/Scenery/astro.c index 411fd6b1..4e1558e7 100644 --- a/Scenery/astro.c +++ b/Scenery/astro.c @@ -91,7 +91,7 @@ void fgAstroRender() { xglDisable( GL_FOG ); /* set the sun position */ - xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv ); + /* xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv ); */ xglPushMatrix(); @@ -122,10 +122,13 @@ void fgAstroRender() { /* $Log$ -/* Revision 1.8 1997/12/15 23:54:57 curt -/* Add xgl wrappers for debugging. -/* Generate terrain normals on the fly. +/* Revision 1.9 1997/12/18 23:32:35 curt +/* First stab at sky dome actually starting to look reasonable. :-) /* + * Revision 1.8 1997/12/15 23:54:57 curt + * Add xgl wrappers for debugging. + * Generate terrain normals on the fly. + * * Revision 1.7 1997/12/15 20:59:09 curt * Misc. tweaks. * diff --git a/Scenery/sky.c b/Scenery/sky.c index 046d36be..ef81c8b5 100644 --- a/Scenery/sky.c +++ b/Scenery/sky.c @@ -46,20 +46,20 @@ #include "../Flight/flight.h" #include "../Include/constants.h" #include "../Main/views.h" +#include "../Math/fg_random.h" /* #include "../Include/general.h" */ /* in meters of course */ #define INNER_RADIUS 50000.0 -#define INNER_ELEV 8000.0 /* was 20000 */ +#define INNER_ELEV 20000.0 #define MIDDLE_RADIUS 70000.0 -#define MIDDLE_ELEV 10000.0 +#define MIDDLE_ELEV 4000.0 #define OUTER_RADIUS 80000.0 #define OUTER_ELEV 0.0 -static GLint sky; /* sky display list */ static float sky_center[12][3]; static float sky_middle[12][3]; static float sky_outer[12][3]; @@ -67,62 +67,32 @@ static float sky_outer[12][3]; /* (Re)generate the display list */ void fgSkyInit() { struct fgLIGHT *l; - static int dl_exists = 0; float theta; int i; l = &cur_light_params; - if ( dl_exists ) { - xglDeleteLists(sky, 1); - } else { - dl_exists = 1; + printf("Generating the sky dome vertices.\n"); - /* first time through, calculate sky vertices */ - for ( i = 0; i < 12; i++ ) { - theta = (i * 30.0) * DEG_TO_RAD; - - sky_center[i][0] = cos(theta) * INNER_RADIUS; - sky_center[i][1] = sin(theta) * INNER_RADIUS; - sky_center[i][2] = INNER_ELEV; - - printf(" %.2f %.2f\n", cos(theta) * INNER_RADIUS, - sin(theta) * INNER_RADIUS); - - sky_middle[i][0] = cos((double)theta) * MIDDLE_RADIUS; - sky_middle[i][1] = sin((double)theta) * MIDDLE_RADIUS; - sky_middle[i][2] = MIDDLE_ELEV; - - sky_outer[i][0] = cos((double)theta) * OUTER_RADIUS; - sky_outer[i][1] = sin((double)theta) * OUTER_RADIUS; - sky_outer[i][2] = OUTER_ELEV; - - } - } - - printf("Creating the sky\n"); - - sky = xglGenLists(1); - xglNewList(sky, GL_COMPILE ); - - /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear); - xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */ - - /* Draw inner section */ - xglBegin( GL_TRIANGLE_FAN ); - - xglColor3f(0.0, 0.0, 1.0); - xglVertex3f(0.0, 0.0, INNER_ELEV); - - xglColor3f(0.2, 0.2, 1.0); for ( i = 0; i < 12; i++ ) { - xglVertex3fv( sky_center[i] ); + theta = (i * 30.0) * DEG_TO_RAD; + + sky_center[i][0] = cos(theta) * INNER_RADIUS; + sky_center[i][1] = sin(theta) * INNER_RADIUS; + sky_center[i][2] = INNER_ELEV; + + printf(" %.2f %.2f\n", cos(theta) * INNER_RADIUS, + sin(theta) * INNER_RADIUS); + + sky_middle[i][0] = cos((double)theta) * MIDDLE_RADIUS; + sky_middle[i][1] = sin((double)theta) * MIDDLE_RADIUS; + sky_middle[i][2] = MIDDLE_ELEV; + + sky_outer[i][0] = cos((double)theta) * OUTER_RADIUS; + sky_outer[i][1] = sin((double)theta) * OUTER_RADIUS; + sky_outer[i][2] = OUTER_ELEV; + } - xglVertex3fv( sky_center[0] ); - - xglEnd(); - - xglEndList(); } @@ -130,26 +100,16 @@ void fgSkyInit() { void fgSkyRender() { struct fgFLIGHT *f; struct fgVIEW *v; - /* - struct fgLIGHT *l; - struct fgTIME *t; int i; - */ f = ¤t_aircraft.flight; v = ¤t_view; - /* - l = &cur_light_params; - t = &cur_time_params; - */ - - /* 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) */ printf("Rendering the sky.\n"); xglDisable( GL_LIGHTING ); + xglDisable( GL_CULL_FACE ); + xglShadeModel( GL_SMOOTH ); xglPushMatrix(); @@ -158,23 +118,61 @@ void fgSkyRender() { /* 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 ); - xglCallList( sky ); + /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear); + xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */ + + /* Draw inner/center section of sky*/ + xglBegin( GL_TRIANGLE_FAN ); + xglColor4f(0.0, 0.0, 1.0, 1.0); + xglVertex3f(0.0, 0.0, INNER_ELEV); + xglColor4f(0.2, 0.2, 0.8, 1.0); + for ( i = 0; i < 12; i++ ) { + xglVertex3fv( sky_center[i] ); + } + xglVertex3fv( sky_center[0] ); + xglEnd(); + + /* Draw the middle ring */ + xglBegin( GL_TRIANGLE_STRIP ); + for ( i = 0; i < 12; i++ ) { + xglVertex3fv( sky_middle[i] ); + xglVertex3fv( sky_center[i] ); + } + xglVertex3fv( sky_middle[0] ); + xglVertex3fv( sky_center[0] ); + xglEnd(); + + /* Draw the outer ring */ + xglBegin( GL_TRIANGLE_STRIP ); + for ( i = 0; i < 12; i++ ) { + xglVertex3fv( sky_outer[i] ); + xglVertex3fv( sky_middle[i] ); + } + xglVertex3fv( sky_outer[0] ); + xglVertex3fv( sky_middle[0] ); + xglEnd(); xglPopMatrix(); + xglShadeModel( GL_FLAT ); + xglEnable( GL_CULL_FACE ); xglEnable( GL_LIGHTING ); } /* $Log$ -/* Revision 1.2 1997/12/18 04:07:03 curt -/* Worked on properly translating and positioning the sky dome. +/* 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.) From 37ec7421aaeafd3b0051473448107d2f89f9756b Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 19 Dec 1997 16:44:57 +0000 Subject: [PATCH 021/123] Working on scene rendering order and options. --- Scenery/astro.c | 13 +++++-------- Scenery/moon.c | 2 +- Scenery/sky.c | 15 +++++---------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Scenery/astro.c b/Scenery/astro.c index 4e1558e7..d49af701 100644 --- a/Scenery/astro.c +++ b/Scenery/astro.c @@ -87,9 +87,6 @@ void fgAstroRender() { fgMoonInit(); } - /* Disable fog effects */ - xglDisable( GL_FOG ); - /* set the sun position */ /* xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv ); */ @@ -115,16 +112,16 @@ void fgAstroRender() { fgSunRender(); xglPopMatrix(); - - /* reenable fog effects */ - xglEnable( GL_FOG ); } /* $Log$ -/* Revision 1.9 1997/12/18 23:32:35 curt -/* First stab at sky dome actually starting to look reasonable. :-) +/* Revision 1.10 1997/12/19 16:45:01 curt +/* Working on scene rendering order and options. /* + * Revision 1.9 1997/12/18 23:32:35 curt + * First stab at sky dome actually starting to look reasonable. :-) + * * Revision 1.8 1997/12/15 23:54:57 curt * Add xgl wrappers for debugging. * Generate terrain normals on the fly. diff --git a/Scenery/moon.c b/Scenery/moon.c index 203d70bf..17446e30 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -258,7 +258,7 @@ void fgMoonInit() { cos(moonPos.Declination); zMoon = 60000.0 * sin(moonPos.Declination); - glutSolidSphere(1.0, 15, 15); + glutSolidSphere(1.0, 10, 10); xglEndList(); } diff --git a/Scenery/sky.c b/Scenery/sky.c index ef81c8b5..dc262837 100644 --- a/Scenery/sky.c +++ b/Scenery/sky.c @@ -107,10 +107,6 @@ void fgSkyRender() { printf("Rendering the sky.\n"); - xglDisable( GL_LIGHTING ); - xglDisable( GL_CULL_FACE ); - xglShadeModel( GL_SMOOTH ); - xglPushMatrix(); /* Translate to view position */ @@ -159,17 +155,16 @@ void fgSkyRender() { xglEnd(); xglPopMatrix(); - - xglShadeModel( GL_FLAT ); - xglEnable( GL_CULL_FACE ); - xglEnable( GL_LIGHTING ); } /* $Log$ -/* Revision 1.3 1997/12/18 23:32:36 curt -/* First stab at sky dome actually starting to look reasonable. :-) +/* 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. * From 4c18fbcafd5537da23eba3606aff7a16263a90a7 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 19 Dec 1997 23:34:03 +0000 Subject: [PATCH 022/123] Lot's of tweaking with sky rendering and lighting. --- Scenery/moon.c | 13 +++------- Scenery/sky.c | 66 ++++++++++++++++++++++++++++++++++---------------- Scenery/sun.c | 11 +++++---- 3 files changed, 54 insertions(+), 36 deletions(-) diff --git a/Scenery/moon.c b/Scenery/moon.c index 17446e30..22461d60 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -268,24 +268,17 @@ void fgMoonInit() { /* Draw the moon */ void fgMoonRender() { struct fgLIGHT *l; - GLfloat moon_color[4] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; l = &cur_light_params; - /* set lighting parameters */ - xglLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_clear ); - xglLightfv(GL_LIGHT0, GL_DIFFUSE, moon_color ); - - xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear ); - xglMaterialfv(GL_FRONT, GL_AMBIENT, moon_color ); - xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); + xglMaterialfv(GL_FRONT, GL_AMBIENT, l->sky_color ); + xglMaterialfv(GL_FRONT, GL_DIFFUSE, white); xglPushMatrix(); xglTranslatef(xMoon, yMoon, zMoon); xglScalef(1400, 1400, 1400); - xglColor3fv(moon_color); - /* glutSolidSphere(1.0, 25, 25); */ xglCallList(moon); xglPopMatrix(); diff --git a/Scenery/sky.c b/Scenery/sky.c index dc262837..a3844c0b 100644 --- a/Scenery/sky.c +++ b/Scenery/sky.c @@ -52,34 +52,32 @@ */ /* 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 4000.0 +#define MIDDLE_ELEV 8000.0 #define OUTER_RADIUS 80000.0 #define OUTER_ELEV 0.0 -static float sky_center[12][3]; +static float sky_inner[12][3]; static float sky_middle[12][3]; static float sky_outer[12][3]; -/* (Re)generate the display list */ +/* Calculate the sky structure verticies */ void fgSkyInit() { - struct fgLIGHT *l; float theta; int i; - l = &cur_light_params; - printf("Generating the sky dome vertices.\n"); for ( i = 0; i < 12; i++ ) { theta = (i * 30.0) * DEG_TO_RAD; - sky_center[i][0] = cos(theta) * INNER_RADIUS; - sky_center[i][1] = sin(theta) * INNER_RADIUS; - sky_center[i][2] = INNER_ELEV; + sky_inner[i][0] = cos(theta) * INNER_RADIUS; + sky_inner[i][1] = sin(theta) * INNER_RADIUS; + sky_inner[i][2] = INNER_ELEV; printf(" %.2f %.2f\n", cos(theta) * INNER_RADIUS, sin(theta) * INNER_RADIUS); @@ -99,14 +97,32 @@ void fgSkyInit() { /* Draw the Sky */ void fgSkyRender() { struct fgFLIGHT *f; + struct fgLIGHT *l; struct fgVIEW *v; + float inner_color[4], middle_color[4], diff; int i; f = ¤t_aircraft.flight; + l = &cur_light_params; v = ¤t_view; printf("Rendering the sky.\n"); + /* + l->fog_color[0] = 1.0; + l->fog_color[1] = 0.0; + l->fog_color[2] = 0.0; + l->fog_color[3] = 1.0; + */ + + /* calculate transition colors between sky and fog */ + for ( i = 0; i < 3; i++ ) { + diff = l->sky_color[i] - l->fog_color[i]; + inner_color[i] = l->sky_color[i] - diff * 0.3; + middle_color[i] = l->sky_color[i] - diff * 1.0; + } + inner_color[3] = middle_color[3] = l->sky_color[3]; + xglPushMatrix(); /* Translate to view position */ @@ -120,37 +136,42 @@ void fgSkyRender() { 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 ); - /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear); - xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */ - /* Draw inner/center section of sky*/ xglBegin( GL_TRIANGLE_FAN ); - xglColor4f(0.0, 0.0, 1.0, 1.0); - xglVertex3f(0.0, 0.0, INNER_ELEV); - xglColor4f(0.2, 0.2, 0.8, 1.0); + xglColor4fv(l->sky_color); + xglVertex3f(0.0, 0.0, CENTER_ELEV); + xglColor4fv( inner_color ); for ( i = 0; i < 12; i++ ) { - xglVertex3fv( sky_center[i] ); + xglVertex3fv( sky_inner[i] ); } - xglVertex3fv( sky_center[0] ); + xglVertex3fv( sky_inner[0] ); xglEnd(); /* Draw the middle ring */ xglBegin( GL_TRIANGLE_STRIP ); for ( i = 0; i < 12; i++ ) { + xglColor4fv( middle_color ); xglVertex3fv( sky_middle[i] ); - xglVertex3fv( sky_center[i] ); + xglColor4fv( inner_color ); + xglVertex3fv( sky_inner[i] ); } + xglColor4fv( middle_color ); xglVertex3fv( sky_middle[0] ); - xglVertex3fv( sky_center[0] ); + xglColor4fv( inner_color ); + xglVertex3fv( sky_inner[0] ); xglEnd(); /* Draw the outer ring */ xglBegin( GL_TRIANGLE_STRIP ); for ( i = 0; i < 12; i++ ) { + xglColor4fv( l->fog_color ); xglVertex3fv( sky_outer[i] ); + xglColor4fv( middle_color ); xglVertex3fv( sky_middle[i] ); } + xglColor4fv( l->fog_color ); xglVertex3fv( sky_outer[0] ); + xglColor4fv( middle_color ); xglVertex3fv( sky_middle[0] ); xglEnd(); @@ -159,9 +180,12 @@ void fgSkyRender() { /* $Log$ -/* Revision 1.4 1997/12/19 16:45:02 curt -/* Working on scene rendering order and options. +/* 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. :-) * diff --git a/Scenery/sun.c b/Scenery/sun.c index 8b012c3e..08768e6a 100644 --- a/Scenery/sun.c +++ b/Scenery/sun.c @@ -169,10 +169,8 @@ void fgSunRender() { xglTranslatef(xSun, ySun, zSun); xglScalef(1400, 1400, 1400); - xglColor3f(0.85, 0.65, 0.05); + xglColor4f(0.85, 0.65, 0.05, 1.0); - /* xglColor3fv( color ); */ - /* xglutSolidSphere(1.0, 25, 25); */ xglCallList(sun_obj); xglPopMatrix(); @@ -182,9 +180,12 @@ void fgSunRender() { /* $Log$ -/* Revision 1.7 1997/12/17 23:12:16 curt -/* Fixed so moon and sun display lists aren't recreate periodically. +/* 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. From 982d714749055275b00885447532291bd411b9b9 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 22 Dec 1997 04:14:28 +0000 Subject: [PATCH 023/123] Aligned sky with sun so dusk/dawn effects can be correct relative to the sun. --- Scenery/sky.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/Scenery/sky.c b/Scenery/sky.c index a3844c0b..662a3344 100644 --- a/Scenery/sky.c +++ b/Scenery/sky.c @@ -99,7 +99,7 @@ void fgSkyRender() { struct fgFLIGHT *f; struct fgLIGHT *l; struct fgVIEW *v; - float inner_color[4], middle_color[4], diff; + float inner_color[4], middle_color[4], diff, east_dot, dot, angle; int i; f = ¤t_aircraft.flight; @@ -125,6 +125,25 @@ void fgSkyRender() { 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", @@ -135,6 +154,7 @@ void fgSkyRender() { 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 ); @@ -156,8 +176,10 @@ void fgSkyRender() { xglVertex3fv( sky_inner[i] ); } xglColor4fv( middle_color ); + xglColor4f(1.0, 0.0, 0.0, 1.0); xglVertex3fv( sky_middle[0] ); xglColor4fv( inner_color ); + xglColor4f(1.0, 0.0, 0.0, 1.0); xglVertex3fv( sky_inner[0] ); xglEnd(); @@ -180,9 +202,12 @@ void fgSkyRender() { /* $Log$ -/* Revision 1.5 1997/12/19 23:34:59 curt -/* Lot's of tweaking with sky rendering and lighting. +/* 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. * From 13d4d0777fa9f65448b45219006dcb238610d147 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 22 Dec 1997 23:45:45 +0000 Subject: [PATCH 024/123] First stab at sunset/sunrise sky glow effects. --- Scenery/sky.c | 209 +++++++++++++++++++++++++++++++++++++------------- Scenery/sky.h | 12 ++- 2 files changed, 165 insertions(+), 56 deletions(-) diff --git a/Scenery/sky.c b/Scenery/sky.c index 662a3344..6b2b062d 100644 --- a/Scenery/sky.c +++ b/Scenery/sky.c @@ -61,12 +61,17 @@ #define OUTER_ELEV 0.0 -static float sky_inner[12][3]; -static float sky_middle[12][3]; -static float sky_outer[12][3]; +static float inner_vertex[12][3]; +static float middle_vertex[12][3]; +static float outer_vertex[12][3]; -/* Calculate the sky structure verticies */ -void fgSkyInit() { +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() { float theta; int i; @@ -75,31 +80,140 @@ void fgSkyInit() { for ( i = 0; i < 12; i++ ) { theta = (i * 30.0) * DEG_TO_RAD; - sky_inner[i][0] = cos(theta) * INNER_RADIUS; - sky_inner[i][1] = sin(theta) * INNER_RADIUS; - sky_inner[i][2] = INNER_ELEV; + 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); - sky_middle[i][0] = cos((double)theta) * MIDDLE_RADIUS; - sky_middle[i][1] = sin((double)theta) * MIDDLE_RADIUS; - sky_middle[i][2] = MIDDLE_ELEV; + middle_vertex[i][0] = cos((double)theta) * MIDDLE_RADIUS; + middle_vertex[i][1] = sin((double)theta) * MIDDLE_RADIUS; + middle_vertex[i][2] = MIDDLE_ELEV; - sky_outer[i][0] = cos((double)theta) * OUTER_RADIUS; - sky_outer[i][1] = sin((double)theta) * OUTER_RADIUS; - sky_outer[i][2] = OUTER_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; } } +/* (Re)calculate the sky colors at each vertex */ +void fgSkyColorsInit() { + struct fgLIGHT *l; + float sun_angle, diff; + float outer_red_param, outer_red_amt, outer_red_diff; + float middle_red_param, middle_red_amt, middle_red_diff; + 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_red_param = (10.0 - fabs(90.0 - sun_angle)) / 25.0; + outer_red_diff = outer_red_param / 6.0; + } else { + outer_red_param = 0.0; + outer_red_diff = 0.0; + } + printf(" outer_red_param = %.2f outer_red_diff = %.2f\n", + outer_red_param, outer_red_diff); + + if ( (sun_angle > 85.0) && (sun_angle < 95.0) ) { + /* 0.0 - 0.4 */ + middle_red_param = (5.0 - fabs(90.0 - sun_angle)) / 12.5; + middle_red_diff = middle_red_param / 6.0; + } else { + middle_red_param = 0.0; + middle_red_diff = 0.0; + } + printf(" middle_red_param = %.2f middle_red_diff = %.2f\n", + middle_red_param, middle_red_diff); + + /* calculate transition colors between sky and fog */ + outer_red_amt = outer_red_param; + middle_red_amt = middle_red_param; + + 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; + outer_color[i][j] = l->fog_color[j]; + } + outer_color[i][0] += outer_red_amt; + middle_color[i][0] += middle_red_amt; + if ( outer_color[i][0] > 1.0 ) { outer_color[i][0] = 1.0; } + if ( middle_color[i][0] > 1.0 ) { middle_color[i][0] = 1.0; } + inner_color[i][3] = middle_color[i][3] = outer_color[i][3] = + l->sky_color[3]; + + outer_red_amt -= outer_red_diff; + middle_red_amt -= middle_red_diff; + + 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]); + } + + outer_red_amt = 0.0; + middle_red_amt = 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; + outer_color[i][j] = l->fog_color[j]; + } + outer_color[i][0] += outer_red_amt; + middle_color[i][0] += middle_red_amt; + if ( outer_color[i][0] > 1.0 ) { outer_color[i][0] = 1.0; } + if ( middle_color[i][0] > 1.0 ) { middle_color[i][0] = 1.0; } + inner_color[i][3] = middle_color[i][3] = outer_color[i][3] = + l->sky_color[3]; + + outer_red_amt += outer_red_diff; + middle_red_amt += middle_red_diff; + + 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() { + fgSkyVerticesInit(); + fgSkyColorsInit(); +} + + /* Draw the Sky */ void fgSkyRender() { struct fgFLIGHT *f; struct fgLIGHT *l; struct fgVIEW *v; - float inner_color[4], middle_color[4], diff, east_dot, dot, angle; + float /* inner_color[4], middle_color[4], diff, */ east_dot, dot, angle; int i; f = ¤t_aircraft.flight; @@ -108,21 +222,6 @@ void fgSkyRender() { printf("Rendering the sky.\n"); - /* - l->fog_color[0] = 1.0; - l->fog_color[1] = 0.0; - l->fog_color[2] = 0.0; - l->fog_color[3] = 1.0; - */ - - /* calculate transition colors between sky and fog */ - for ( i = 0; i < 3; i++ ) { - diff = l->sky_color[i] - l->fog_color[i]; - inner_color[i] = l->sky_color[i] - diff * 0.3; - middle_color[i] = l->sky_color[i] - diff * 1.0; - } - inner_color[3] = middle_color[3] = l->sky_color[3]; - xglPushMatrix(); /* calculate the angle between v->surface_to_sun and @@ -160,41 +259,42 @@ void fgSkyRender() { xglBegin( GL_TRIANGLE_FAN ); xglColor4fv(l->sky_color); xglVertex3f(0.0, 0.0, CENTER_ELEV); - xglColor4fv( inner_color ); for ( i = 0; i < 12; i++ ) { - xglVertex3fv( sky_inner[i] ); + xglColor4fv( inner_color[i] ); + xglVertex3fv( inner_vertex[i] ); } - xglVertex3fv( sky_inner[0] ); + 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 ); - xglVertex3fv( sky_middle[i] ); - xglColor4fv( inner_color ); - xglVertex3fv( sky_inner[i] ); + xglColor4fv( middle_color[i] ); + xglVertex3fv( middle_vertex[i] ); + xglColor4fv( inner_color[i] ); + xglVertex3fv( inner_vertex[i] ); } - xglColor4fv( middle_color ); - xglColor4f(1.0, 0.0, 0.0, 1.0); - xglVertex3fv( sky_middle[0] ); - xglColor4fv( inner_color ); - xglColor4f(1.0, 0.0, 0.0, 1.0); - xglVertex3fv( sky_inner[0] ); + 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( l->fog_color ); - xglVertex3fv( sky_outer[i] ); - xglColor4fv( middle_color ); - xglVertex3fv( sky_middle[i] ); + xglColor4fv( outer_color[i] ); + xglVertex3fv( outer_vertex[i] ); + xglColor4fv( middle_color[i] ); + xglVertex3fv( middle_vertex[i] ); } - xglColor4fv( l->fog_color ); - xglVertex3fv( sky_outer[0] ); - xglColor4fv( middle_color ); - xglVertex3fv( sky_middle[0] ); + xglColor4fv( outer_color[0] ); + xglVertex3fv( outer_vertex[0] ); + xglColor4fv( middle_color[0] ); + xglVertex3fv( middle_vertex[0] ); xglEnd(); xglPopMatrix(); @@ -202,9 +302,12 @@ void fgSkyRender() { /* $Log$ -/* 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.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. * diff --git a/Scenery/sky.h b/Scenery/sky.h index 4fdcc0db..f5bd771b 100644 --- a/Scenery/sky.h +++ b/Scenery/sky.h @@ -27,13 +27,19 @@ /* (Re)generate the display list */ void fgSkyInit(); +/* (Re)calculate the sky colors at each vertex */ +void fgSkyColorsInit(); + /* Draw the Sky */ void fgSkyRender(); /* $Log$ -/* 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.) +/* 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.) + * */ From e4890297a6a843f3130468a6afa5fb209532d130 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 23 Dec 1997 04:58:38 +0000 Subject: [PATCH 025/123] Tweaked the sky coloring a bit to build in structures to allow finer rgb control. --- Scenery/sky.c | 97 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 40 deletions(-) diff --git a/Scenery/sky.c b/Scenery/sky.c index 6b2b062d..bbd8aeab 100644 --- a/Scenery/sky.c +++ b/Scenery/sky.c @@ -103,8 +103,8 @@ void fgSkyVerticesInit() { void fgSkyColorsInit() { struct fgLIGHT *l; float sun_angle, diff; - float outer_red_param, outer_red_amt, outer_red_diff; - float middle_red_param, middle_red_amt, middle_red_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; @@ -117,46 +117,55 @@ void fgSkyColorsInit() { if ( (sun_angle > 80.0) && (sun_angle < 100.0) ) { /* 0.0 - 0.4 */ - outer_red_param = (10.0 - fabs(90.0 - sun_angle)) / 25.0; - outer_red_diff = outer_red_param / 6.0; - } else { - outer_red_param = 0.0; - outer_red_diff = 0.0; - } - printf(" outer_red_param = %.2f outer_red_diff = %.2f\n", - outer_red_param, outer_red_diff); + outer_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 25.0; + outer_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 45.0; + outer_param[2] = 0.0; - if ( (sun_angle > 85.0) && (sun_angle < 95.0) ) { - /* 0.0 - 0.4 */ - middle_red_param = (5.0 - fabs(90.0 - sun_angle)) / 12.5; - middle_red_diff = middle_red_param / 6.0; + middle_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 40.0; + middle_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 60.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 { - middle_red_param = 0.0; - middle_red_diff = 0.0; + 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(" middle_red_param = %.2f middle_red_diff = %.2f\n", - middle_red_param, middle_red_diff); + /* printf(" outer_red_param = %.2f outer_red_diff = %.2f\n", + outer_red_param, outer_red_diff); */ /* calculate transition colors between sky and fog */ - outer_red_amt = outer_red_param; - middle_red_amt = middle_red_param; + 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; - outer_color[i][j] = l->fog_color[j]; + 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.0 ) { middle_color[i][j] = 1.0; } + if ( outer_color[i][j] > 1.0 ) { outer_color[i][j] = 1.0; } } - outer_color[i][0] += outer_red_amt; - middle_color[i][0] += middle_red_amt; - if ( outer_color[i][0] > 1.0 ) { outer_color[i][0] = 1.0; } - if ( middle_color[i][0] > 1.0 ) { middle_color[i][0] = 1.0; } inner_color[i][3] = middle_color[i][3] = outer_color[i][3] = l->sky_color[3]; - outer_red_amt -= outer_red_diff; - middle_red_amt -= middle_red_diff; + 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]); @@ -168,26 +177,30 @@ void fgSkyColorsInit() { outer_color[i][3]); } - outer_red_amt = 0.0; - middle_red_amt = 0.0; + 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; - outer_color[i][j] = l->fog_color[j]; + 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.0 ) { middle_color[i][j] = 1.0; } + if ( outer_color[i][j] > 1.0 ) { outer_color[i][j] = 1.0; } } - outer_color[i][0] += outer_red_amt; - middle_color[i][0] += middle_red_amt; - if ( outer_color[i][0] > 1.0 ) { outer_color[i][0] = 1.0; } - if ( middle_color[i][0] > 1.0 ) { middle_color[i][0] = 1.0; } inner_color[i][3] = middle_color[i][3] = outer_color[i][3] = l->sky_color[3]; - outer_red_amt += outer_red_diff; - middle_red_amt += middle_red_diff; + 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]); @@ -302,9 +315,13 @@ void fgSkyRender() { /* $Log$ -/* Revision 1.7 1997/12/22 23:45:48 curt -/* First stab at sunset/sunrise sky glow effects. +/* 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. * From de235cc8beb741f778a40fbb5eaa9f170ec4f059 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 30 Dec 1997 13:06:56 +0000 Subject: [PATCH 026/123] A couple lighting tweaks ... --- Scenery/sky.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Scenery/sky.c b/Scenery/sky.c index bbd8aeab..2024f444 100644 --- a/Scenery/sky.c +++ b/Scenery/sky.c @@ -156,8 +156,10 @@ void fgSkyColorsInit() { 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.0 ) { middle_color[i][j] = 1.0; } - if ( outer_color[i][j] > 1.0 ) { outer_color[i][j] = 1.0; } + 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]; @@ -191,8 +193,10 @@ void fgSkyColorsInit() { 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.0 ) { middle_color[i][j] = 1.0; } - if ( outer_color[i][j] > 1.0 ) { outer_color[i][j] = 1.0; } + 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]; @@ -315,10 +319,13 @@ void fgSkyRender() { /* $Log$ -/* 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.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. * From 5c5e4fff7bda0252822da36d65fb1960b4b9b21a Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 30 Dec 1997 16:36:40 +0000 Subject: [PATCH 027/123] Merged in Durk's changes ... --- Scenery/moon.c | 157 +++++++++++++++++++++++++++------------------- Scenery/orbits.h | 9 ++- Scenery/planets.c | 61 ++++++++++++++++-- Scenery/planets.h | 9 ++- Scenery/sun.c | 41 +++++++----- 5 files changed, 189 insertions(+), 88 deletions(-) diff --git a/Scenery/moon.c b/Scenery/moon.c index 22461d60..839de32f 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -28,6 +28,7 @@ #include "orbits.h" #include "moon.h" +#include "../Aircraft/aircraft.h" #include "../Include/general.h" #include "../Main/views.h" #include "../Time/fg_time.h" @@ -148,80 +149,110 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, struct OrbElements sunParams, struct fgTIME t) { - struct CelestialCoord - result; - - double - eccAnom, ecl, lonecl, latecl, actTime, - xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze, - Ls, Lm, D, F; + 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; + + struct fgAIRCRAFT *a; + struct fgFLIGHT *f; - /* calculate the angle between ecliptic and equatorial coordinate system */ - actTime = fgCalcActTime(t); - ecl = fgDegToRad(23.4393 - 3.563E-7 * actTime); // in radians of course + a = ¤t_aircraft; + f = &a->flight; + +/* calculate the angle between ecliptic and equatorial coordinate system */ + actTime = fgCalcActTime(t); + ecl = fgDegToRad(23.4393 - 3.563E-7 * actTime); // in radians of course + + /* calculate the eccentric anomaly */ + eccAnom = fgCalcEccAnom(params.M, params.e); - /* calculate the eccentric anomaly */ - eccAnom = fgCalcEccAnom(params.M, params.e); + /* calculate the moon's distance (d) and true anomaly (v) */ + 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 the moon's distance (d) 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); + /* calculate a number of perturbations */ + Ls = sunParams.M + sunParams.w; + Lm = params.M + params.w + params.N; + D = Lm - Ls; + F = Lm - params.N; + + lonecl += fgDegToRad( + - 1.274 * sin (params.M - 2*D) // the Evection + + 0.658 * sin (2 * D) // the Variation + - 0.186 * sin (sunParams.M) // the yearly variation + - 0.059 * sin (2*params.M - 2*D) + - 0.057 * sin (params.M - 2*D + sunParams.M) + + 0.053 * sin (params.M + 2*D) + + 0.046 * sin (2*D - sunParams.M) + + 0.041 * sin (params.M - sunParams.M) + - 0.035 * sin (D) // the Parallactic Equation + - 0.031 * sin (params.M + sunParams.M) + - 0.015 * sin (2*F - 2*D) + + 0.011 * sin (params.M - 4*D) + ); /* Pheeuuwwww */ + latecl += fgDegToRad( + - 0.173 * sin (F - 2*D) + - 0.055 * sin (params.M - F - 2*D) + - 0.046 * sin (params.M + F - 2*D) + + 0.033 * sin (F + 2*D) + + 0.017 * sin (2 * params.M + F) + ); /* Yep */ - /* 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)); + r += ( + - 0.58 * cos(params.M - 2*D) + - 0.46 * cos(2*D) + ); /* Ok! */ - /* calculate the ecliptic latitude and longitude here */ - lonecl = atan2( yh, xh); - latecl = atan2( zh, sqrt( xh*xh + yh*yh)); + xg = r * cos(lonecl) * cos(latecl); + yg = r * sin(lonecl) * cos(latecl); + zg = r * sin(latecl); - /* calculate a number of perturbations */ - Ls = sunParams.M + sunParams.w; - Lm = params.M + params.w + params.N; - D = Lm - Ls; - F = Lm - params.N; + xe = xg; + ye = yg * cos(ecl) - zg * sin(ecl); + ze = yg * sin(ecl) + zg * cos(ecl); + - lonecl += fgDegToRad( - - 1.274 * sin (params.M - 2*D) // the Evection - + 0.658 * sin (2 * D) // the Variation - - 0.186 * sin (sunParams.M) // the yearly variation - - 0.059 * sin (2*params.M - 2*D) - - 0.057 * sin (params.M - 2*D + sunParams.M) - + 0.053 * sin (params.M + 2*D) - + 0.046 * sin (2*D - sunParams.M) - + 0.041 * sin (params.M - sunParams.M) - - 0.035 * sin (D) // the Parallactic Equation - - 0.031 * sin (params.M + sunParams.M) - - 0.015 * sin (2*F - 2*D) - + 0.011 * sin (params.M - 4*D) - ); /* Pheeuuwwww */ - latecl += fgDegToRad( - - 0.173 * sin (F - 2*D) - - 0.055 * sin (params.M - F - 2*D) - - 0.046 * sin (params.M + F - 2*D) - + 0.033 * sin (F + 2*D) - + 0.017 * sin (2 * params.M + F) - ); /* Yep */ + - r += ( - - 0.58 * cos(params.M - 2*D) - - 0.46 * cos(2*D) - ); /* Ok! */ + 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! */ - xg = r * cos(lonecl) * cos(latecl); - yg = r * sin(lonecl) * cos(latecl); - zg = r * sin(latecl); + mpar = asin( 1 / r); /* calculate the moon's parrallax, i.e. the apparent size of the + (equatorial) radius of the Earth, as seen from the moon */ + gclat = FG_Latitude - 0.083358 * sin (2 * fgDegToRad( FG_Latitude)); + rho = 0.99883 + 0.00167 * cos(2 * fgDegToRad(FG_Latitude)); - xe = xg; - ye = yg * cos(ecl) - zg * sin(ecl); - ze = yg * sin(ecl) + zg * cos(ecl); + if (geocCoord.RightAscension < 0) + geocCoord.RightAscension += (2*M_PI); - result.RightAscension = atan2(ye, xe); - result.Declination = atan2(ze, sqrt(xe*xe + ye*ye)); - return result; + 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; } diff --git a/Scenery/orbits.h b/Scenery/orbits.h index 2ce03b12..c51b305e 100644 --- a/Scenery/orbits.h +++ b/Scenery/orbits.h @@ -40,6 +40,7 @@ struct SunPos { double xs; double ys; + double dist; }; struct OrbElements { @@ -63,6 +64,7 @@ struct CelestialCoord { double RightAscension; double Declination; double distance; + double magnitude; }; @@ -79,7 +81,10 @@ void fgSolarSystemUpdate(struct OrbElements *planets, struct fgTIME t); /* $Log$ -/* Revision 1.1 1997/10/25 03:16:10 curt -/* Initial revision of code contributed by Durk Talsma. +/* 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/Scenery/planets.c b/Scenery/planets.c index b4e2bb16..4aeaf0c9 100644 --- a/Scenery/planets.c +++ b/Scenery/planets.c @@ -31,7 +31,7 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, struct OrbElements theSun, - struct fgTIME t) + struct fgTIME t, int idx) { struct CelestialCoord result; @@ -40,7 +40,7 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, SolarPosition; double - eccAnom, r, v, ecl, actTime, + 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); @@ -77,18 +77,69 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, xe = xg; ye = yg * cos(ecl) - zg * sin(ecl); - ze = yg * sin(ecl) + zg * cos(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 (abs(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: + printf("index %d out of range !!!!\n", idx); + } + printf("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; } + /* $Log$ -/* Revision 1.2 1997/12/12 21:41:29 curt -/* More light/material property tweaking ... still a ways off. +/* 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/Scenery/planets.h b/Scenery/planets.h index dfbc35fe..3d5df465 100644 --- a/Scenery/planets.h +++ b/Scenery/planets.h @@ -29,15 +29,18 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, struct OrbElements theSun, - struct fgTIME t); + struct fgTIME t, int idx); #endif /* PLANETS_H */ /* $Log$ -/* Revision 1.2 1997/12/12 21:41:30 curt -/* More light/material property tweaking ... still a ways off. +/* 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/Scenery/sun.c b/Scenery/sun.c index 08768e6a..2630136f 100644 --- a/Scenery/sun.c +++ b/Scenery/sun.c @@ -60,6 +60,7 @@ struct SunPos fgCalcSunPos(struct OrbElements params) coordinates (xs, ys) */ solarPosition.xs = r * cos(lonSun); solarPosition.ys = r * sin(lonSun); + solarPosition.dist = r; return solarPosition; } @@ -126,23 +127,27 @@ void fgSunInit() { void fgSunRender() { struct fgVIEW *v; struct fgTIME *t; - GLfloat color[4] = { 0.85, 0.65, 0.05, 1.0 }; - /* double x_2, x_4, x_8, x_10; */ - /* GLfloat ambient; */ - /* GLfloat amb[3], diff[3]; */ + struct fgLIGHT *l; + /* GLfloat color[4] = { 0.85, 0.65, 0.05, 1.0 }; */ + GLfloat color[4] = { 1.00, 1.00, 1.00, 1.00 }; + double x_2, x_4, x_8, x_10; + GLfloat ambient; + GLfloat amb[3], diff[3]; t = &cur_time_params; v = ¤t_view; + l = &cur_light_params; - /* x_2 = t->sun_angle * t->sun_angle; + x_2 = l->sun_angle * l->sun_angle; x_4 = x_2 * x_2; x_8 = x_4 * x_4; - x_10 = x_8 * x_2; */ + x_10 = x_8 * x_2; - /* ambient = (0.4 * pow(1.1, -x_10 / 30.0)); + ambient = (0.4 * pow(1.1, -x_10 / 30.0)); if ( ambient < 0.3 ) ambient = 0.3; if ( ambient > 1.0 ) ambient = 1.0; + amb[0] = 0.50 + ((ambient * 6.66) - 1.6); amb[1] = 0.00 + ((ambient * 6.66) - 1.6); amb[2] = 0.00 + ((ambient * 6.66) - 1.6); @@ -155,34 +160,40 @@ void fgSunRender() { diff[0] = 0.0; diff[1] = 0.0; diff[2] = 0.0; - diff[3] = 0.0; */ + diff[3] = 1.0; /* set lighting parameters */ - /* xglLightfv(GL_LIGHT0, GL_AMBIENT, color ); + xglLightfv(GL_LIGHT0, GL_AMBIENT, color ); xglLightfv(GL_LIGHT0, GL_DIFFUSE, color ); xglMaterialfv(GL_FRONT, GL_AMBIENT, amb); - xglMaterialfv(GL_FRONT, GL_DIFFUSE, diff); */ + xglMaterialfv(GL_FRONT, GL_DIFFUSE, diff); + xglMaterialfv(GL_FRONT, GL_SHININESS, diff); + xglMaterialfv(GL_FRONT, GL_EMISSION, diff); + xglMaterialfv(GL_FRONT, GL_SPECULAR, diff); - xglDisable( GL_LIGHTING ); + /* xglDisable( GL_LIGHTING ); */ xglPushMatrix(); xglTranslatef(xSun, ySun, zSun); xglScalef(1400, 1400, 1400); - xglColor4f(0.85, 0.65, 0.05, 1.0); + xglColor3f(0.85, 0.65, 0.05); xglCallList(sun_obj); xglPopMatrix(); - xglEnable( GL_LIGHTING ); + /* xglEnable( GL_LIGHTING ); */ } /* $Log$ -/* Revision 1.8 1997/12/19 23:35:00 curt -/* Lot's of tweaking with sky rendering and lighting. +/* 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. * From 9bd9645b3e08e8860aec49a5d22b592cc1494916 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 30 Dec 1997 16:41:00 +0000 Subject: [PATCH 028/123] Added log at end of file. --- Scenery/moon.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Scenery/moon.c b/Scenery/moon.c index 839de32f..fcf038f2 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -315,3 +315,9 @@ void fgMoonRender() { xglPopMatrix(); } + +/* $Log$ +/* Revision 1.13 1997/12/30 16:41:00 curt +/* Added log at end of file. +/* + */ From bf92d30877fa3ba6647b2e6fec0308503ed4bac6 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 30 Dec 1997 20:47:34 +0000 Subject: [PATCH 029/123] Integrated new event manager with subsystem initializations. --- Scenery/moon.c | 9 +++++++-- Scenery/orbits.c | 22 ++++++++++++++-------- Scenery/planets.c | 19 ++++++++++++------- Scenery/sky.c | 27 ++++++++++++++++++++------- Scenery/sun.c | 9 +++++++-- 5 files changed, 60 insertions(+), 26 deletions(-) diff --git a/Scenery/moon.c b/Scenery/moon.c index fcf038f2..bc2592b0 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -260,6 +260,8 @@ void fgMoonInit() { struct fgLIGHT *l; static int dl_exists = 0; + printf("Initializing the Moon\n"); + l = &cur_light_params; /* position the moon */ @@ -317,7 +319,10 @@ void fgMoonRender() { /* $Log$ -/* Revision 1.13 1997/12/30 16:41:00 curt -/* Added log at end of file. +/* 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/Scenery/orbits.c b/Scenery/orbits.c index 8ff0f182..99ddd635 100644 --- a/Scenery/orbits.c +++ b/Scenery/orbits.c @@ -53,10 +53,11 @@ double fgCalcActTime(struct fgTIME t) actTime += (UT / 24.0); #define DEBUG 1 #ifdef DEBUG - printf("Actual Time:\n"); - printf("current day = %f\t", actTime); - printf("GMT = %d, %d, %d, %d, %d, %d\n", year, t.gmt->tm_mon, t.gmt->tm_mday, - t.gmt->tm_hour, t.gmt->tm_min, t.gmt->tm_sec); + /* printf(" Actual Time:\n"); */ + /* printf(" current day = %f\t", actTime); */ + /* printf(" GMT = %d, %d, %d, %d, %d, %d\n", + year, t.gmt->tm_mon, t.gmt->tm_mday, + t.gmt->tm_hour, t.gmt->tm_min, t.gmt->tm_sec); */ #endif return actTime; } @@ -124,6 +125,8 @@ void fgSolarSystemInit(struct fgTIME t) int i; FILE *data; + printf("Initializing solar system\n"); + /* build the full path name to the orbital elements database file */ g = &general; path[0] = '\0'; @@ -137,7 +140,7 @@ void fgSolarSystemInit(struct fgTIME t) return; } #ifdef DEBUG - printf("reading datafile %s", path); + printf(" reading datafile %s\n", path); #endif /* for all the objects... */ @@ -170,10 +173,13 @@ void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t) /* $Log$ -/* Revision 1.5 1997/12/15 23:55:02 curt -/* Add xgl wrappers for debugging. -/* Generate terrain normals on the fly. +/* 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 {}" diff --git a/Scenery/planets.c b/Scenery/planets.c index 4aeaf0c9..cd2171c5 100644 --- a/Scenery/planets.c +++ b/Scenery/planets.c @@ -120,20 +120,25 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, default: printf("index %d out of range !!!!\n", idx); } - printf("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); + printf(" Planet found at %f (ra), %f (dec)\n", + result.RightAscension, result.Declination); + printf(" 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; } /* $Log$ -/* Revision 1.3 1997/12/30 16:36:52 curt -/* Merged in Durk's changes ... +/* 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. * diff --git a/Scenery/sky.c b/Scenery/sky.c index 2024f444..d73f5718 100644 --- a/Scenery/sky.c +++ b/Scenery/sky.c @@ -40,6 +40,7 @@ #include "sky.h" +#include "../Time/event.h" #include "../Time/fg_time.h" #include "../Aircraft/aircraft.h" @@ -75,7 +76,7 @@ void fgSkyVerticesInit() { float theta; int i; - printf("Generating the sky dome vertices.\n"); + printf(" Generating the sky dome vertices.\n"); for ( i = 0; i < 12; i++ ) { theta = (i * 30.0) * DEG_TO_RAD; @@ -84,8 +85,8 @@ void fgSkyVerticesInit() { 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); + /* 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; @@ -109,7 +110,7 @@ void fgSkyColorsInit() { l = &cur_light_params; - printf("Generating the sky colors for each vertex.\n"); + printf(" Generating the sky colors for each vertex.\n"); /* setup for the possibility of sunset effects */ sun_angle = l->sun_angle * RAD_TO_DEG; @@ -169,6 +170,7 @@ void fgSkyColorsInit() { 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, @@ -177,6 +179,7 @@ void fgSkyColorsInit() { 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++ ) { @@ -206,6 +209,7 @@ void fgSkyColorsInit() { 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, @@ -214,14 +218,20 @@ void fgSkyColorsInit() { 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() { + printf("Initializing the sky\n"); + fgSkyVerticesInit(); - fgSkyColorsInit(); + + /* regester fgSkyColorsInit() as an event to be run periodically */ + fgEventRegister("fgSkyColorsInit()", fgSkyColorsInit, + FG_EVENT_READY, 30000); } @@ -319,9 +329,12 @@ void fgSkyRender() { /* $Log$ -/* Revision 1.9 1997/12/30 13:06:57 curt -/* A couple lighting tweaks ... +/* 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. diff --git a/Scenery/sun.c b/Scenery/sun.c index 2630136f..372044a7 100644 --- a/Scenery/sun.c +++ b/Scenery/sun.c @@ -97,6 +97,8 @@ struct CelestialCoord fgCalculateSun(struct OrbElements params, struct fgTIME t) void fgSunInit() { static int dl_exists = 0; + printf("Initializing the Sun\n"); + fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params); sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params); #ifdef DEBUG @@ -188,9 +190,12 @@ void fgSunRender() { /* $Log$ -/* Revision 1.9 1997/12/30 16:36:54 curt -/* Merged in Durk's changes ... +/* 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. * From 5909595442b9a10959ed2847cc98398794d707f0 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 30 Dec 1997 22:22:31 +0000 Subject: [PATCH 030/123] Further integration of event manager. --- Scenery/sky.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Scenery/sky.c b/Scenery/sky.c index d73f5718..e34e6c7b 100644 --- a/Scenery/sky.c +++ b/Scenery/sky.c @@ -247,7 +247,7 @@ void fgSkyRender() { l = &cur_light_params; v = ¤t_view; - printf("Rendering the sky.\n"); + /* printf("Rendering the sky.\n"); */ xglPushMatrix(); @@ -255,20 +255,20 @@ void fgSkyRender() { * 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); + /* 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); + /* 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); + /*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 ); @@ -276,8 +276,8 @@ void fgSkyRender() { 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); + /* 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 ); @@ -329,9 +329,12 @@ void fgSkyRender() { /* $Log$ -/* Revision 1.10 1997/12/30 20:47:53 curt -/* Integrated new event manager with subsystem initializations. +/* 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 ... * From 66651d064863c34bf5deadc29f59984ed017f663 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 30 Dec 1997 23:09:40 +0000 Subject: [PATCH 031/123] Worked on winding problem without luck, so back to calling glFrontFace() 3 times for each scenery area. --- Scenery/sun.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Scenery/sun.c b/Scenery/sun.c index 372044a7..5aa32341 100644 --- a/Scenery/sun.c +++ b/Scenery/sun.c @@ -97,7 +97,7 @@ struct CelestialCoord fgCalculateSun(struct OrbElements params, struct fgTIME t) void fgSunInit() { static int dl_exists = 0; - printf("Initializing the Sun\n"); + printf(" Initializing the Sun\n"); fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params); sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params); @@ -190,9 +190,13 @@ void fgSunRender() { /* $Log$ -/* Revision 1.10 1997/12/30 20:47:54 curt -/* Integrated new event manager with subsystem initializations. +/* 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 ... * From f2e77048537e65552373126e39ec109171cc6f4f Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 5 Jan 1998 18:44:33 +0000 Subject: [PATCH 032/123] Add an option to advance/decrease time from keyboard. --- Scenery/moon.c | 19 +++++++++++-------- Scenery/sun.c | 17 ++++++++++------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Scenery/moon.c b/Scenery/moon.c index bc2592b0..4f4652be 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -273,6 +273,10 @@ void fgMoonInit() { moonPos.Declination); #endif + 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 ( !dl_exists ) { dl_exists = 1; @@ -285,12 +289,6 @@ void fgMoonInit() { xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */ - xMoon = 60000.0 * cos(moonPos.RightAscension) * - cos(moonPos.Declination); - yMoon = 60000.0 * sin(moonPos.RightAscension) * - cos(moonPos.Declination); - zMoon = 60000.0 * sin(moonPos.Declination); - glutSolidSphere(1.0, 10, 10); xglEndList(); @@ -303,6 +301,8 @@ void fgMoonRender() { struct fgLIGHT *l; GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; + /* printf("Rendering moon\n"); */ + l = &cur_light_params; xglMaterialfv(GL_FRONT, GL_AMBIENT, l->sky_color ); @@ -319,9 +319,12 @@ void fgMoonRender() { /* $Log$ -/* Revision 1.14 1997/12/30 20:47:50 curt -/* Integrated new event manager with subsystem initializations. +/* 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/Scenery/sun.c b/Scenery/sun.c index 5aa32341..d68d179a 100644 --- a/Scenery/sun.c +++ b/Scenery/sun.c @@ -106,6 +106,10 @@ void fgSunInit() { sunPos.Declination); #endif + xSun = 60000.0 * cos(sunPos.RightAscension) * cos(sunPos.Declination); + ySun = 60000.0 * sin(sunPos.RightAscension) * cos(sunPos.Declination); + zSun = 60000.0 * sin(sunPos.Declination); + if ( !dl_exists ) { dl_exists = 1; @@ -114,10 +118,6 @@ void fgSunInit() { sun_obj = xglGenLists(1); xglNewList(sun_obj, GL_COMPILE ); - xSun = 60000.0 * cos(sunPos.RightAscension) * cos(sunPos.Declination); - ySun = 60000.0 * sin(sunPos.RightAscension) * cos(sunPos.Declination); - zSun = 60000.0 * sin(sunPos.Declination); - glutSolidSphere(1.0, 10, 10); xglEndList(); @@ -190,10 +190,13 @@ void fgSunRender() { /* $Log$ -/* 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.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. * From 0363628a55af58550fc9878b174bd9ed2aca9bed Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 6 Jan 1998 01:20:16 +0000 Subject: [PATCH 033/123] Tweaks to help building with MSVC++ --- Scenery/moon.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Scenery/moon.c b/Scenery/moon.c index 4f4652be..dd39f072 100644 --- a/Scenery/moon.c +++ b/Scenery/moon.c @@ -29,6 +29,7 @@ #include "moon.h" #include "../Aircraft/aircraft.h" +#include "../Include/constants.h" #include "../Include/general.h" #include "../Main/views.h" #include "../Time/fg_time.h" @@ -242,7 +243,7 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, rho = 0.99883 + 0.00167 * cos(2 * fgDegToRad(FG_Latitude)); if (geocCoord.RightAscension < 0) - geocCoord.RightAscension += (2*M_PI); + geocCoord.RightAscension += (2*FG_PI); HA = t.lst - (3.8197186 * geocCoord.RightAscension); @@ -319,9 +320,12 @@ void fgMoonRender() { /* $Log$ -/* Revision 1.15 1998/01/05 18:44:35 curt -/* Add an option to advance/decrease time from keyboard. +/* 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. * From 7b3b55f6ef520f0b77d144a0f318e4ff57f9624b Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 7 Jan 1998 03:06:12 +0000 Subject: [PATCH 034/123] Moved from .../Src/Scenery/ to .../Src/Astro/ --- Astro/Makefile | 165 ++++++++++++++++ Astro/depend | 56 ++++++ {Scenery => Astro}/moon.c | 7 +- {Scenery => Astro}/moon.h | 9 +- {Scenery => Astro}/orbits.c | 7 +- {Scenery => Astro}/orbits.h | 7 +- {Scenery => Astro}/planets.c | 7 +- {Scenery => Astro}/planets.h | 7 +- {Scenery => Astro}/sky.c | 7 +- {Scenery => Astro}/sky.h | 7 +- Astro/stars.c | 357 +++++++++++++++++++++++++++++++++++ Astro/stars.h | 69 +++++++ {Scenery => Astro}/sun.c | 7 +- {Scenery => Astro}/sun.h | 9 +- Scenery/astro.c | 152 --------------- Scenery/astro.h | 61 ------ 16 files changed, 699 insertions(+), 235 deletions(-) create mode 100644 Astro/Makefile create mode 100644 Astro/depend rename {Scenery => Astro}/moon.c (98%) rename {Scenery => Astro}/moon.h (89%) rename {Scenery => Astro}/orbits.c (96%) rename {Scenery => Astro}/orbits.h (94%) rename {Scenery => Astro}/planets.c (95%) rename {Scenery => Astro}/planets.h (89%) rename {Scenery => Astro}/sky.c (98%) rename {Scenery => Astro}/sky.h (88%) create mode 100644 Astro/stars.c create mode 100644 Astro/stars.h rename {Scenery => Astro}/sun.c (97%) rename {Scenery => Astro}/sun.h (87%) delete mode 100644 Scenery/astro.c delete mode 100644 Scenery/astro.h diff --git a/Astro/Makefile b/Astro/Makefile new file mode 100644 index 00000000..24e85c65 --- /dev/null +++ b/Astro/Makefile @@ -0,0 +1,165 @@ +#--------------------------------------------------------------------------- +# Makefile +# +# Written by Curtis Olson, started May 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) +#--------------------------------------------------------------------------- + + +TARGET = libAstro.a + +CFILES = moon.c orbits.c planets.c sky.c stars.c sun.c + +OFILES = $(CFILES:.c=.o) + + +include ../make.inc + + +CFLAGS = $(FG_CFLAGS) + + +#--------------------------------------------------------------------------- +# Primary Targets +#--------------------------------------------------------------------------- + +$(TARGET): $(OFILES) $(HFILES) + $(AR) rv $(TARGET) $(OFILES) + $(RANLIB) $(TARGET) + +all: $(TARGET) + +clean: + rm -f *.o $(TARGET) lib*.a *.os2 *~ core + +realclean: clean + + +#--------------------------------------------------------------------------- +# Secondary Targets +#--------------------------------------------------------------------------- + +include depend + +moon.o: + $(CC) $(CFLAGS) -c moon.c -o $@ + +orbits.o: + $(CC) $(CFLAGS) -c orbits.c -o $@ + +planets.o: + $(CC) $(CFLAGS) -c planets.c -o $@ + +sky.c: + $(CC) $(CFLAGS) -c sky.c -o $@ + +stars.c: + $(CC) $(CFLAGS) -c stars.c -o $@ + +sun.o: + $(CC) $(CFLAGS) -c sun.c -o $@ + + + +#--------------------------------------------------------------------------- +# $Log$ +# Revision 1.1 1998/01/07 03:16:15 curt +# Moved from .../Src/Scenery/ to .../Src/Astro/ +# +# Revision 1.26 1997/12/19 16:45:01 curt +# Working on scene rendering order and options. +# +# Revision 1.25 1997/12/17 23:13:45 curt +# Began working on rendering the sky. +# +# Revision 1.24 1997/11/25 19:25:33 curt +# Changes to integrate Durk's moon/sun code updates + clean up. +# +# Revision 1.23 1997/10/28 21:00:20 curt +# Changing to new terrain format. +# +# Revision 1.22 1997/10/25 03:30:07 curt +# Misc. tweaks. +# +# Revision 1.21 1997/10/25 03:18:26 curt +# Incorporated sun, moon, and planet position and rendering code contributed +# by Durk Talsma. +# +# Revision 1.20 1997/09/22 14:44:21 curt +# Continuing to try to align stars correctly. +# +# Revision 1.19 1997/08/27 03:30:23 curt +# Changed naming scheme of basic shared structures. +# +# Revision 1.18 1997/08/02 19:10:12 curt +# Incorporated mesh2GL.c into mesh.c +# +# Revision 1.17 1997/07/23 21:52:23 curt +# Put comments around the text after an #endif for increased portability. +# +# Revision 1.16 1997/07/20 02:19:11 curt +# First stab at a system to generate os2 makefiles automatically. +# +# Revision 1.15 1997/07/12 02:24:47 curt +# Added ranlib. +# +# Revision 1.14 1997/06/29 21:16:47 curt +# More twiddling with the Scenery Management system. +# +# Revision 1.13 1997/06/27 21:38:10 curt +# Working on Makefile structure. +# +# Revision 1.12 1997/06/27 20:03:37 curt +# Working on Makefile structure. +# +# Revision 1.11 1997/06/26 22:14:57 curt +# Beginning work on a scenery management system. +# +# Revision 1.10 1997/06/26 19:08:34 curt +# Restructuring make, adding automatic "make dep" support. +# +# Revision 1.9 1997/06/25 15:39:48 curt +# Minor changes to compile with rsxnt/win32. +# +# Revision 1.8 1997/06/21 17:58:07 curt +# directory shuffling ... +# +# Revision 1.1 1997/06/21 17:39:28 curt +# Moved to the ParseScn subdirectory. +# +# Revision 1.6 1997/06/21 17:12:55 curt +# Capitalized subdirectory names. +# +# Revision 1.5 1997/05/31 19:16:29 curt +# Elevator trim added. +# +# Revision 1.4 1997/05/27 17:48:50 curt +# Added -f flag to flex to generate a "fast" scanner. +# +# Revision 1.3 1997/05/23 15:40:40 curt +# Added GNU copyright headers. +# +# Revision 1.2 1997/05/17 00:17:01 curt +# Cosmetic changes. +# +# Revision 1.1 1997/05/16 16:07:02 curt +# Initial revision. +# diff --git a/Astro/depend b/Astro/depend new file mode 100644 index 00000000..a948633f --- /dev/null +++ b/Astro/depend @@ -0,0 +1,56 @@ +astro.o: astro.c ../XGL/xgl.h astro.h stars.h moon.h orbits.h \ + ../Time/fg_time.h ../Time/../Include/types.h \ + ../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \ + ../Time/../Flight/LaRCsim/ls_interface.h \ + ../Time/../Flight/LaRCsim/../flight.h planets.h sun.h \ + ../Include/constants.h ../Include/general.h ../Main/views.h \ + ../Main/../Include/types.h ../Main/../Flight/flight.h \ + ../Main/../Math/mat3.h ../Main/../Time/fg_time.h \ + ../Aircraft/aircraft.h ../Aircraft/../Flight/flight.h \ + ../Aircraft/../Controls/controls.h \ + ../Aircraft/../Controls/../Include/limits.h +moon.o: moon.c ../XGL/xgl.h orbits.h ../Time/fg_time.h \ + ../Time/../Include/types.h ../Time/../Flight/flight.h \ + ../Time/../Flight/Slew/slew.h \ + ../Time/../Flight/LaRCsim/ls_interface.h \ + ../Time/../Flight/LaRCsim/../flight.h moon.h ../Aircraft/aircraft.h \ + ../Aircraft/../Flight/flight.h ../Aircraft/../Controls/controls.h \ + ../Aircraft/../Controls/../Include/limits.h ../Include/constants.h \ + ../Include/general.h ../Main/views.h ../Main/../Include/types.h \ + ../Main/../Flight/flight.h ../Main/../Math/mat3.h \ + ../Main/../Time/fg_time.h +orbits.o: orbits.c orbits.h ../Time/fg_time.h \ + ../Time/../Include/types.h ../Time/../Flight/flight.h \ + ../Time/../Flight/Slew/slew.h \ + ../Time/../Flight/LaRCsim/ls_interface.h \ + ../Time/../Flight/LaRCsim/../flight.h ../Include/general.h +planets.o: planets.c ../Time/fg_time.h ../Time/../Include/types.h \ + ../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \ + ../Time/../Flight/LaRCsim/ls_interface.h \ + ../Time/../Flight/LaRCsim/../flight.h orbits.h planets.h sun.h +sky.o: sky.c ../XGL/xgl.h sky.h ../Time/event.h ../Time/fg_time.h \ + ../Time/../Include/types.h ../Time/../Flight/flight.h \ + ../Time/../Flight/Slew/slew.h \ + ../Time/../Flight/LaRCsim/ls_interface.h \ + ../Time/../Flight/LaRCsim/../flight.h ../Aircraft/aircraft.h \ + ../Aircraft/../Flight/flight.h ../Aircraft/../Controls/controls.h \ + ../Aircraft/../Controls/../Include/limits.h ../Flight/flight.h \ + ../Include/constants.h ../Main/views.h ../Main/../Include/types.h \ + ../Main/../Flight/flight.h ../Main/../Math/mat3.h \ + ../Main/../Time/fg_time.h ../Math/fg_random.h +stars.o: stars.c ../XGL/xgl.h orbits.h ../Time/fg_time.h \ + ../Time/../Include/types.h ../Time/../Flight/flight.h \ + ../Time/../Flight/Slew/slew.h \ + ../Time/../Flight/LaRCsim/ls_interface.h \ + ../Time/../Flight/LaRCsim/../flight.h planets.h stars.h \ + ../Include/constants.h ../Include/general.h ../Aircraft/aircraft.h \ + ../Aircraft/../Flight/flight.h ../Aircraft/../Controls/controls.h \ + ../Aircraft/../Controls/../Include/limits.h ../Main/views.h \ + ../Main/../Include/types.h ../Main/../Flight/flight.h \ + ../Main/../Math/mat3.h ../Main/../Time/fg_time.h +sun.o: sun.c ../XGL/xgl.h ../Time/fg_time.h ../Time/../Include/types.h \ + ../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \ + ../Time/../Flight/LaRCsim/ls_interface.h \ + ../Time/../Flight/LaRCsim/../flight.h ../Main/views.h \ + ../Main/../Include/types.h ../Main/../Flight/flight.h \ + ../Main/../Math/mat3.h ../Main/../Time/fg_time.h orbits.h sun.h diff --git a/Scenery/moon.c b/Astro/moon.c similarity index 98% rename from Scenery/moon.c rename to Astro/moon.c index dd39f072..aa99c92d 100644 --- a/Scenery/moon.c +++ b/Astro/moon.c @@ -320,9 +320,12 @@ void fgMoonRender() { /* $Log$ -/* Revision 1.16 1998/01/06 01:20:24 curt -/* Tweaks to help building with MSVC++ +/* 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. * diff --git a/Scenery/moon.h b/Astro/moon.h similarity index 89% rename from Scenery/moon.h rename to Astro/moon.h index a8e90386..c4d21ed2 100644 --- a/Scenery/moon.h +++ b/Astro/moon.h @@ -51,10 +51,13 @@ extern struct OrbElements pltOrbElements[9]; /* $Log$ -/* 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.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. * diff --git a/Scenery/orbits.c b/Astro/orbits.c similarity index 96% rename from Scenery/orbits.c rename to Astro/orbits.c index 99ddd635..50a28366 100644 --- a/Scenery/orbits.c +++ b/Astro/orbits.c @@ -173,9 +173,12 @@ void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t) /* $Log$ -/* Revision 1.6 1997/12/30 20:47:52 curt -/* Integrated new event manager with subsystem initializations. +/* 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. diff --git a/Scenery/orbits.h b/Astro/orbits.h similarity index 94% rename from Scenery/orbits.h rename to Astro/orbits.h index c51b305e..9077cd4a 100644 --- a/Scenery/orbits.h +++ b/Astro/orbits.h @@ -81,9 +81,12 @@ void fgSolarSystemUpdate(struct OrbElements *planets, struct fgTIME t); /* $Log$ -/* Revision 1.2 1997/12/30 16:36:52 curt -/* Merged in Durk's changes ... +/* 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/Scenery/planets.c b/Astro/planets.c similarity index 95% rename from Scenery/planets.c rename to Astro/planets.c index cd2171c5..0453cb33 100644 --- a/Scenery/planets.c +++ b/Astro/planets.c @@ -133,9 +133,12 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, /* $Log$ -/* Revision 1.4 1997/12/30 20:47:52 curt -/* Integrated new event manager with subsystem initializations. +/* 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 ... * diff --git a/Scenery/planets.h b/Astro/planets.h similarity index 89% rename from Scenery/planets.h rename to Astro/planets.h index 3d5df465..6cf87489 100644 --- a/Scenery/planets.h +++ b/Astro/planets.h @@ -35,9 +35,12 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet, /* $Log$ -/* Revision 1.3 1997/12/30 16:36:53 curt -/* Merged in Durk's changes ... +/* 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. * diff --git a/Scenery/sky.c b/Astro/sky.c similarity index 98% rename from Scenery/sky.c rename to Astro/sky.c index e34e6c7b..4de37c73 100644 --- a/Scenery/sky.c +++ b/Astro/sky.c @@ -329,9 +329,12 @@ void fgSkyRender() { /* $Log$ -/* Revision 1.11 1997/12/30 22:22:38 curt -/* Further integration of event manager. +/* 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. * diff --git a/Scenery/sky.h b/Astro/sky.h similarity index 88% rename from Scenery/sky.h rename to Astro/sky.h index f5bd771b..7ba4863e 100644 --- a/Scenery/sky.h +++ b/Astro/sky.h @@ -35,9 +35,12 @@ void fgSkyRender(); /* $Log$ -/* Revision 1.2 1997/12/22 23:45:49 curt -/* First stab at sunset/sunrise sky glow effects. +/* 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 new file mode 100644 index 00000000..6d3d4a53 --- /dev/null +++ b/Astro/stars.c @@ -0,0 +1,357 @@ +/************************************************************************** + * 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) + **************************************************************************/ + + +#ifdef WIN32 +# include +#endif + +#include +#include +#include +#include + +#include +#include "../XGL/xgl.h" + +#include "orbits.h" +#include "planets.h" +#include "stars.h" + +#include "../Include/constants.h" +#include "../Include/general.h" +#include "../Aircraft/aircraft.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 */ +void fgStarsInit() { + FILE *fd; + struct fgGENERAL *g; + struct CelestialCoord pltPos; + char path[1024]; + char line[256], name[256]; + char *front, *end; + double right_ascension, declination, magnitude; + double ra_save, decl_save; + double ra_save1, decl_save1; + int count, i, j, max_stars; + + printf("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++ ) { + printf(" Loading %d Stars: %s\n", max_stars, path); + + if ( (fd = fopen(path, "r")) == NULL ) { + printf("Cannot open star file: '%s'\n", path); + return; + } + + 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++; + } /* if valid line */ + + } /* while */ + + fclose(fd); + + /* Add the planets to all four display lists */ + for ( j = 2; j < 9; j++ ) { + pltPos = fgCalculatePlanet(pltOrbElements[j], + pltOrbElements[0], cur_time_params, j); + /* give the planets a temporary color, for testing purposes */ + /* xglColor3f( 1.0, 0.0, 0.0); */ + + /* scale magnitudes to (0.0 - 1.0) */ + magnitude = (0.0 - pltPos.magnitude) / 5.0 + 1.0; + + /* scale magnitudes again so they look ok */ + if ( magnitude > 1.0 ) { magnitude = 1.0; } + if ( magnitude < 0.0 ) { magnitude = 0.0; } + magnitude = + magnitude * 0.7 + (((FG_STAR_LEVELS - 1) - i) * 0.1); + + + xglColor3f(magnitude, magnitude, magnitude); + + xglVertex3f( 50000.0 * cos(pltPos.RightAscension) * + cos(pltPos.Declination), + 50000.0 * sin(pltPos.RightAscension) * + cos(pltPos.Declination), + 50000.0 * sin(pltPos.Declination) ); + } + xglEnd(); + + /* + 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; + } +} + + +/* Draw the Stars */ +void fgStarsRender() { + struct fgFLIGHT *f; + struct fgVIEW *v; + struct fgLIGHT *l; + struct fgTIME *t; + int i; + + f = ¤t_aircraft.flight; + l = &cur_light_params; + t = &cur_time_params; + v = ¤t_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/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 new file mode 100644 index 00000000..19524e12 --- /dev/null +++ b/Astro/stars.h @@ -0,0 +1,69 @@ +/************************************************************************** + * 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 + + +#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 */ +void fgStarsInit(); + +/* Draw the Stars */ +void fgStarsRender(); +extern struct OrbElements pltOrbElements[9]; +extern struct fgTIME cur_time_params; + +#endif /* STARS_H */ + + +/* $Log$ +/* 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/Scenery/sun.c b/Astro/sun.c similarity index 97% rename from Scenery/sun.c rename to Astro/sun.c index d68d179a..43e2c353 100644 --- a/Scenery/sun.c +++ b/Astro/sun.c @@ -190,9 +190,12 @@ void fgSunRender() { /* $Log$ -/* Revision 1.12 1998/01/05 18:44:36 curt -/* Add an option to advance/decrease time from keyboard. +/* 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. diff --git a/Scenery/sun.h b/Astro/sun.h similarity index 87% rename from Scenery/sun.h rename to Astro/sun.h index 9d597d27..260101f7 100644 --- a/Scenery/sun.h +++ b/Astro/sun.h @@ -41,10 +41,13 @@ void fgSunRender(); /* $Log$ -/* 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.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. * diff --git a/Scenery/astro.c b/Scenery/astro.c deleted file mode 100644 index d49af701..00000000 --- a/Scenery/astro.c +++ /dev/null @@ -1,152 +0,0 @@ -/************************************************************************** - * astro.c - * - * Written by Durk Talsma. Started November 1997, for use with 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 -#include -#include -#include - -#include -#include "../XGL/xgl.h" - -#include "astro.h" -#include "moon.h" -#include "orbits.h" -#include "planets.h" -#include "stars.h" -#include "sun.h" - -#include "../Include/constants.h" -#include "../Include/general.h" - -#include "../Main/views.h" -#include "../Aircraft/aircraft.h" -#include "../Time/fg_time.h" - -static double prevUpdate = 0; - - -/* Initialize Astronomical Objects */ -void fgAstroInit() { - struct fgTIME *t; - t = &cur_time_params; - - /* Initialize the orbital elements of sun, moon and mayor planets */ - fgSolarSystemInit(*t); - - /* Initialize the Stars subsystem */ - fgStarsInit(); - - /* Initialize the sun's position */ - fgSunInit(); - - /* Intialize the moon's position */ - fgMoonInit(); -} - - -/* Render Astronomical Objects */ -void fgAstroRender() { - struct fgFLIGHT *f; - struct fgLIGHT *l; - struct fgVIEW *v; - struct fgTIME *t; - double angle; - - f = ¤t_aircraft.flight; - l = &cur_light_params; - t = &cur_time_params; - v = ¤t_view; - - /* a hack: Force sun and moon position to be updated on an hourly basis */ - if (((t->gst - prevUpdate) > 1) || (t->gst < prevUpdate)) { - prevUpdate = t->gst; - fgSunInit(); - fgMoonInit(); - } - - /* set the sun position */ - /* xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv ); */ - - xglPushMatrix(); - - /* Translate to view position */ - xglTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z ); - - /* Rotate based on gst (side real time) */ - angle = t->gst * 15.041085; /* should be 15.041085, Curt thought it was 15*/ -#ifdef DEBUG - printf("Rotating astro objects by %.2f degrees\n",angle); -#endif - xglRotatef( angle, 0.0, 0.0, -1.0 ); - - /* render the moon */ - fgMoonRender(); - - /* render the stars */ - fgStarsRender(); - - /* render the sun */ - fgSunRender(); - - xglPopMatrix(); -} - - -/* $Log$ -/* Revision 1.10 1997/12/19 16:45:01 curt -/* Working on scene rendering order and options. -/* - * Revision 1.9 1997/12/18 23:32:35 curt - * First stab at sky dome actually starting to look reasonable. :-) - * - * Revision 1.8 1997/12/15 23:54:57 curt - * Add xgl wrappers for debugging. - * Generate terrain normals on the fly. - * - * Revision 1.7 1997/12/15 20:59:09 curt - * Misc. tweaks. - * - * Revision 1.6 1997/12/12 21:41:27 curt - * More light/material property tweaking ... still a ways off. - * - * Revision 1.5 1997/12/12 19:52:54 curt - * Working on lightling and material properties. - * - * 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/12/10 22:37:49 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.2 1997/12/09 04:25:33 curt - * Working on adding a global lighting params structure. - * - * Revision 1.1 1997/11/25 23:20:22 curt - * Initial revision. - * - */ diff --git a/Scenery/astro.h b/Scenery/astro.h deleted file mode 100644 index 4fa5150a..00000000 --- a/Scenery/astro.h +++ /dev/null @@ -1,61 +0,0 @@ -/************************************************************************** - * astro.h - * - * Written by Durk Talsma. Started November 1997, for use with 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 _ASTRO_H_ -#define _ASTRO_H_ - -#include -#include "stars.h" - -extern struct CelestialCoord - moonPos; - -extern float xMoon, yMoon, zMoon, xSun, ySun, zSun; -/* extern GLint moon, sun; */ -extern GLint stars[FG_STAR_LEVELS]; - - -/* Initialize Astronomical Objects */ -void fgAstroInit(); - -/* Render Astronomical objects */ -void fgAstroRender(); - - -#endif /* _ASTRO_H_ */ - - -/* $Log$ -/* Revision 1.3 1997/12/17 23:13:46 curt -/* Began working on rendering the sky. -/* - * Revision 1.2 1997/12/11 04:43:56 curt - * Fixed sun vector and lighting problems. I thing the moon is now lit - * correctly. - * - * Revision 1.1 1997/11/25 23:20:23 curt - * Initial revision. - * - */ From 86e571f18bf456318057678feb3bafa1b401fd12 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 7 Jan 1998 03:31:25 +0000 Subject: [PATCH 035/123] Miscellaneous tweaks. --- Astro/depend | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Astro/depend b/Astro/depend index a948633f..223726e3 100644 --- a/Astro/depend +++ b/Astro/depend @@ -1,14 +1,3 @@ -astro.o: astro.c ../XGL/xgl.h astro.h stars.h moon.h orbits.h \ - ../Time/fg_time.h ../Time/../Include/types.h \ - ../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \ - ../Time/../Flight/LaRCsim/ls_interface.h \ - ../Time/../Flight/LaRCsim/../flight.h planets.h sun.h \ - ../Include/constants.h ../Include/general.h ../Main/views.h \ - ../Main/../Include/types.h ../Main/../Flight/flight.h \ - ../Main/../Math/mat3.h ../Main/../Time/fg_time.h \ - ../Aircraft/aircraft.h ../Aircraft/../Flight/flight.h \ - ../Aircraft/../Controls/controls.h \ - ../Aircraft/../Controls/../Include/limits.h moon.o: moon.c ../XGL/xgl.h orbits.h ../Time/fg_time.h \ ../Time/../Include/types.h ../Time/../Flight/flight.h \ ../Time/../Flight/Slew/slew.h \ @@ -19,6 +8,17 @@ moon.o: moon.c ../XGL/xgl.h orbits.h ../Time/fg_time.h \ ../Include/general.h ../Main/views.h ../Main/../Include/types.h \ ../Main/../Flight/flight.h ../Main/../Math/mat3.h \ ../Main/../Time/fg_time.h +old_astro.o: old_astro.c ../XGL/xgl.h old_astro.h stars.h moon.h \ + orbits.h ../Time/fg_time.h ../Time/../Include/types.h \ + ../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \ + ../Time/../Flight/LaRCsim/ls_interface.h \ + ../Time/../Flight/LaRCsim/../flight.h planets.h sun.h \ + ../Include/constants.h ../Include/general.h ../Main/views.h \ + ../Main/../Include/types.h ../Main/../Flight/flight.h \ + ../Main/../Math/mat3.h ../Main/../Time/fg_time.h \ + ../Aircraft/aircraft.h ../Aircraft/../Flight/flight.h \ + ../Aircraft/../Controls/controls.h \ + ../Aircraft/../Controls/../Include/limits.h orbits.o: orbits.c orbits.h ../Time/fg_time.h \ ../Time/../Include/types.h ../Time/../Flight/flight.h \ ../Time/../Flight/Slew/slew.h \ From fdda5da598cb78652051e26246be9748e26299c5 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 8 Jan 1998 02:22:01 +0000 Subject: [PATCH 036/123] Beginning to integrate Tile management subsystem. --- Astro/depend | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Astro/depend b/Astro/depend index 223726e3..f73a2539 100644 --- a/Astro/depend +++ b/Astro/depend @@ -8,17 +8,6 @@ moon.o: moon.c ../XGL/xgl.h orbits.h ../Time/fg_time.h \ ../Include/general.h ../Main/views.h ../Main/../Include/types.h \ ../Main/../Flight/flight.h ../Main/../Math/mat3.h \ ../Main/../Time/fg_time.h -old_astro.o: old_astro.c ../XGL/xgl.h old_astro.h stars.h moon.h \ - orbits.h ../Time/fg_time.h ../Time/../Include/types.h \ - ../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \ - ../Time/../Flight/LaRCsim/ls_interface.h \ - ../Time/../Flight/LaRCsim/../flight.h planets.h sun.h \ - ../Include/constants.h ../Include/general.h ../Main/views.h \ - ../Main/../Include/types.h ../Main/../Flight/flight.h \ - ../Main/../Math/mat3.h ../Main/../Time/fg_time.h \ - ../Aircraft/aircraft.h ../Aircraft/../Flight/flight.h \ - ../Aircraft/../Controls/controls.h \ - ../Aircraft/../Controls/../Include/limits.h orbits.o: orbits.c orbits.h ../Time/fg_time.h \ ../Time/../Include/types.h ../Time/../Flight/flight.h \ ../Time/../Flight/Slew/slew.h \ From b6b503a1907f942a0c12187c5d5329204c125b23 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 19 Jan 1998 18:40:15 +0000 Subject: [PATCH 037/123] Tons of little changes to clean up the code and to remove fatal errors when building with the c++ compiler. --- Astro/depend | 11 +++++++++++ Astro/moon.c | 12 ++++++++---- Astro/moon.h | 12 ++++++++---- Astro/sky.c | 16 ++++++++++------ Astro/sky.h | 14 +++++++++----- Astro/stars.c | 12 ++++++++---- Astro/stars.h | 12 ++++++++---- Astro/sun.c | 12 ++++++++---- Astro/sun.h | 12 ++++++++---- 9 files changed, 78 insertions(+), 35 deletions(-) diff --git a/Astro/depend b/Astro/depend index f73a2539..223726e3 100644 --- a/Astro/depend +++ b/Astro/depend @@ -8,6 +8,17 @@ moon.o: moon.c ../XGL/xgl.h orbits.h ../Time/fg_time.h \ ../Include/general.h ../Main/views.h ../Main/../Include/types.h \ ../Main/../Flight/flight.h ../Main/../Math/mat3.h \ ../Main/../Time/fg_time.h +old_astro.o: old_astro.c ../XGL/xgl.h old_astro.h stars.h moon.h \ + orbits.h ../Time/fg_time.h ../Time/../Include/types.h \ + ../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \ + ../Time/../Flight/LaRCsim/ls_interface.h \ + ../Time/../Flight/LaRCsim/../flight.h planets.h sun.h \ + ../Include/constants.h ../Include/general.h ../Main/views.h \ + ../Main/../Include/types.h ../Main/../Flight/flight.h \ + ../Main/../Math/mat3.h ../Main/../Time/fg_time.h \ + ../Aircraft/aircraft.h ../Aircraft/../Flight/flight.h \ + ../Aircraft/../Controls/controls.h \ + ../Aircraft/../Controls/../Include/limits.h orbits.o: orbits.c orbits.h ../Time/fg_time.h \ ../Time/../Include/types.h ../Time/../Flight/flight.h \ ../Time/../Flight/Slew/slew.h \ diff --git a/Astro/moon.c b/Astro/moon.c index aa99c92d..227743e9 100644 --- a/Astro/moon.c +++ b/Astro/moon.c @@ -257,7 +257,7 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params, } -void fgMoonInit() { +void fgMoonInit( void ) { struct fgLIGHT *l; static int dl_exists = 0; @@ -298,7 +298,7 @@ void fgMoonInit() { /* Draw the moon */ -void fgMoonRender() { +void fgMoonRender( void ) { struct fgLIGHT *l; GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; @@ -320,9 +320,13 @@ void fgMoonRender() { /* $Log$ -/* Revision 1.1 1998/01/07 03:16:16 curt -/* Moved from .../Src/Scenery/ to .../Src/Astro/ +/* 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++ * diff --git a/Astro/moon.h b/Astro/moon.h index c4d21ed2..90a94f98 100644 --- a/Astro/moon.h +++ b/Astro/moon.h @@ -36,10 +36,10 @@ /* Initialize the Moon Display management Subsystem */ -void fgMoonInit(); +void fgMoonInit( void ); /* Draw the Stars */ -void fgMoonRender(); +void fgMoonRender( void ); struct CelestialCoord fgCalculateMoon(struct OrbElements Params, struct OrbElements sunParams, @@ -51,9 +51,13 @@ extern struct OrbElements pltOrbElements[9]; /* $Log$ -/* Revision 1.1 1998/01/07 03:16:16 curt -/* Moved from .../Src/Scenery/ to .../Src/Astro/ +/* 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. diff --git a/Astro/sky.c b/Astro/sky.c index 4de37c73..a7a7b098 100644 --- a/Astro/sky.c +++ b/Astro/sky.c @@ -72,7 +72,7 @@ static float outer_color[12][4]; /* Calculate the sky structure vertices */ -void fgSkyVerticesInit() { +void fgSkyVerticesInit( void ) { float theta; int i; @@ -101,7 +101,7 @@ void fgSkyVerticesInit() { /* (Re)calculate the sky colors at each vertex */ -void fgSkyColorsInit() { +void fgSkyColorsInit( void ) { struct fgLIGHT *l; float sun_angle, diff; float outer_param[3], outer_amt[3], outer_diff[3]; @@ -224,7 +224,7 @@ void fgSkyColorsInit() { /* Initialize the sky structure and colors */ -void fgSkyInit() { +void fgSkyInit( void ) { printf("Initializing the sky\n"); fgSkyVerticesInit(); @@ -236,7 +236,7 @@ void fgSkyInit() { /* Draw the Sky */ -void fgSkyRender() { +void fgSkyRender( void ) { struct fgFLIGHT *f; struct fgLIGHT *l; struct fgVIEW *v; @@ -329,9 +329,13 @@ void fgSkyRender() { /* $Log$ -/* Revision 1.1 1998/01/07 03:16:19 curt -/* Moved from .../Src/Scenery/ to .../Src/Astro/ +/* 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. * diff --git a/Astro/sky.h b/Astro/sky.h index 7ba4863e..0479a4b9 100644 --- a/Astro/sky.h +++ b/Astro/sky.h @@ -25,19 +25,23 @@ /* (Re)generate the display list */ -void fgSkyInit(); +void fgSkyInit( void ); /* (Re)calculate the sky colors at each vertex */ -void fgSkyColorsInit(); +void fgSkyColorsInit( void ); /* Draw the Sky */ -void fgSkyRender(); +void fgSkyRender( void ); /* $Log$ -/* Revision 1.1 1998/01/07 03:16:19 curt -/* Moved from .../Src/Scenery/ to .../Src/Astro/ +/* 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. * diff --git a/Astro/stars.c b/Astro/stars.c index 6d3d4a53..711a9a06 100644 --- a/Astro/stars.c +++ b/Astro/stars.c @@ -56,7 +56,7 @@ /* Initialize the Star Management Subsystem */ -void fgStarsInit() { +void fgStarsInit( void ) { FILE *fd; struct fgGENERAL *g; struct CelestialCoord pltPos; @@ -237,7 +237,7 @@ void fgStarsInit() { /* Draw the Stars */ -void fgStarsRender() { +void fgStarsRender( void ) { struct fgFLIGHT *f; struct fgVIEW *v; struct fgLIGHT *l; @@ -276,9 +276,13 @@ void fgStarsRender() { /* $Log$ -/* Revision 1.1 1998/01/07 03:16:20 curt -/* Moved from .../Src/Scenery/ to .../Src/Astro/ +/* 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. * diff --git a/Astro/stars.h b/Astro/stars.h index 19524e12..b08ffda9 100644 --- a/Astro/stars.h +++ b/Astro/stars.h @@ -33,10 +33,10 @@ #define FG_MIN_STAR_MAG 0.738750 /* magnitude of weakest star we'll display */ /* Initialize the Star Management Subsystem */ -void fgStarsInit(); +void fgStarsInit( void ); /* Draw the Stars */ -void fgStarsRender(); +void fgStarsRender( void ); extern struct OrbElements pltOrbElements[9]; extern struct fgTIME cur_time_params; @@ -44,9 +44,13 @@ extern struct fgTIME cur_time_params; /* $Log$ -/* Revision 1.1 1998/01/07 03:16:20 curt -/* Moved from .../Src/Scenery/ to .../Src/Astro/ +/* 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. diff --git a/Astro/sun.c b/Astro/sun.c index 43e2c353..2c89ae3c 100644 --- a/Astro/sun.c +++ b/Astro/sun.c @@ -94,7 +94,7 @@ struct CelestialCoord fgCalculateSun(struct OrbElements params, struct fgTIME t) /* Initialize the Sun */ -void fgSunInit() { +void fgSunInit( void ) { static int dl_exists = 0; printf(" Initializing the Sun\n"); @@ -126,7 +126,7 @@ void fgSunInit() { /* Draw the Sun */ -void fgSunRender() { +void fgSunRender( void ) { struct fgVIEW *v; struct fgTIME *t; struct fgLIGHT *l; @@ -190,9 +190,13 @@ void fgSunRender() { /* $Log$ -/* Revision 1.1 1998/01/07 03:16:20 curt -/* Moved from .../Src/Scenery/ to .../Src/Astro/ +/* 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. * diff --git a/Astro/sun.h b/Astro/sun.h index 260101f7..9683462c 100644 --- a/Astro/sun.h +++ b/Astro/sun.h @@ -31,19 +31,23 @@ struct SunPos fgCalcSunPos(struct OrbElements sunParams); extern struct OrbElements pltOrbElements[9]; /* Initialize the Sun */ -void fgSunInit(); +void fgSunInit( void ); /* Draw the Sun */ -void fgSunRender(); +void fgSunRender( void ); #endif /* SUN_H */ /* $Log$ -/* Revision 1.1 1998/01/07 03:16:21 curt -/* Moved from .../Src/Scenery/ to .../Src/Astro/ +/* 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. From ccc3af8937ba7e16aa5b8723e8173c3cb541b3a4 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 19 Jan 1998 19:26:51 +0000 Subject: [PATCH 038/123] Merged in make system changes from Bob Kuehne This should simplify things tremendously. --- Astro/Makefile | 141 +++--------------------------------------------- Astro/moon.c | 26 +++++---- Astro/moon.h | 14 +++-- Astro/orbits.c | 14 +++-- Astro/orbits.h | 10 ++-- Astro/planets.c | 16 +++--- Astro/sky.c | 31 ++++++----- Astro/stars.c | 28 +++++----- Astro/sun.c | 20 ++++--- 9 files changed, 102 insertions(+), 198 deletions(-) diff --git a/Astro/Makefile b/Astro/Makefile index 24e85c65..9e9a7a0c 100644 --- a/Astro/Makefile +++ b/Astro/Makefile @@ -23,143 +23,14 @@ # (Log is kept at end of this file) #--------------------------------------------------------------------------- - -TARGET = libAstro.a +ARLIBRARY = libAstro.a +TARGETS = $(ARLIBRARY) CFILES = moon.c orbits.c planets.c sky.c stars.c sun.c +CXXFILES = -OFILES = $(CFILES:.c=.o) +LDIRT = $(FG_ROOT_LIB)/$(ARLIBRARY) +include $(FG_ROOT_SRC)/commondefs -include ../make.inc - - -CFLAGS = $(FG_CFLAGS) - - -#--------------------------------------------------------------------------- -# Primary Targets -#--------------------------------------------------------------------------- - -$(TARGET): $(OFILES) $(HFILES) - $(AR) rv $(TARGET) $(OFILES) - $(RANLIB) $(TARGET) - -all: $(TARGET) - -clean: - rm -f *.o $(TARGET) lib*.a *.os2 *~ core - -realclean: clean - - -#--------------------------------------------------------------------------- -# Secondary Targets -#--------------------------------------------------------------------------- - -include depend - -moon.o: - $(CC) $(CFLAGS) -c moon.c -o $@ - -orbits.o: - $(CC) $(CFLAGS) -c orbits.c -o $@ - -planets.o: - $(CC) $(CFLAGS) -c planets.c -o $@ - -sky.c: - $(CC) $(CFLAGS) -c sky.c -o $@ - -stars.c: - $(CC) $(CFLAGS) -c stars.c -o $@ - -sun.o: - $(CC) $(CFLAGS) -c sun.c -o $@ - - - -#--------------------------------------------------------------------------- -# $Log$ -# Revision 1.1 1998/01/07 03:16:15 curt -# Moved from .../Src/Scenery/ to .../Src/Astro/ -# -# Revision 1.26 1997/12/19 16:45:01 curt -# Working on scene rendering order and options. -# -# Revision 1.25 1997/12/17 23:13:45 curt -# Began working on rendering the sky. -# -# Revision 1.24 1997/11/25 19:25:33 curt -# Changes to integrate Durk's moon/sun code updates + clean up. -# -# Revision 1.23 1997/10/28 21:00:20 curt -# Changing to new terrain format. -# -# Revision 1.22 1997/10/25 03:30:07 curt -# Misc. tweaks. -# -# Revision 1.21 1997/10/25 03:18:26 curt -# Incorporated sun, moon, and planet position and rendering code contributed -# by Durk Talsma. -# -# Revision 1.20 1997/09/22 14:44:21 curt -# Continuing to try to align stars correctly. -# -# Revision 1.19 1997/08/27 03:30:23 curt -# Changed naming scheme of basic shared structures. -# -# Revision 1.18 1997/08/02 19:10:12 curt -# Incorporated mesh2GL.c into mesh.c -# -# Revision 1.17 1997/07/23 21:52:23 curt -# Put comments around the text after an #endif for increased portability. -# -# Revision 1.16 1997/07/20 02:19:11 curt -# First stab at a system to generate os2 makefiles automatically. -# -# Revision 1.15 1997/07/12 02:24:47 curt -# Added ranlib. -# -# Revision 1.14 1997/06/29 21:16:47 curt -# More twiddling with the Scenery Management system. -# -# Revision 1.13 1997/06/27 21:38:10 curt -# Working on Makefile structure. -# -# Revision 1.12 1997/06/27 20:03:37 curt -# Working on Makefile structure. -# -# Revision 1.11 1997/06/26 22:14:57 curt -# Beginning work on a scenery management system. -# -# Revision 1.10 1997/06/26 19:08:34 curt -# Restructuring make, adding automatic "make dep" support. -# -# Revision 1.9 1997/06/25 15:39:48 curt -# Minor changes to compile with rsxnt/win32. -# -# Revision 1.8 1997/06/21 17:58:07 curt -# directory shuffling ... -# -# Revision 1.1 1997/06/21 17:39:28 curt -# Moved to the ParseScn subdirectory. -# -# Revision 1.6 1997/06/21 17:12:55 curt -# Capitalized subdirectory names. -# -# Revision 1.5 1997/05/31 19:16:29 curt -# Elevator trim added. -# -# Revision 1.4 1997/05/27 17:48:50 curt -# Added -f flag to flex to generate a "fast" scanner. -# -# Revision 1.3 1997/05/23 15:40:40 curt -# Added GNU copyright headers. -# -# Revision 1.2 1997/05/17 00:17:01 curt -# Cosmetic changes. -# -# Revision 1.1 1997/05/16 16:07:02 curt -# Initial revision. -# +include $(COMMONRULES) diff --git a/Astro/moon.c b/Astro/moon.c index 227743e9..4160b8d4 100644 --- a/Astro/moon.c +++ b/Astro/moon.c @@ -23,16 +23,16 @@ #include #include -#include "../XGL/xgl.h" +#include -#include "orbits.h" -#include "moon.h" +#include +#include -#include "../Aircraft/aircraft.h" -#include "../Include/constants.h" -#include "../Include/general.h" -#include "../Main/views.h" -#include "../Time/fg_time.h" +#include +#include +#include +#include
+#include