1 /**************************************************************************
4 * Written 1997 by Durk Talsma, started October, 1997. For the flight gear
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * (Log is kept at end of this file)
23 **************************************************************************/
35 #include <Time/fg_time.h>
36 #include <Astro/orbits.h>
37 #include <Astro/planets.h>
38 #include <Astro/sun.h>
39 #include <Include/fg_constants.h>
40 #include <Main/fg_debug.h>
44 struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
45 struct OrbElements theSun,
46 struct fgTIME t, int idx)
48 struct CelestialCoord result;
50 fgSUNPOS SolarPosition;
52 double eccAnom, r, v, ecl, actTime, R, s, ir, Nr, B, FV, ring_magn,
53 xv, yv, xh, yh, zh, xg, yg, zg, xe, ye, ze;
55 actTime = fgCalcActTime(t);
56 /*calculate the angle between ecliptic and equatorial coordinate system */
57 ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime);
59 /* calculate the eccentric anomaly */
60 eccAnom = fgCalcEccAnom(planet.M, planet.e);
62 /* calculate the planets distance (r) and true anomaly (v) */
63 xv = planet.a * (cos(eccAnom) - planet.e);
64 yv = planet.a * (sqrt(1.0 - planet.e*planet.e) * sin(eccAnom));
66 r = sqrt ( xv*xv + yv*yv);
68 /* calculate the planets position in 3-dimensional space */
69 xh = r * (cos (planet.N) * cos (v + planet.w) -
70 sin (planet.N) * sin (v + planet.w) * cos (planet.i));
71 yh = r * (sin (planet.N) * cos (v + planet.w) +
72 cos (planet.N) * sin (v + planet.w) * cos (planet.i));
73 zh = r * ( sin(v+planet.w) * sin(planet.i));
75 /* calculate the ecliptic longitude and latitude */
77 xg = xh + solarPosition.xs;
78 yg = yh + solarPosition.ys;
82 ye = yg * cos(ecl) - zg * sin(ecl);
83 ze = yg * sin(ecl) + zg * cos(ecl);
85 result.RightAscension = atan2(ye,xe);
86 result.Declination = atan2(ze, sqrt(xe*xe + ye*ye));
88 /* Let's calculate the brightness of the planet */
89 R = sqrt ( xg*xg + yg*yg + zg*zg);
90 s = SolarPosition.dist;
91 FV = acos( (r*r + R*R - s*s) / (2*r*R));
92 FV *= 57.29578; /* convert radians to degrees */
96 result.magnitude = -0.36 + 5*log10( r*R ) + 0.027 * FV + 2.2E-13 * pow(FV, 6);
99 result.magnitude = -4.34 + 5*log10( r*R ) + 0.013 * FV + 4.2E-07 * pow(FV,3);
102 result.magnitude = -1.51 + 5*log10( r*R ) + 0.016 * FV;
104 case 5: /* Jupiter */
105 result.magnitude = -9.25 + 5*log10( r*R ) + 0.014 * FV;
110 Nr = 2.9585076 + 6.6672E-7*actTime;
112 B = asin (sin (result.Declination) * cos (ir) -
113 cos (result.Declination) * sin (ir) *
114 sin (result.RightAscension - Nr));
115 ring_magn = -2.6 * sin (fabs(B)) + 1.2 * pow(sin(B),2);
116 result.magnitude = -9.0 + 5*log10( r*R ) + 0.044 * FV + ring_magn;
119 result.magnitude = -7.15 + 5*log10( r*R) + 0.001 * FV;
121 case 8: /* Neptune */
122 result.magnitude = -6.90 + 5*log10 (r*R) + 0.001 *FV;
125 fgPrintf( FG_ASTRO, FG_ALERT, "index %d out of range !!!!\n", idx);
127 fgPrintf( FG_ASTRO, FG_DEBUG,
128 " Planet found at %f (ra), %f (dec)\n",
129 result.RightAscension, result.Declination);
130 fgPrintf( FG_ASTRO, FG_DEBUG,
131 " Geocentric dist %f\n"
132 " Heliocentric dist %f\n"
133 " Distance to the sun %f\n"
135 " Brightness %f\n", R, r, s, FV, result.magnitude);
140 void fgPlanetsInit( void )
144 struct CelestialCoord pltPos;
147 l = &cur_light_params;
148 /* if the display list was already built during a previous init,
152 xglDeleteLists(planets, 1);
155 planets = xglGenLists(1);
156 xglNewList( planets, GL_COMPILE );
157 xglBegin( GL_POINTS );
160 /* Add the planets to all four display lists */
161 for ( i = 2; i < 9; i++ ) {
162 fgSolarSystemUpdate(&(pltOrbElements[i]), cur_time_params);
163 pltPos = fgCalculatePlanet(pltOrbElements[i],
164 pltOrbElements[0], cur_time_params, i);
166 magnitude = (0.0 - pltPos.magnitude) / 5.0 + 1.0;
168 /* scale magnitudes again so they look ok */
170 magnitude * 0.7 + (((FG_STAR_LEVELS - 1) - i) * 0.1); */
172 /* the following statement could be made a little more sopisticated
173 for the moment: Stick to this one */
174 magnitude = magnitude * 0.7 + (3 * 0.1);
175 if ( magnitude > 1.0 ) { magnitude = 1.0; }
176 if ( magnitude < 0.0 ) { magnitude = 0.0; }
178 /* Add planets to the display list, based on sun_angle and current
179 magnitude It's pretty experimental... */
181 if ((double) (l->sun_angle - FG_PI_2) >
182 ((magnitude - 1.0) * -20 * DEG_TO_RAD))
184 xglColor3f (magnitude, magnitude, magnitude);
185 printf ("Sun Angle to Horizon (in Rads) = %f\n",
186 (double) (l->sun_angle - FG_PI_2));
187 printf ("Transformed Magnitude is :%f %f\n",
188 magnitude, (magnitude - 1.0) * -20 * DEG_TO_RAD);
190 xglVertex3f (50000.0 * cos (pltPos.RightAscension) *
191 cos (pltPos.Declination),
192 50000.0 * sin (pltPos.RightAscension) *
193 cos (pltPos.Declination),
194 50000.0 * sin (pltPos.Declination));
203 void fgPlanetsRender( void ) {
204 xglCallList(planets);
209 /* Revision 1.8 1998/04/03 21:52:50 curt
210 /* Converting to Gnu autoconf system.
212 * Revision 1.7 1998/02/23 19:07:55 curt
213 * Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
214 * calculation code between sun display, and other FG sections that use this
215 * for things like lighting.
217 * Revision 1.6 1998/02/12 21:59:36 curt
218 * Incorporated code changes contributed by Charlie Hotchkiss
219 * <chotchkiss@namg.us.anritsu.com>
221 * Revision 1.5 1998/02/03 23:20:12 curt
222 * Lots of little tweaks to fix various consistency problems discovered by
223 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
224 * passed arguments along to the real printf(). Also incorporated HUD changes
225 * by Michele America.
227 * Revision 1.4 1998/02/02 20:53:23 curt
230 * Revision 1.3 1998/01/27 00:47:47 curt
231 * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
232 * system and commandline/config file processing code.
234 * Revision 1.2 1998/01/19 19:26:59 curt
235 * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
236 * This should simplify things tremendously.
238 * Revision 1.1 1998/01/07 03:16:18 curt
239 * Moved from .../Src/Scenery/ to .../Src/Astro/
241 * Revision 1.4 1997/12/30 20:47:52 curt
242 * Integrated new event manager with subsystem initializations.
244 * Revision 1.3 1997/12/30 16:36:52 curt
245 * Merged in Durk's changes ...
247 * Revision 1.2 1997/12/12 21:41:29 curt
248 * More light/material property tweaking ... still a ways off.
250 * Revision 1.1 1997/10/25 03:16:10 curt
251 * Initial revision of code contributed by Durk Talsma.