Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
calculation code between sun display, and other FG sections that use this for things like lighting.
This commit is contained in:
86
Astro/moon.c
86
Astro/moon.c
@@ -38,7 +38,7 @@
|
||||
struct CelestialCoord moonPos;
|
||||
|
||||
static float xMoon, yMoon, zMoon;
|
||||
static GLint moon;
|
||||
static GLint moon = 0;
|
||||
|
||||
|
||||
|
||||
@@ -67,8 +67,8 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params,
|
||||
/* calculate the angle between ecliptic and equatorial coordinate
|
||||
* system, in Radians */
|
||||
actTime = fgCalcActTime(t);
|
||||
/* ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime);*/
|
||||
ecl = 0.409093 - 6.2186E-9 * actTime;
|
||||
ecl = ((DEG_TO_RAD * 23.4393) - (DEG_TO_RAD * 3.563E-7) * actTime);
|
||||
/*ecl = 0.409093 - 6.2186E-9 * actTime; */
|
||||
|
||||
/* calculate the eccentric anomaly */
|
||||
eccAnom = fgCalcEccAnom(params.M, params.e);
|
||||
@@ -80,8 +80,10 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params,
|
||||
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));
|
||||
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 */
|
||||
@@ -90,7 +92,7 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params,
|
||||
|
||||
/* calculate a number of perturbations, i.e. disturbances caused by
|
||||
* the gravitational influence of the sun and the other mayor
|
||||
* planets, the largest even have their own names */
|
||||
* planets. The largest of these even have their own names */
|
||||
Ls = sunParams.M + sunParams.w;
|
||||
Lm = params.M + params.w + params.N;
|
||||
D = Lm - Ls;
|
||||
@@ -155,24 +157,19 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params,
|
||||
|
||||
|
||||
|
||||
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);
|
||||
topocCoord.RightAscension = geocCoord.RightAscension -
|
||||
mpar * rho * cos (gclat) * sin (HA) / cos (geocCoord.Declination);
|
||||
topocCoord.Declination = geocCoord.Declination -
|
||||
mpar * rho * sin (gclat) * sin (g - geocCoord.Declination) / sin (g);
|
||||
return topocCoord;
|
||||
}
|
||||
|
||||
|
||||
void fgMoonInit( void ) {
|
||||
/* struct fgLIGHT *l; */
|
||||
static int dl_exists = 0;
|
||||
/* GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; */
|
||||
GLfloat moonColor[4] = {0.85, 0.65, 0.05, 1.0};
|
||||
GLfloat moonColor[4] = {0.85, 0.75, 0.35, 1.0};
|
||||
GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
|
||||
|
||||
fgPrintf( FG_ASTRO, FG_INFO, "Initializing the Moon\n");
|
||||
|
||||
/* l = &cur_light_params; */
|
||||
|
||||
/* position the moon */
|
||||
fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params);
|
||||
moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0],
|
||||
cur_time_params);
|
||||
@@ -184,52 +181,41 @@ void fgMoonInit( void ) {
|
||||
yMoon = 60000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination);
|
||||
zMoon = 60000.0 * sin(moonPos.Declination);
|
||||
|
||||
if ( !dl_exists ) {
|
||||
dl_exists = 1;
|
||||
|
||||
/* printf("First time through, creating moon display list\n"); */
|
||||
|
||||
moon = xglGenLists(1);
|
||||
xglNewList(moon, GL_COMPILE );
|
||||
|
||||
/* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear);
|
||||
xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */
|
||||
xglMaterialfv(GL_FRONT, GL_AMBIENT, black);
|
||||
xglMaterialfv(GL_FRONT, GL_DIFFUSE, moonColor);
|
||||
|
||||
glutSolidSphere(1.0, 10, 10);
|
||||
|
||||
xglEndList();
|
||||
if (moon) {
|
||||
xglDeleteLists (moon, 1);
|
||||
}
|
||||
|
||||
moon = xglGenLists (1);
|
||||
xglNewList (moon, GL_COMPILE);
|
||||
|
||||
xglMaterialfv (GL_FRONT, GL_AMBIENT, black);
|
||||
xglMaterialfv (GL_FRONT, GL_DIFFUSE, moonColor);
|
||||
xglPushMatrix ();
|
||||
xglTranslatef (xMoon, yMoon, zMoon);
|
||||
xglScalef (1400, 1400, 1400);
|
||||
|
||||
glutSolidSphere (1.0, 10, 10);
|
||||
xglPopMatrix ();
|
||||
xglEndList ();
|
||||
}
|
||||
|
||||
|
||||
/* Draw the moon */
|
||||
void fgMoonRender( void ) {
|
||||
/* struct fgLIGHT *l; */
|
||||
|
||||
/* printf("Rendering moon\n"); */
|
||||
|
||||
/* l = &cur_light_params; */
|
||||
|
||||
/* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->sky_color ); */
|
||||
/* xglMaterialfv(GL_FRONT, GL_DIFFUSE, white); */
|
||||
|
||||
xglPushMatrix();
|
||||
xglTranslatef(xMoon, yMoon, zMoon);
|
||||
xglScalef(1400, 1400, 1400);
|
||||
|
||||
xglCallList(moon);
|
||||
|
||||
xglPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.6 1998/02/07 15:29:32 curt
|
||||
/* Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
/* <chotchkiss@namg.us.anritsu.com>
|
||||
/* Revision 1.7 1998/02/23 19:07:54 curt
|
||||
/* Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
|
||||
/* calculation code between sun display, and other FG sections that use this
|
||||
/* for things like lighting.
|
||||
/*
|
||||
* Revision 1.6 1998/02/07 15:29:32 curt
|
||||
* Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
* <chotchkiss@namg.us.anritsu.com>
|
||||
*
|
||||
* Revision 1.5 1998/02/02 20:53:21 curt
|
||||
* To version 0.29
|
||||
*
|
||||
|
||||
14
Astro/moon.h
14
Astro/moon.h
@@ -31,11 +31,8 @@
|
||||
#include <Time/fg_time.h>
|
||||
#include <math.h>
|
||||
|
||||
/* #define X .525731112119133606 */
|
||||
/* #define Z .850650808352039932 */
|
||||
|
||||
|
||||
/* Initialize the Moon Display management Subsystem */
|
||||
/* Initialize the Moon Display management Subsystem */
|
||||
void fgMoonInit( void );
|
||||
|
||||
/* Draw the Moon */
|
||||
@@ -51,9 +48,14 @@ extern struct OrbElements pltOrbElements[9];
|
||||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.5 1998/02/02 20:53:21 curt
|
||||
/* To version 0.29
|
||||
/* Revision 1.6 1998/02/23 19:07:54 curt
|
||||
/* Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
|
||||
/* calculation code between sun display, and other FG sections that use this
|
||||
/* for things like lighting.
|
||||
/*
|
||||
* Revision 1.5 1998/02/02 20:53:21 curt
|
||||
* To version 0.29
|
||||
*
|
||||
* Revision 1.4 1998/01/22 02:59:27 curt
|
||||
* Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
*
|
||||
|
||||
@@ -36,48 +36,12 @@
|
||||
struct OrbElements pltOrbElements[9];
|
||||
|
||||
|
||||
//double fgCalcActTime(struct fgTIME t)
|
||||
//{
|
||||
// double
|
||||
// actTime, UT;
|
||||
// int year;
|
||||
//
|
||||
// /* a hack. This one introduces the 2000 problem into the program */
|
||||
// year = t.gmt->tm_year + 1900;
|
||||
//
|
||||
// /* calculate the actual time, remember to add 1 to tm_mon! */
|
||||
// actTime = 367 * year - 7 *
|
||||
// (year + ((t.gmt->tm_mon+1) + 9) / 12) / 4 + 275 *
|
||||
// (t.gmt->tm_mon+1) / 9 + t.gmt->tm_mday - 730530;
|
||||
//
|
||||
// UT = t.gmt->tm_hour + ((double) t.gmt->tm_min / 60);
|
||||
// /*printf("UT = %f\n", UT); */
|
||||
// actTime += (UT / 24.0);
|
||||
// #define DEBUG 1
|
||||
// #ifdef DEBUG
|
||||
// /* printf(" Actual Time:\n"); */
|
||||
// /* printf(" current day = %f\t", actTime); */
|
||||
// /* printf(" GMT = %d, %d, %d, %d, %d, %d\n",
|
||||
// year, t.gmt->tm_mon, t.gmt->tm_mday,
|
||||
// t.gmt->tm_hour, t.gmt->tm_min, t.gmt->tm_sec); */
|
||||
// #endif
|
||||
// return actTime;
|
||||
//}
|
||||
|
||||
|
||||
double fgCalcActTime(struct fgTIME t)
|
||||
{
|
||||
return (t.mjd - 36523.5);
|
||||
}
|
||||
|
||||
|
||||
/* convert degrees to radians */
|
||||
/*
|
||||
double fgDegToRad(double angle)
|
||||
{
|
||||
return (angle * PIOVER180);
|
||||
}
|
||||
*/
|
||||
double fgCalcEccAnom(double M, double e)
|
||||
{
|
||||
double
|
||||
@@ -101,16 +65,26 @@ double fgCalcEccAnom(double M, double e)
|
||||
}
|
||||
|
||||
|
||||
// This function assumes that if the FILE ptr is valid that the contents
|
||||
// will be valid. Should we check the file for validity?
|
||||
/* This function assumes that if the FILE ptr is valid that the
|
||||
contents will be valid. Should we check the file for validity? */
|
||||
|
||||
/* Sounds like a good idea to me. What type of checks are you thinking
|
||||
of, other than feof(FILE*)? That's currently the only check I can
|
||||
think of (Durk) */
|
||||
|
||||
void fgReadOrbElements(struct OrbElements *dest, FILE *src)
|
||||
int fgReadOrbElements(struct OrbElements *dest, FILE *src)
|
||||
{
|
||||
char line[256];
|
||||
int i,j;
|
||||
j = 0;
|
||||
do
|
||||
{
|
||||
if (feof (src)) {
|
||||
fgPrintf (FG_ASTRO, FG_ALERT,
|
||||
"End of file found while reading planetary positions:\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fgets(line, 256,src);
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
@@ -127,6 +101,8 @@ void fgReadOrbElements(struct OrbElements *dest, FILE *src)
|
||||
&dest->aFirst, &dest->aSec,
|
||||
&dest->eFirst, &dest->eSec,
|
||||
&dest->MFirst, &dest->MSec);
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +135,9 @@ int fgSolarSystemInit(struct fgTIME t)
|
||||
for (i = 0; i < 9; i ++)
|
||||
{
|
||||
/* ...read from the data file ... */
|
||||
fgReadOrbElements(&pltOrbElements[i], data);
|
||||
if (!(fgReadOrbElements (&pltOrbElements[i], data))) {
|
||||
ret_val = 0;
|
||||
}
|
||||
/* ...and calculate the actual values */
|
||||
fgSolarSystemUpdate(&pltOrbElements[i], t);
|
||||
}
|
||||
@@ -177,20 +155,25 @@ void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t)
|
||||
actTime = fgCalcActTime(t);
|
||||
|
||||
/* calculate the actual orbital elements */
|
||||
planet->M = DEG_TO_RAD * (planet->MFirst + (planet->MSec * actTime)); // angle in radians
|
||||
planet->w = DEG_TO_RAD * (planet->wFirst + (planet->wSec * actTime)); // angle in radians
|
||||
planet->N = DEG_TO_RAD * (planet->NFirst + (planet->NSec * actTime)); // angle in radians
|
||||
planet->i = DEG_TO_RAD * (planet->iFirst + (planet->iSec * actTime)); // angle in radians
|
||||
planet->e = planet->eFirst + (planet->eSec * actTime);
|
||||
planet->a = planet->aFirst + (planet->aSec * actTime);
|
||||
planet->M = DEG_TO_RAD * (planet->MFirst + (planet->MSec * actTime));
|
||||
planet->w = DEG_TO_RAD * (planet->wFirst + (planet->wSec * actTime));
|
||||
planet->N = DEG_TO_RAD * (planet->NFirst + (planet->NSec * actTime));
|
||||
planet->i = DEG_TO_RAD * (planet->iFirst + (planet->iSec * actTime));
|
||||
planet->e = planet->eFirst + (planet->eSec * actTime);
|
||||
planet->a = planet->aFirst + (planet->aSec * actTime);
|
||||
}
|
||||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.7 1998/02/12 21:59:33 curt
|
||||
/* Incorporated code changes contributed by Charlie Hotchkiss
|
||||
/* <chotchkiss@namg.us.anritsu.com>
|
||||
/* Revision 1.8 1998/02/23 19:07:55 curt
|
||||
/* Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
|
||||
/* calculation code between sun display, and other FG sections that use this
|
||||
/* for things like lighting.
|
||||
/*
|
||||
* Revision 1.7 1998/02/12 21:59:33 curt
|
||||
* Incorporated code changes contributed by Charlie Hotchkiss
|
||||
* <chotchkiss@namg.us.anritsu.com>
|
||||
*
|
||||
* Revision 1.6 1998/02/03 23:20:11 curt
|
||||
* Lots of little tweaks to fix various consistency problems discovered by
|
||||
* Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
|
||||
|
||||
@@ -34,14 +34,17 @@
|
||||
|
||||
|
||||
|
||||
#define STANDARDEPOCH 2000
|
||||
#define PIOVER180 1.74532925199433E-002
|
||||
//#define STANDARDEPOCH 2000
|
||||
|
||||
struct SunPos {
|
||||
typedef struct {
|
||||
double xs;
|
||||
double ys;
|
||||
double dist;
|
||||
};
|
||||
double lonSun;
|
||||
} fgSUNPOS;
|
||||
|
||||
extern fgSUNPOS solarPosition;
|
||||
|
||||
|
||||
struct OrbElements {
|
||||
double NFirst; /* longitude of the ascending node first part */
|
||||
@@ -68,11 +71,10 @@ struct CelestialCoord {
|
||||
};
|
||||
|
||||
|
||||
/* double fgDegToRad(double angle); */
|
||||
double fgCalcEccAnom(double M, double e);
|
||||
double fgCalcActTime(struct fgTIME t);
|
||||
|
||||
void fgReadOrbElements(struct OrbElements *dest, FILE *src);
|
||||
int fgReadOrbElements (struct OrbElements *dest, FILE * src);
|
||||
int fgSolarSystemInit(struct fgTIME t);
|
||||
void fgSolarSystemUpdate(struct OrbElements *planets, struct fgTIME t);
|
||||
|
||||
@@ -81,10 +83,15 @@ void fgSolarSystemUpdate(struct OrbElements *planets, struct fgTIME t);
|
||||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.5 1998/02/12 21:59:35 curt
|
||||
/* Incorporated code changes contributed by Charlie Hotchkiss
|
||||
/* <chotchkiss@namg.us.anritsu.com>
|
||||
/* Revision 1.6 1998/02/23 19:07:55 curt
|
||||
/* Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
|
||||
/* calculation code between sun display, and other FG sections that use this
|
||||
/* for things like lighting.
|
||||
/*
|
||||
* Revision 1.5 1998/02/12 21:59:35 curt
|
||||
* Incorporated code changes contributed by Charlie Hotchkiss
|
||||
* <chotchkiss@namg.us.anritsu.com>
|
||||
*
|
||||
* Revision 1.4 1998/02/02 20:53:22 curt
|
||||
* To version 0.29
|
||||
*
|
||||
|
||||
@@ -43,46 +43,37 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
|
||||
struct OrbElements theSun,
|
||||
struct fgTIME t, int idx)
|
||||
{
|
||||
struct CelestialCoord
|
||||
result;
|
||||
struct CelestialCoord result;
|
||||
|
||||
struct SunPos
|
||||
SolarPosition;
|
||||
fgSUNPOS SolarPosition;
|
||||
|
||||
double
|
||||
eccAnom, r, v, ecl, actTime, R, s, ir, Nr, B, FV, ring_magn,
|
||||
double eccAnom, r, v, ecl, actTime, R, s, ir, Nr, B, FV, ring_magn,
|
||||
xv, yv, xh, yh, zh, xg, yg, zg, xe, ye, ze;
|
||||
|
||||
actTime = fgCalcActTime(t);
|
||||
/* calculate the angle between ecliptic and equatorial coordinate system */
|
||||
/* ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime); */
|
||||
ecl = 0.409093 - 6.2186E-9 * actTime;
|
||||
actTime = fgCalcActTime(t);
|
||||
/*calculate the angle between ecliptic and equatorial coordinate system */
|
||||
ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime);
|
||||
|
||||
/* calculate the eccentric anomaly */
|
||||
eccAnom = fgCalcEccAnom(planet.M, planet.e);
|
||||
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));
|
||||
xh = r * (cos (planet.N) * cos (v + planet.w) -
|
||||
sin (planet.N) * sin (v + planet.w) * cos (planet.i));
|
||||
yh = r * (sin (planet.N) * cos (v + planet.w) +
|
||||
cos (planet.N) * sin (v + planet.w) * cos (planet.i));
|
||||
zh = r * ( sin(v+planet.w) * sin(planet.i));
|
||||
|
||||
/* calculate the ecliptic longitude and latitude */
|
||||
|
||||
/*
|
||||
lonecl = atan2(yh, xh);
|
||||
latecl = atan2(zh, sqrt ( xh*xh + yh*yh));
|
||||
*/
|
||||
/* calculate the solar position */
|
||||
|
||||
SolarPosition = fgCalcSunPos(theSun);
|
||||
xg = xh + SolarPosition.xs;
|
||||
yg = yh + SolarPosition.ys;
|
||||
xg = xh + solarPosition.xs;
|
||||
yg = yh + solarPosition.ys;
|
||||
zg = zh;
|
||||
|
||||
xe = xg;
|
||||
@@ -91,7 +82,6 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
|
||||
|
||||
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);
|
||||
@@ -117,7 +107,9 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
|
||||
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));
|
||||
B = asin (sin (result.Declination) * cos (ir) -
|
||||
cos (result.Declination) * sin (ir) *
|
||||
sin (result.RightAscension - Nr));
|
||||
ring_magn = -2.6 * sin (fabs(B)) + 1.2 * pow(sin(B),2);
|
||||
result.magnitude = -9.0 + 5*log10( r*R ) + 0.044 * FV + ring_magn;
|
||||
break;
|
||||
@@ -145,15 +137,18 @@ struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
|
||||
|
||||
void fgPlanetsInit( void )
|
||||
{
|
||||
struct fgLIGHT *l;
|
||||
int i;
|
||||
struct CelestialCoord pltPos;
|
||||
double magnitude;
|
||||
|
||||
l = &cur_light_params;
|
||||
/* if the display list was already built during a previous init,
|
||||
recycle it */
|
||||
then recycle it */
|
||||
|
||||
if (planets)
|
||||
if (planets) {
|
||||
xglDeleteLists(planets, 1);
|
||||
}
|
||||
|
||||
planets = xglGenLists(1);
|
||||
xglNewList( planets, GL_COMPILE );
|
||||
@@ -166,10 +161,6 @@ void fgPlanetsInit( void )
|
||||
pltPos = fgCalculatePlanet(pltOrbElements[i],
|
||||
pltOrbElements[0], cur_time_params, i);
|
||||
|
||||
/* give the planets a temporary color, for testing purposes */
|
||||
/* xglColor3f( 1.0, 0.0, 0.0); */
|
||||
/* scale magnitudes to (0.0 - 1.0) */
|
||||
|
||||
magnitude = (0.0 - pltPos.magnitude) / 5.0 + 1.0;
|
||||
|
||||
/* scale magnitudes again so they look ok */
|
||||
@@ -182,15 +173,24 @@ void fgPlanetsInit( void )
|
||||
if ( magnitude > 1.0 ) { magnitude = 1.0; }
|
||||
if ( magnitude < 0.0 ) { magnitude = 0.0; }
|
||||
|
||||
|
||||
xglColor3f(magnitude, magnitude, magnitude);
|
||||
/* xglColor3f(1.0, 1.0,1.0); */
|
||||
|
||||
xglVertex3f( 50000.0 * cos(pltPos.RightAscension) *
|
||||
cos(pltPos.Declination),
|
||||
50000.0 * sin(pltPos.RightAscension) *
|
||||
cos(pltPos.Declination),
|
||||
50000.0 * sin(pltPos.Declination) );
|
||||
/* Add planets to the display list, based on sun_angle and current
|
||||
magnitude It's pretty experimental... */
|
||||
|
||||
if ((double) (l->sun_angle - FG_PI_2) >
|
||||
((magnitude - 1.0) * -20 * DEG_TO_RAD))
|
||||
{
|
||||
xglColor3f (magnitude, magnitude, magnitude);
|
||||
printf ("Sun Angle to Horizon (in Rads) = %f\n",
|
||||
(double) (l->sun_angle - FG_PI_2));
|
||||
printf ("Transformed Magnitude is :%f %f\n",
|
||||
magnitude, (magnitude - 1.0) * -20 * DEG_TO_RAD);
|
||||
|
||||
xglVertex3f (50000.0 * cos (pltPos.RightAscension) *
|
||||
cos (pltPos.Declination),
|
||||
50000.0 * sin (pltPos.RightAscension) *
|
||||
cos (pltPos.Declination),
|
||||
50000.0 * sin (pltPos.Declination));
|
||||
}
|
||||
}
|
||||
xglEnd();
|
||||
xglEndList();
|
||||
@@ -204,10 +204,15 @@ void fgPlanetsRender( void ) {
|
||||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.6 1998/02/12 21:59:36 curt
|
||||
/* Incorporated code changes contributed by Charlie Hotchkiss
|
||||
/* <chotchkiss@namg.us.anritsu.com>
|
||||
/* Revision 1.7 1998/02/23 19:07:55 curt
|
||||
/* Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
|
||||
/* calculation code between sun display, and other FG sections that use this
|
||||
/* for things like lighting.
|
||||
/*
|
||||
* Revision 1.6 1998/02/12 21:59:36 curt
|
||||
* Incorporated code changes contributed by Charlie Hotchkiss
|
||||
* <chotchkiss@namg.us.anritsu.com>
|
||||
*
|
||||
* Revision 1.5 1998/02/03 23:20:12 curt
|
||||
* Lots of little tweaks to fix various consistency problems discovered by
|
||||
* Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
|
||||
|
||||
85
Astro/sun.c
85
Astro/sun.c
@@ -25,26 +25,23 @@
|
||||
#include <GL/glut.h>
|
||||
#include <XGL/xgl.h>
|
||||
|
||||
#include <Time/fg_time.h>
|
||||
#include <Main/views.h>
|
||||
#include <Astro/orbits.h>
|
||||
#include <Astro/sun.h>
|
||||
#include <Main/fg_debug.h>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Main/fg_debug.h>
|
||||
#include <Main/views.h>
|
||||
#include <Time/fg_time.h>
|
||||
#include <Time/sunpos.h>
|
||||
|
||||
GLint sun_obj = 0;
|
||||
|
||||
static struct CelestialCoord sunPos;
|
||||
|
||||
float xSun, ySun, zSun;
|
||||
fgSUNPOS solarPosition;
|
||||
|
||||
struct SunPos fgCalcSunPos(struct OrbElements params)
|
||||
void fgCalcSunPos(struct OrbElements params)
|
||||
{
|
||||
double
|
||||
EccAnom, lonSun,
|
||||
xv, yv, v, r;
|
||||
struct SunPos
|
||||
solarPosition;
|
||||
double EccAnom, xv, yv, v, r;
|
||||
|
||||
/* calculate the eccentric anomaly */
|
||||
EccAnom = fgCalcEccAnom(params.M, params.e);
|
||||
@@ -56,37 +53,31 @@ struct SunPos fgCalcSunPos(struct OrbElements params)
|
||||
r = sqrt(xv*xv + yv*yv);
|
||||
|
||||
/* calculate the the Sun's true longitude (lonsun) */
|
||||
lonSun = v + params.w;
|
||||
solarPosition.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);
|
||||
/* convert true longitude and distance to ecliptic rectangular
|
||||
geocentric coordinates (xs, ys) */
|
||||
solarPosition.xs = r * cos (solarPosition.lonSun);
|
||||
solarPosition.ys = r * sin (solarPosition.lonSun);
|
||||
solarPosition.dist = r;
|
||||
return solarPosition;
|
||||
/* return solarPosition; */
|
||||
}
|
||||
|
||||
|
||||
struct CelestialCoord fgCalculateSun(struct OrbElements params, struct fgTIME t)
|
||||
{
|
||||
struct CelestialCoord
|
||||
result;
|
||||
struct SunPos
|
||||
SolarPosition;
|
||||
double
|
||||
xe, ye, ze, ecl, actTime;
|
||||
struct CelestialCoord result;
|
||||
double xe, ye, ze, ecl, actTime;
|
||||
|
||||
/* calculate the angle between ecliptic and equatorial coordinate system */
|
||||
actTime = fgCalcActTime(t);
|
||||
ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime); // Angle now in Rads
|
||||
ecl = DEG_TO_RAD * (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);
|
||||
/* 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);
|
||||
@@ -100,6 +91,7 @@ void fgSunInit( void ) {
|
||||
struct fgLIGHT *l;
|
||||
struct fgTIME *t;
|
||||
struct fgVIEW *v;
|
||||
float xSun, ySun, zSun;
|
||||
|
||||
/* GLfloat color[4] = { 1.00, 1.00, 1.00, 1.00 }; */
|
||||
double x_2, x_4, x_8, x_10;
|
||||
@@ -112,9 +104,14 @@ void fgSunInit( void ) {
|
||||
|
||||
fgPrintf( FG_ASTRO, FG_INFO, " Initializing the Sun\n");
|
||||
|
||||
// Calculate basic sun position
|
||||
fgSolarSystemUpdate(&(pltOrbElements[0]), cur_time_params);
|
||||
sunPos = fgCalculateSun(pltOrbElements[0], cur_time_params);
|
||||
|
||||
// Calculate additional sun position parameters based on the above
|
||||
// position that are needed by other parts of FG
|
||||
fgUpdateSunPos();
|
||||
|
||||
fgPrintf( FG_ASTRO, FG_INFO,
|
||||
"Sun found at %f (ra), %f (dec)\n",
|
||||
sunPos.RightAscension, sunPos.Declination);
|
||||
@@ -162,29 +159,12 @@ void fgSunInit( void ) {
|
||||
"Sun Angle : %f\n" ,
|
||||
amb[0], amb[1], amb[2], ambient, l->sun_angle);
|
||||
|
||||
/* set lighting parameters */
|
||||
/*xglLightfv(GL_LIGHT0, GL_AMBIENT, color );
|
||||
xglLightfv(GL_LIGHT0, GL_DIFFUSE, color );
|
||||
xglMaterialfv(GL_FRONT, GL_AMBIENT, amb);
|
||||
xglMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
|
||||
xglMaterialfv(GL_FRONT, GL_SHININESS, diff);
|
||||
xglMaterialfv(GL_FRONT, GL_EMISSION, diff);
|
||||
xglMaterialfv(GL_FRONT, GL_SPECULAR, diff); */
|
||||
|
||||
/* xglDisable( GL_LIGHTING ); */
|
||||
|
||||
xglPushMatrix();
|
||||
xglTranslatef(xSun, ySun, zSun);
|
||||
xglScalef(1400, 1400, 1400);
|
||||
|
||||
/*xglColor3f(0.85, 0.65, 0.05);*/
|
||||
xglColor3f(amb[0], amb[1], amb[2]);
|
||||
glutSolidSphere(1.0, 10, 10);
|
||||
|
||||
xglPopMatrix();
|
||||
|
||||
/* xglEnable( GL_LIGHTING ); */
|
||||
|
||||
xglEndList();
|
||||
}
|
||||
|
||||
@@ -196,10 +176,15 @@ void fgSunRender( void ) {
|
||||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.6 1998/02/12 21:59:39 curt
|
||||
/* Incorporated code changes contributed by Charlie Hotchkiss
|
||||
/* <chotchkiss@namg.us.anritsu.com>
|
||||
/* Revision 1.7 1998/02/23 19:07:56 curt
|
||||
/* Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
|
||||
/* calculation code between sun display, and other FG sections that use this
|
||||
/* for things like lighting.
|
||||
/*
|
||||
* Revision 1.6 1998/02/12 21:59:39 curt
|
||||
* Incorporated code changes contributed by Charlie Hotchkiss
|
||||
* <chotchkiss@namg.us.anritsu.com>
|
||||
*
|
||||
* Revision 1.5 1998/02/02 20:53:24 curt
|
||||
* To version 0.29
|
||||
*
|
||||
|
||||
14
Astro/sun.h
14
Astro/sun.h
@@ -27,7 +27,10 @@
|
||||
#define _SUN_H
|
||||
|
||||
|
||||
struct SunPos fgCalcSunPos(struct OrbElements sunParams);
|
||||
extern struct fgSUNPOS solarPosition;
|
||||
|
||||
|
||||
void fgCalcSunPos (struct OrbElements sunParams);
|
||||
extern struct OrbElements pltOrbElements[9];
|
||||
|
||||
/* Initialize the Sun */
|
||||
@@ -41,9 +44,14 @@ void fgSunRender( void );
|
||||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.3 1998/01/22 02:59:29 curt
|
||||
/* Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
/* Revision 1.4 1998/02/23 19:07:57 curt
|
||||
/* Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
|
||||
/* calculation code between sun display, and other FG sections that use this
|
||||
/* for things like lighting.
|
||||
/*
|
||||
* Revision 1.3 1998/01/22 02:59:29 curt
|
||||
* Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
*
|
||||
* Revision 1.2 1998/01/19 18:40:19 curt
|
||||
* Tons of little changes to clean up the code and to remove fatal errors
|
||||
* when building with the c++ compiler.
|
||||
|
||||
Reference in New Issue
Block a user