Merged in Durk's changes ...

This commit is contained in:
curt
1997-12-30 16:36:40 +00:00
parent de235cc8be
commit 5c5e4fff7b
5 changed files with 189 additions and 88 deletions

View File

@@ -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 = &current_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;
}

View File

@@ -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.
*
*/

View File

@@ -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.
*
*/

View File

@@ -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.
*

View File

@@ -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 = &current_view;
l = &cur_light_params;
/* x_2 = t->sun_angle * t->sun_angle;
x_2 = l->sun_angle * l->sun_angle;
x_4 = x_2 * x_2;
x_8 = x_4 * x_4;
x_10 = x_8 * x_2; */
x_10 = x_8 * x_2;
/* ambient = (0.4 * pow(1.1, -x_10 / 30.0));
ambient = (0.4 * pow(1.1, -x_10 / 30.0));
if ( ambient < 0.3 ) ambient = 0.3;
if ( ambient > 1.0 ) ambient = 1.0;
amb[0] = 0.50 + ((ambient * 6.66) - 1.6);
amb[1] = 0.00 + ((ambient * 6.66) - 1.6);
amb[2] = 0.00 + ((ambient * 6.66) - 1.6);
@@ -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.
*