1
0
Fork 0

Changes to integrate Durk's moon/sun code updates + clean up.

This commit is contained in:
curt 1997-11-25 19:25:27 +00:00
parent b1cf1fcee0
commit c8d2e72433
16 changed files with 446 additions and 148 deletions

View file

@ -73,7 +73,7 @@ static GLfloat win_ratio = 1.0;
/* if the 4th field is 0.0, this specifies a direction ... */ /* if the 4th field is 0.0, this specifies a direction ... */
/* clear color (sky) */ /* clear color (sky) */
static GLfloat fgClearColor[4] = {0.60, 0.60, 0.90, 1.0}; GLfloat fgClearColor[4] = {0.60, 0.60, 0.90, 1.0};
/* fog color */ /* fog color */
static GLfloat fgFogColor[4] = {0.65, 0.65, 0.85, 1.0}; static GLfloat fgFogColor[4] = {0.65, 0.65, 0.85, 1.0};
@ -577,9 +577,12 @@ int main( int argc, char *argv[] ) {
/* $Log$ /* $Log$
/* Revision 1.23 1997/11/15 18:16:34 curt /* Revision 1.24 1997/11/25 19:25:32 curt
/* minor tweaks. /* Changes to integrate Durk's moon/sun code updates + clean up.
/* /*
* Revision 1.23 1997/11/15 18:16:34 curt
* minor tweaks.
*
* Revision 1.22 1997/10/30 12:38:41 curt * Revision 1.22 1997/10/30 12:38:41 curt
* Working on new scenery subsystem. * Working on new scenery subsystem.
* *

View file

@ -38,10 +38,8 @@
#include "../Joystick/joystick.h" #include "../Joystick/joystick.h"
#include "../Math/fg_random.h" #include "../Math/fg_random.h"
#include "../Scenery/mesh.h" #include "../Scenery/mesh.h"
#include "../Scenery/moon.h" #include "../Scenery/astro.h"
#include "../Scenery/orbits.h"
#include "../Scenery/scenery.h" #include "../Scenery/scenery.h"
#include "../Scenery/stars.h"
#include "../Time/fg_time.h" #include "../Time/fg_time.h"
#include "../Time/sunpos.h" #include "../Time/sunpos.h"
#include "../Weather/weather.h" #include "../Weather/weather.h"
@ -176,14 +174,8 @@ void fgInitSubsystems( void ) {
exit( 1 ); exit( 1 );
} }
/* Initialize the orbital elements of sun, moon and mayor planets */ /* Initialize Astronomical Objects */
fgSolarSystemInit(*t); fgAstroInit();
/* Intialize the moon's position */
fgMoonInit();
/* Initialize the Stars subsystem */
fgStarsInit();
/* Initialize the Scenery Management subsystem */ /* Initialize the Scenery Management subsystem */
fgSceneryInit(); fgSceneryInit();
@ -224,9 +216,12 @@ void fgInitSubsystems( void ) {
/* $Log$ /* $Log$
/* Revision 1.12 1997/11/15 18:16:35 curt /* Revision 1.13 1997/11/25 19:25:32 curt
/* minor tweaks. /* Changes to integrate Durk's moon/sun code updates + clean up.
/* /*
* Revision 1.12 1997/11/15 18:16:35 curt
* minor tweaks.
*
* Revision 1.11 1997/10/30 12:38:42 curt * Revision 1.11 1997/10/30 12:38:42 curt
* Working on new scenery subsystem. * Working on new scenery subsystem.
* *

View file

@ -26,7 +26,7 @@
TARGET = libScenery.a TARGET = libScenery.a
CFILES = common.c geometry.c mesh.c moon.c obj.c orbits.c planets.c \ CFILES = astro.c common.c geometry.c mesh.c moon.c obj.c orbits.c planets.c \
scenery.c stars.c sun.c scenery.c stars.c sun.c
OFILES = $(CFILES:.c=.o) OFILES = $(CFILES:.c=.o)
@ -60,6 +60,9 @@ realclean: clean
include depend include depend
astro.o:
$(CC) $(CFLAGS) -c astro.c -o $@
common.o: common.o:
$(CC) $(CFLAGS) -c common.c -o $@ $(CC) $(CFLAGS) -c common.c -o $@
@ -96,6 +99,9 @@ geometry.o:
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# $Log$ # $Log$
# 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 # Revision 1.23 1997/10/28 21:00:20 curt
# Changing to new terrain format. # Changing to new terrain format.
# #

View file

@ -1,3 +1,13 @@
astro.o: astro.c astro.h stars.h moon.h orbits.h ../Time/fg_time.h \
../Time/../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 ../constants.h \
../general.h ../Main/views.h ../Main/../types.h \
../Main/../Flight/flight.h ../Main/../Math/mat3.h \
../Aircraft/aircraft.h ../Aircraft/../Flight/flight.h \
../Aircraft/../Controls/controls.h \
../Aircraft/../Controls/../limits.h
common.o: common.c common.h common.o: common.c common.h
geometry.o: geometry.c geometry.h mesh.h geometry.o: geometry.c geometry.h mesh.h
mesh.o: mesh.c ../constants.h ../types.h ../Math/fg_geodesy.h \ mesh.o: mesh.c ../constants.h ../types.h ../Math/fg_geodesy.h \
@ -6,11 +16,10 @@ mesh.o: mesh.c ../constants.h ../types.h ../Math/fg_geodesy.h \
moon.o: moon.c orbits.h ../Time/fg_time.h ../Time/../types.h \ moon.o: moon.c orbits.h ../Time/fg_time.h ../Time/../types.h \
../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \ ../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \
../Time/../Flight/LaRCsim/ls_interface.h \ ../Time/../Flight/LaRCsim/ls_interface.h \
../Time/../Flight/LaRCsim/../flight.h moon.h ../Main/views.h \ ../Time/../Flight/LaRCsim/../flight.h moon.h ../general.h \
../Main/../types.h ../Main/../Flight/flight.h ../Main/../Math/mat3.h \ ../Main/views.h ../Main/../types.h ../Main/../Flight/flight.h \
../general.h ../Main/../Math/mat3.h
obj.o: obj.c obj.h scenery.h ../types.h ../constants.h \ obj.o: obj.c obj.h scenery.h ../types.h ../Math/mat3.h
../Math/fg_geodesy.h ../Math/polar.h ../Math/../types.h
orbits.o: orbits.c orbits.h ../Time/fg_time.h ../Time/../types.h \ orbits.o: orbits.c orbits.h ../Time/fg_time.h ../Time/../types.h \
../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \ ../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \
../Time/../Flight/LaRCsim/ls_interface.h \ ../Time/../Flight/LaRCsim/ls_interface.h \
@ -36,4 +45,6 @@ stars.o: stars.c orbits.h ../Time/fg_time.h ../Time/../types.h \
sun.o: sun.c ../Time/fg_time.h ../Time/../types.h \ sun.o: sun.c ../Time/fg_time.h ../Time/../types.h \
../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \ ../Time/../Flight/flight.h ../Time/../Flight/Slew/slew.h \
../Time/../Flight/LaRCsim/ls_interface.h \ ../Time/../Flight/LaRCsim/ls_interface.h \
../Time/../Flight/LaRCsim/../flight.h orbits.h ../Time/../Flight/LaRCsim/../flight.h ../Main/views.h \
../Main/../types.h ../Main/../Flight/flight.h ../Main/../Math/mat3.h \
orbits.h sun.h

View file

@ -1,5 +1,6 @@
/************************************************************************** /**************************************************************************
* moon.c * 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
@ -26,13 +27,123 @@
#include "orbits.h" #include "orbits.h"
#include "moon.h" #include "moon.h"
#include "../general.h"
#include "../Main/views.h" #include "../Main/views.h"
#include "../Time/fg_time.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 CelestialCoord fgCalculateMoon(struct OrbElements params,
struct OrbElements sunParams, struct OrbElements sunParams,
@ -99,7 +210,8 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params,
r += ( r += (
- 0.58 * cos(params.M - 2*D) - 0.58 * cos(params.M - 2*D)
- 0.46 * cos(2*D) - 0.46 * cos(2*D)
); ); /* Ok! */
xg = r * cos(lonecl) * cos(latecl); xg = r * cos(lonecl) * cos(latecl);
yg = r * sin(lonecl) * cos(latecl); yg = r * sin(lonecl) * cos(latecl);
zg = r * sin(latecl); zg = r * sin(latecl);
@ -110,65 +222,61 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements params,
result.RightAscension = atan2(ye, xe); result.RightAscension = atan2(ye, xe);
result.Declination = atan2(ze, sqrt(xe*xe + ye*ye)); result.Declination = atan2(ze, sqrt(xe*xe + ye*ye));
return result; return result;
} }
void fgMoonInit() void fgMoonInit()
{ {
struct CelestialCoord // int i;
moonPos; // moon = glGenLists(1);
// glNewList(moon, GL_COMPILE );
moon = glGenLists(1); fgSolarSystemUpdate(&(pltOrbElements[1]), cur_time_params);
glNewList(moon, GL_COMPILE );
glBegin( GL_POINTS );
moonPos = fgCalculateMoon(pltOrbElements[1], pltOrbElements[0], 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); printf("Moon found at %f (ra), %f (dec)\n", moonPos.RightAscension, moonPos.Declination);
/* give the moon a temporary color, for testing purposes */ #endif
glColor3f( 0.0, 1.0, 0.0); glColor3f(1.0, 1.0, 0.0);
glVertex3f( 190000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination),
190000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination), /* xMoon = 90000.0 * cos(moonPos.RightAscension) * cos(moonPos.Declination);
190000.0 * sin(moonPos.Declination) ); yMoon = 90000.0 * sin(moonPos.RightAscension) * cos(moonPos.Declination);
glEnd(); zMoon = 90000.0 * sin(moonPos.Declination); */
glEndList();
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);
// glEnd();
// glPopMatrix();
// glEndList();
} }
void fgMoonRender()
{
double angle;
static double warp = 0;
struct VIEW *v;
struct fgTIME *t;
t = &cur_time_params; /* Draw the moon */
v = &current_view; 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);
glDisable( GL_FOG );
glDisable( GL_LIGHTING );
glPushMatrix(); glPushMatrix();
glTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z ); glTranslatef(xMoon, yMoon, zMoon);
angle = t->gst * 15.0; /* 15 degrees per hour rotation */ glScalef(1400, 1400, 1400);
/* warp += 1.0; */ /* glutSolidSphere(1.0, 25, 25); */
/* warp = 15.0; */ glutSolidSphere(1.0, 15, 15);
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(); glPopMatrix();
glEnable( GL_LIGHTING );
glEnable( GL_FOG );
} }
/* $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.
*
*/

View file

@ -29,6 +29,10 @@
#include "orbits.h" #include "orbits.h"
#include "../Time/fg_time.h" #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 */
@ -42,15 +46,18 @@ struct CelestialCoord fgCalculateMoon(struct OrbElements Params,
struct fgTIME t); struct fgTIME t);
extern struct OrbElements pltOrbElements[9]; extern struct OrbElements pltOrbElements[9];
extern GLfloat fgClearColor[4];
#endif /* _MOON_H_ */ #endif /* _MOON_H_ */
/* $Log$ /* $Log$
/* Revision 1.2 1997/10/25 03:24:23 curt /* Revision 1.3 1997/11/25 19:25:35 curt
/* Incorporated sun, moon, and star positioning code contributed by Durk Talsma. /* 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 * Revision 1.1 1997/10/25 03:16:09 curt
* Initial revision of code contributed by Durk Talsma. * Initial revision of code contributed by Durk Talsma.
* *

View file

@ -117,10 +117,10 @@ GLint fgObjLoad(char *path) {
glBegin(GL_TRIANGLE_STRIP); glBegin(GL_TRIANGLE_STRIP);
printf("new tri strip = %s", line); /* printf("new tri strip = %s", line); */
sscanf(line, "t %d %d %d %d\n", &n1, &n2, &n3, &n4); sscanf(line, "t %d %d %d %d\n", &n1, &n2, &n3, &n4);
printf("(t) = "); /* printf("(t) = "); */
/* try to get the proper rotation by calculating an /* try to get the proper rotation by calculating an
* approximate normal and seeing if it is close to the * approximate normal and seeing if it is close to the
@ -169,7 +169,7 @@ GLint fgObjLoad(char *path) {
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
printf("new triangle = %s", line); /* printf("new triangle = %s", line);*/
sscanf(line, "f %d %d %d\n", &n1, &n2, &n3); sscanf(line, "f %d %d %d\n", &n1, &n2, &n3);
glNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]); glNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
@ -187,16 +187,16 @@ GLint fgObjLoad(char *path) {
/* continue a triangle strip */ /* continue a triangle strip */
n1 = n2 = 0; n1 = n2 = 0;
printf("continued tri strip = %s ", line); /* printf("continued tri strip = %s ", line); */
sscanf(line, "q %d %d\n", &n1, &n2); sscanf(line, "q %d %d\n", &n1, &n2);
printf("read %d %d\n", n1, n2); /* printf("read %d %d\n", n1, n2); */
glNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]); glNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
glVertex3d(nodes[n1][0] - ref.x, nodes[n1][1] - ref.y, glVertex3d(nodes[n1][0] - ref.x, nodes[n1][1] - ref.y,
nodes[n1][2] - ref.z); nodes[n1][2] - ref.z);
if ( n2 > 0 ) { if ( n2 > 0 ) {
printf(" (cont)\n"); /* printf(" (cont)\n"); */
glNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]); glNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]);
glVertex3d(nodes[n2][0] - ref.x, nodes[n2][1] - ref.y, glVertex3d(nodes[n2][0] - ref.x, nodes[n2][1] - ref.y,
nodes[n2][2] - ref.z); nodes[n2][2] - ref.z);
@ -216,9 +216,12 @@ GLint fgObjLoad(char *path) {
/* $Log$ /* $Log$
/* Revision 1.5 1997/11/15 18:16:39 curt /* Revision 1.6 1997/11/25 19:25:35 curt
/* minor tweaks. /* Changes to integrate Durk's moon/sun code updates + clean up.
/* /*
* Revision 1.5 1997/11/15 18:16:39 curt
* minor tweaks.
*
* Revision 1.4 1997/11/14 00:26:49 curt * Revision 1.4 1997/11/14 00:26:49 curt
* Transform scenery coordinates earlier in pipeline when scenery is being * Transform scenery coordinates earlier in pipeline when scenery is being
* created, not when it is being loaded. Precalculate normals for each node * created, not when it is being loaded. Precalculate normals for each node

View file

@ -43,17 +43,21 @@ double fgCalcActTime(struct fgTIME t)
/* a hack. This one introduces the 2000 problem into the program */ /* a hack. This one introduces the 2000 problem into the program */
year = t.gmt->tm_year + 1900; 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 * actTime = 367 * year - 7 *
(year + (t.gmt->tm_mon + 9) / 12) / 4 + 275 * (year + ((t.gmt->tm_mon+1) + 9) / 12) / 4 + 275 *
t.gmt->tm_mon / 9 + t.gmt->tm_mday - 730530; (t.gmt->tm_mon+1) / 9 + t.gmt->tm_mday - 730530;
UT = t.gmt->tm_hour + ((double) t.gmt->tm_min / 60); UT = t.gmt->tm_hour + ((double) t.gmt->tm_min / 60);
/*printf("UT = %f\n", UT); */ /*printf("UT = %f\n", UT); */
actTime += (UT / 24.0); actTime += (UT / 24.0);
#define DEBUG 1
#ifdef DEBUG
printf("Actual Time:\n");
printf("current day = %f\t", actTime); printf("current day = %f\t", actTime);
printf("GMT = %d, %d, %d, %d, %d, %d\n", year, t.gmt->tm_mon, t.gmt->tm_mday, 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); t.gmt->tm_hour, t.gmt->tm_min, t.gmt->tm_sec);
#endif
return actTime; return actTime;
} }
@ -132,7 +136,9 @@ void fgSolarSystemInit(struct fgTIME t)
printf("Cannot open data file: '%s'\n", path); printf("Cannot open data file: '%s'\n", path);
return; return;
} }
#ifdef DEBUG
printf("reading datafile %s", path); printf("reading datafile %s", path);
#endif
/* for all the objects... */ /* for all the objects... */
for (i = 0; i < 9; i ++) for (i = 0; i < 9; i ++)
@ -164,7 +170,10 @@ void fgSolarSystemUpdate(struct OrbElements *planet, struct fgTIME t)
/* $Log$ /* $Log$
/* Revision 1.1 1997/10/25 03:16:10 curt /* Revision 1.2 1997/11/25 19:25:36 curt
/* Initial revision of code contributed by Durk Talsma. /* 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.
*
*/ */

View file

@ -34,7 +34,7 @@
#include "../general.h" #include "../general.h"
#include "moon.h" #include "astro.h"
#include "obj.h" #include "obj.h"
#include "scenery.h" #include "scenery.h"
#include "stars.h" #include "stars.h"
@ -80,19 +80,19 @@ void fgSceneryUpdate(double lon, double lat, double elev) {
/* Render out the current scene */ /* Render out the current scene */
void fgSceneryRender() { void fgSceneryRender() {
glPushMatrix(); /* glCallList(area_terrain); */
glCallList(area_terrain);
glPopMatrix();
fgStarsRender();
fgMoonRender(); fgAstroRender();
} }
/* $Log$ /* $Log$
/* Revision 1.22 1997/10/28 21:00:22 curt /* Revision 1.23 1997/11/25 19:25:37 curt
/* Changing to new terrain format. /* Changes to integrate Durk's moon/sun code updates + clean up.
/* /*
* Revision 1.22 1997/10/28 21:00:22 curt
* Changing to new terrain format.
*
* Revision 1.21 1997/10/25 03:24:24 curt * Revision 1.21 1997/10/25 03:24:24 curt
* Incorporated sun, moon, and star positioning code contributed by Durk Talsma. * Incorporated sun, moon, and star positioning code contributed by Durk Talsma.
* *

View file

@ -51,7 +51,7 @@
/* Define four structures, each with varying amounts of stars */ /* Define four structures, each with varying amounts of stars */
static GLint stars[FG_STAR_LEVELS]; /* static */ GLint stars[FG_STAR_LEVELS];
/* Initialize the Star Management Subsystem */ /* Initialize the Star Management Subsystem */
@ -219,8 +219,6 @@ void fgStarsRender() {
struct FLIGHT *f; struct FLIGHT *f;
struct VIEW *v; struct VIEW *v;
struct fgTIME *t; struct fgTIME *t;
double angle;
static double warp = 0;
int i; int i;
f = &current_aircraft.flight; f = &current_aircraft.flight;
@ -231,6 +229,7 @@ void fgStarsRender() {
/* t->sun_angle = 3.0; */ /* to force stars to be drawn (for testing) */ /* t->sun_angle = 3.0; */ /* to force stars to be drawn (for testing) */
/* render the stars */
if ( t->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) { if ( t->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) {
/* determine which star structure to draw */ /* determine which star structure to draw */
if ( t->sun_angle > (FG_PI_2 + 7.25 * DEG_TO_RAD ) ) { if ( t->sun_angle > (FG_PI_2 + 7.25 * DEG_TO_RAD ) ) {
@ -245,24 +244,9 @@ void fgStarsRender() {
printf("RENDERING STARS = %d (night)\n", i); printf("RENDERING STARS = %d (night)\n", i);
glDisable( GL_FOG );
glDisable( GL_LIGHTING ); 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 stars by %.2f degrees + %.2f degrees\n",angle,warp);
glCallList(stars[i]); glCallList(stars[i]);
glPopMatrix();
glEnable( GL_LIGHTING ); glEnable( GL_LIGHTING );
glEnable( GL_FOG );
} else { } else {
printf("not RENDERING STARS (day)\n"); printf("not RENDERING STARS (day)\n");
} }
@ -270,9 +254,12 @@ void fgStarsRender() {
/* $Log$ /* $Log$
/* Revision 1.15 1997/10/30 12:38:45 curt /* Revision 1.16 1997/11/25 19:25:38 curt
/* Working on new scenery subsystem. /* 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 * Revision 1.14 1997/10/28 21:00:22 curt
* Changing to new terrain format. * Changing to new terrain format.
* *

View file

@ -22,9 +22,18 @@
* (Log is kept at end of this file) * (Log is kept at end of this file)
**************************************************************************/ **************************************************************************/
#include <GL/glut.h>
#include "../Time/fg_time.h" #include "../Time/fg_time.h"
#include "../Main/views.h"
#include "orbits.h" #include "orbits.h"
#include "sun.h"
GLint sun;
static struct CelestialCoord
sunPos;
float xSun, ySun, zSun;
struct SunPos fgCalcSunPos(struct OrbElements params) struct SunPos fgCalcSunPos(struct OrbElements params)
{ {
@ -43,7 +52,7 @@ struct SunPos fgCalcSunPos(struct OrbElements params)
v = atan2(yv, xv); v = atan2(yv, xv);
r = sqrt(xv*xv + yv*yv); 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; lonSun = v + params.w;
/* convert true longitude and distance to ecliptic rectangular geocentric /* convert true longitude and distance to ecliptic rectangular geocentric
@ -54,8 +63,141 @@ struct SunPos fgCalcSunPos(struct OrbElements params)
} }
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 = &current_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$ /* $Log$
/* Revision 1.1 1997/10/25 03:16:11 curt /* Revision 1.2 1997/11/25 19:25:39 curt
/* Initial revision of code contributed by Durk Talsma. /* 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.
*
*/ */

View file

@ -28,13 +28,24 @@
struct SunPos fgCalcSunPos(struct OrbElements sunParams); 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 */ #endif /* SUN_H */
/* $Log$ /* $Log$
/* Revision 1.1 1997/10/25 03:16:12 curt /* Revision 1.2 1997/11/25 19:25:39 curt
/* Initial revision of code contributed by Durk Talsma. /* 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.
*
*/ */

View file

@ -58,6 +58,8 @@ LN = ln -sf
# #
# -O2 - Enable compiler optimization # -O2 - Enable compiler optimization
# #
# -O3 -fomit-frame-pointer -funroll-all-loops -ffast-math
# - Other potential compiler optimization flags
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
GLOBAL_CFLAGS = -g -Wall -DVERSION=\"$(VERSION)\" GLOBAL_CFLAGS = -g -Wall -DVERSION=\"$(VERSION)\"
@ -129,6 +131,9 @@ FG_CFLAGS = $(GLOBAL_CFLAGS)
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# $Log$ # $Log$
# Revision 1.19 1997/11/25 19:25:27 curt
# Changes to integrate Durk's moon/sun code updates + clean up.
#
# Revision 1.18 1997/10/28 19:35:41 curt # Revision 1.18 1997/10/28 19:35:41 curt
# Organizational changes. # Organizational changes.
# #

View file

@ -230,9 +230,9 @@ void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t) {
static long int warp = 0; static long int warp = 0;
/* get current Unix calendar time (in seconds) */ /* get current Unix calendar time (in seconds) */
warp += 20; warp += 60;
/* warp = 0; */ /* warp = 0; */
t->cur_time = time(NULL) + 4 * 60 * 60; t->cur_time = time(NULL) + (0) * 60 * 60;
t->cur_time += warp; t->cur_time += warp;
printf("Current Unix calendar time = %ld warp = %ld\n", t->cur_time, warp); printf("Current Unix calendar time = %ld warp = %ld\n", t->cur_time, warp);
@ -276,17 +276,20 @@ void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t) {
sidereal_course(t->gmt, t->cur_time, -(FG_Longitude * RAD_TO_DEG)) sidereal_course(t->gmt, t->cur_time, -(FG_Longitude * RAD_TO_DEG))
+ t->gst_diff; + t->gst_diff;
} }
printf("Current lon=0.00 Sidereal Time = %.3f\n", t->gst); /* printf("Current lon=0.00 Sidereal Time = %.3f\n", t->gst); */
printf("Current LOCAL Sidereal Time = %.3f (%.3f) (diff = %.3f)\n", t->lst, /* printf("Current LOCAL Sidereal Time = %.3f (%.3f) (diff = %.3f)\n",
sidereal_precise(t->mjd, -(FG_Longitude * RAD_TO_DEG)), t->lst, sidereal_precise(t->mjd, -(FG_Longitude * RAD_TO_DEG)),
t->gst_diff); t->gst_diff); */
} }
/* $Log$ /* $Log$
/* Revision 1.10 1997/11/15 18:16:42 curt /* Revision 1.11 1997/11/25 19:25:40 curt
/* minor tweaks. /* Changes to integrate Durk's moon/sun code updates + clean up.
/* /*
* Revision 1.10 1997/11/15 18:16:42 curt
* minor tweaks.
*
* Revision 1.9 1997/11/14 00:26:50 curt * Revision 1.9 1997/11/14 00:26:50 curt
* Transform scenery coordinates earlier in pipeline when scenery is being * Transform scenery coordinates earlier in pipeline when scenery is being
* created, not when it is being loaded. Precalculate normals for each node * created, not when it is being loaded. Precalculate normals for each node

View file

@ -59,7 +59,8 @@ struct fgTIME {
/* position of the sun in various forms */ /* position of the sun in various forms */
double sun_lon, sun_gc_lat; /* in geocentric coordinates */ double sun_lon, sun_gc_lat; /* in geocentric coordinates */
struct fgCartesianPoint fg_sunpos; /* in cartesian coordiantes */ struct fgCartesianPoint fg_sunpos; /* in cartesian coordiantes */
GLfloat sun_vec[4]; /* in view coordinates */ GLfloat sun_vec[4]; /* (in view coordinates) */
GLfloat sun_vec_inv[4]; /* inverse (in view coordinates) */
double sun_angle; /* the angle between the sun and the double sun_angle; /* the angle between the sun and the
local horizontal */ local horizontal */
}; };
@ -78,9 +79,12 @@ void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t);
/* $Log$ /* $Log$
/* Revision 1.6 1997/09/20 03:34:35 curt /* Revision 1.7 1997/11/25 19:25:41 curt
/* Still trying to get those durned stars aligned properly. /* Changes to integrate Durk's moon/sun code updates + clean up.
/* /*
* Revision 1.6 1997/09/20 03:34:35 curt
* Still trying to get those durned stars aligned properly.
*
* Revision 1.5 1997/09/16 15:50:31 curt * Revision 1.5 1997/09/16 15:50:31 curt
* Working on star alignment and time issues. * Working on star alignment and time issues.
* *

View file

@ -282,13 +282,14 @@ void fgUpdateSunPos(struct fgCartesianPoint scenery_center) {
t->sun_gc_lat); */ t->sun_gc_lat); */
/* the sun position has to be translated just like everything else */ /* the sun position has to be translated just like everything else */
t->sun_vec[0] = t->fg_sunpos.x - scenery_center.x; t->sun_vec_inv[0] = t->fg_sunpos.x - scenery_center.x;
t->sun_vec[1] = t->fg_sunpos.y - scenery_center.y; t->sun_vec_inv[1] = t->fg_sunpos.y - scenery_center.y;
t->sun_vec[2] = t->fg_sunpos.z - scenery_center.z; t->sun_vec_inv[2] = t->fg_sunpos.z - scenery_center.z;
MAT3_SCALE_VEC(t->sun_vec, t->sun_vec, -1.0); MAT3_SCALE_VEC(t->sun_vec, t->sun_vec_inv, -1.0);
/* make this a directional light source only */ /* make these are directional light sources only */
t->sun_vec[3] = 0.0; t->sun_vec[3] = 0.0;
t->sun_vec_inv[3] = 0.0;
/* calculate thesun's relative angle to local up */ /* calculate thesun's relative angle to local up */
MAT3_COPY_VEC(nup, v->local_up); MAT3_COPY_VEC(nup, v->local_up);
@ -305,9 +306,12 @@ void fgUpdateSunPos(struct fgCartesianPoint scenery_center) {
/* $Log$ /* $Log$
/* Revision 1.12 1997/11/15 18:15:39 curt /* Revision 1.13 1997/11/25 19:25:42 curt
/* Reverse direction of sun vector, so object normals can be more normal. /* Changes to integrate Durk's moon/sun code updates + clean up.
/* /*
* Revision 1.12 1997/11/15 18:15:39 curt
* Reverse direction of sun vector, so object normals can be more normal.
*
* Revision 1.11 1997/10/28 21:07:21 curt * Revision 1.11 1997/10/28 21:07:21 curt
* Changed GLUT/ -> Main/ * Changed GLUT/ -> Main/
* *