Removed solarsystem.* replaced mostly with ephemeris.* which is similar

but not rendering oriented.
Added star database management class.
This commit is contained in:
curt 2000-03-16 22:00:53 +00:00
parent 427f309aea
commit 1984ae1583
7 changed files with 110 additions and 552 deletions

View File

@ -10,7 +10,6 @@ libAstro_a_SOURCES = \
neptune.cxx neptune.hxx \
pluto.hxx \
saturn.cxx saturn.hxx \
solarsystem.cxx solarsystem.hxx \
star.cxx star.hxx \
stars.cxx stars.hxx \
uranus.cxx uranus.hxx \

View File

@ -26,7 +26,7 @@
// Constructor
FGEphemeris::FGEphemeris( void ) {
FGEphemeris::FGEphemeris( const string &path ) {
our_sun = new Star;
moon = new Moon;
mercury = new Mercury;
@ -36,6 +36,7 @@ FGEphemeris::FGEphemeris( void ) {
saturn = new Saturn;
uranus = new Uranus;
neptune = new Neptune;
stars = new FGStars( FGPath(path) );
}
@ -50,6 +51,7 @@ FGEphemeris::~FGEphemeris( void ) {
delete saturn;
delete uranus;
delete neptune;
delete stars;
}

View File

@ -39,6 +39,7 @@
#include "saturn.hxx"
#include "uranus.hxx"
#include "neptune.hxx"
#include "stars.hxx"
class FGEphemeris {
@ -59,11 +60,13 @@ class FGEphemeris {
// planets[i][2] = Magnitude
int nplanets;
sgdVec3 planets[7];
FGStars *stars;
public:
// Constructor
FGEphemeris( void );
FGEphemeris( const string &path );
// Destructor
~FGEphemeris( void );
@ -93,6 +96,10 @@ public:
// planets
inline int getNumPlanets() const { return nplanets; }
inline sgdVec3 *getPlanets() { return planets; }
// planets
inline int getNumStars() const { return stars->getNumStars(); }
inline sgdVec3 *getStars() { return stars->getStars(); }
};

View File

@ -1,221 +0,0 @@
/**************************************************************************
* solarsystem.cxx
* Written by Durk Talsma. Originally started October 1997, for distribution
* with the FlightGear project. Version 2 was written in August and
* September 1998. This code is based upon algorithms and data kindly
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
*
* 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$
**************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#ifdef __BORLANDC__
# define exception c_exception
#endif
#include <math.h>
#include <GL/glut.h>
#include <simgear/xgl/xgl.h>
#include <simgear/debug/logstream.hxx>
#include <Time/sunpos.hxx>
#include <Time/moonpos.hxx>
#include "solarsystem.hxx"
/***************************************************************************
* default constructor for class SolarSystem:
* or course there can only be one way to create an entire solar system -:) )
* the FGTime argument is needed to properly initialize the the current orbital
* elements
*************************************************************************/
SolarSystem::SolarSystem(FGTime *t)
{
if (theSolarSystem)
{
FG_LOG( FG_GENERAL, FG_ALERT, "Error: only one solarsystem allowed" );
exit(-1);
}
theSolarSystem = this;
ourSun = new Star(t);
earthsMoon = new Moon(t);
mercury = new Mercury(t);
venus = new Venus(t);
mars = new Mars(t);
jupiter = new Jupiter(t);
saturn = new Saturn(t);
uranus = new Uranus(t);
neptune = new Neptune(t);
displayList = 0;
};
/**************************************************************************
* the destructor for class SolarSystem;
**************************************************************************/
SolarSystem::~SolarSystem()
{
delete ourSun;
delete earthsMoon;
delete mercury;
delete venus;
delete mars;
delete jupiter;
delete saturn;
delete uranus;
delete neptune;
}
/****************************************************************************
* void SolarSystem::rebuild()
*
* this member function updates the positions for the sun, moon, and planets,
* and then rebuilds the display list.
*
* arguments: none
* return value: none
***************************************************************************/
void SolarSystem::rebuild()
{
//fgLIGHT *l = &cur_light_params;
FGTime *t = FGTime::cur_time_params;
//float x, y, z;
//double sun_angle;
double ra, dec;
//double x_2, x_4, x_8, x_10;*/
double magnitude;
//GLfloat ambient;
//GLfloat amb[4];
#if 0
glDisable(GL_LIGHTING);
// Step 1: update all the positions
ourSun->updatePosition(t);
earthsMoon->updatePosition(t, ourSun);
mercury->updatePosition(t, ourSun);
venus->updatePosition(t, ourSun);
mars->updatePosition(t, ourSun);
jupiter->updatePosition(t, ourSun);
saturn->updatePosition(t, ourSun);
uranus->updatePosition(t, ourSun);
neptune->updatePosition(t, ourSun);
fgUpdateSunPos(); // get the right sun angle (especially important when
// running for the first time).
fgUpdateMoonPos();
if (displayList)
xglDeleteLists(displayList, 1);
displayList = xglGenLists(1);
FG_LOG( FG_ASTRO, FG_INFO, "Rebuilding astro display list" );
// Step 2: rebuild the display list
xglNewList( displayList, GL_COMPILE);
{
// Step 2a: Add the moon...
// Not that it is preferred to draw the moon first, and the sun next, in order to mime a
// solar eclipse. This is yet untested though...
// Euhh, actually the ecplise doesn't work...
// earthsMoon->newImage();
// Step 2b: Add the sun
// ourSun->newImage();
// Step 2c: Add the planets
xglBegin(GL_POINTS);
mercury->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
venus ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
mars ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
jupiter->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
saturn ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
uranus ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
neptune->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
xglEnd();
xglEnable(GL_LIGHTING);
}
xglEndList();
#endif
}
/*****************************************************************************
* double SolarSystem::scaleMagnitude(double magn)
* This private member function rescales the original magnitude, as used in the
* astronomical sense of the word, into a value used by OpenGL to draw a
* convincing Star or planet
*
* Argument: the astronomical magnitude
*
* return value: the rescaled magnitude
****************************************************************************/
double SolarSystem::scaleMagnitude(double magn)
{
double magnitude = (0.0 - magn) / 5.0 + 1.0;
magnitude = magnitude * 0.7 + (3 * 0.1);
if (magnitude > 1.0) magnitude = 1.0;
if (magnitude < 0.0) magnitude = 0.0;
return magnitude;
}
/***************************************************************************
* void SolarSytem::addPlanetToList(double ra, double dec, double magn);
*
* This private member function first causes the magnitude to be properly
* rescaled, and then adds the planet to the display list.
*
* arguments: Right Ascension, declination, and magnitude
*
* return value: none
**************************************************************************/
void SolarSystem::addPlanetToList(double ra, double dec, double magn)
{
double
magnitude = scaleMagnitude ( magn );
fgLIGHT *l = &cur_light_params;
#if 0
if ((double) (l->sun_angle - FG_PI_2) >
((magnitude - 1.0) * - 20 * DEG_TO_RAD))
{
xglColor3f (magnitude, magnitude, magnitude);
xglVertex3f( 50000.0 * cos (ra) * cos (dec),
50000.0 * sin (ra) * cos (dec),
50000.0 * sin (dec));
}
#endif
}
SolarSystem* SolarSystem::theSolarSystem = 0;
/******************************************************************************
* void solarSystemRebuild()
* this a just a wrapper function, provided for use as an interface to the
* event manager
*****************************************************************************/
void solarSystemRebuild()
{
SolarSystem::theSolarSystem->rebuild();
}

View File

@ -1,91 +0,0 @@
/**************************************************************************
* solarsystem.hxx
* Written by Durk Talsma. Originally started October 1997, for distribution
* with the FlightGear project. Version 2 was written in August and
* September 1998. This code is based upon algorithms and data kindly
* provided by Mr. Paul Schlyter. (pausch@saaf.se).
*
* 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$
**************************************************************************/
#ifndef _SOLARSYSTEM_H_
#define _SOLARSYSTEM_H_
#include <Time/light.hxx>
#include <Time/fg_time.hxx>
#include <Main/views.hxx>
#include "star.hxx"
#include "moon.hxx"
#include "mercury.hxx"
#include "venus.hxx"
#include "mars.hxx"
#include "jupiter.hxx"
#include "saturn.hxx"
#include "uranus.hxx"
#include "neptune.hxx"
#include "pluto.hxx"
class SolarSystem
{
private:
Star* ourSun;
Moon* earthsMoon;
Mercury* mercury;
Venus* venus;
Mars* mars;
Jupiter* jupiter;
Saturn* saturn;
Uranus* uranus;
Neptune* neptune;
//Pluto* pluto;
GLint displayList;
double scaleMagnitude(double magn);
void addPlanetToList(double ra, double dec, double magn);
public:
SolarSystem(FGTime *t);
CelestialBody *getSun();
CelestialBody *getMoon();
~SolarSystem();
static SolarSystem *theSolarSystem; // thanks to Bernie Bright!
void rebuild();
friend void solarSystemRebuild();
void draw();
};
inline CelestialBody* SolarSystem::getSun()
{
return ourSun;
}
inline CelestialBody* SolarSystem::getMoon()
{
return earthsMoon;
}
inline void SolarSystem::draw()
{
xglCallList(displayList);
}
extern void solarSystemRebuild();
#endif // _SOLARSYSTEM_H_

View File

@ -1,8 +1,8 @@
// stars.cxx -- data structures and routines for managing and rendering stars.
// stars.cxx -- manage star data
//
// Written by Curtis Olson, started August 1997.
// Written by Curtis Olson, started March 2000.
//
// Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
@ -19,250 +19,98 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
//*************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#include <simgear/compiler.h>
#ifdef FG_HAVE_STD_INCLUDES
# include <cmath>
# include <cstdio>
# include <cstring>
# include <ctime>
#else
# include <math.h>
# include <stdio.h>
# include <string.h>
# include <time.h>
#endif
#include <string>
#include <GL/glut.h>
#include <simgear/xgl/xgl.h>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/fgpath.hxx>
#include <simgear/misc/fgstream.hxx>
#include <simgear/misc/stopwatch.hxx>
#include <Aircraft/aircraft.hxx>
#include <Main/options.hxx>
#include <Main/views.hxx>
#include <Time/fg_time.hxx>
#include "stars.hxx"
// FG_USING_STD(getline);
#define EpochStart (631065600)
#define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
#define FG_MAX_STARS 3500
// Constructor
FGStars::FGStars() {
}
// Define four structures, each with varying amounts of stars
static GLint stars[FG_STAR_LEVELS];
FGStars::FGStars( FGPath path ) {
data_path = FGPath( path );
load();
}
// Initialize the Star Management Subsystem
int fgStarsInit( void ) {
// Destructor
FGStars::~FGStars() {
}
bool FGStars::load() {
// -dw- avoid local data > 32k error by dynamic allocation of the
// array, problem for some compilers
Point3D *starlist = new Point3D[FG_MAX_STARS];
// struct CelestialCoord pltPos;
double right_ascension, declination, magnitude;
double min_magnitude[FG_STAR_LEVELS];
// double ra_save, decl_save;
// double ra_save1, decl_save1;
int i, j, starcount, count;
stars = new sgdVec3[FG_MAX_STARS];
FG_LOG( FG_ASTRO, FG_INFO, "Initializing stars" );
// build the full path name to the stars data base file
data_path.append( "stars" );
cout << " Loading stars from " << data_path.str() << endl;
if ( FG_STAR_LEVELS < 4 ) {
FG_LOG( FG_ASTRO, FG_ALERT, "Big whups in stars.cxx" );
fg_gzifstream in( data_path.str() );
if ( ! in.is_open() ) {
cout << "Cannot open star file: " << data_path.str() << endl;
exit(-1);
}
// build the full path name to the stars data base file
FGPath path ( current_options.get_fg_root() );
path.append( "Astro/stars" );
FG_LOG( FG_ASTRO, FG_INFO, " Loading stars from " << path.str() );
double ra, dec, mag;
char c;
string name;
fg_gzifstream in( path.str() );
if ( ! in ) {
FG_LOG( FG_ASTRO, FG_ALERT, "Cannot open star file: " << path.str() );
exit(-1);
}
starcount = 0;
StopWatch timer;
timer.start();
nstars = 0;
// read in each line of the file
while ( ! in.eof() && starcount < FG_MAX_STARS )
{
while ( ! in.eof() && nstars < FG_MAX_STARS ) {
in >> skipcomment;
string name;
getline( in, name, ',' );
in >> starlist[starcount];
++starcount;
}
timer.stop();
FG_LOG( FG_ASTRO, FG_INFO,
"Loaded " << starcount << " stars in "
<< timer.elapsedSeconds() << " seconds" );
getline( in, name, ',' );
// cout << " data = " << name << endl;
min_magnitude[0] = 4.2;
min_magnitude[1] = 3.6;
min_magnitude[2] = 3.0;
min_magnitude[3] = 2.4;
min_magnitude[4] = 1.8;
min_magnitude[5] = 1.2;
min_magnitude[6] = 0.6;
min_magnitude[7] = 0.0;
// build the various star display lists
for ( i = 0; i < FG_STAR_LEVELS; i++ ) {
stars[i] = xglGenLists(1);
xglNewList( stars[i], GL_COMPILE );
xglBegin( GL_POINTS );
count = 0;
for ( j = 0; j < starcount; j++ ) {
magnitude = starlist[j].z();
// printf("magnitude = %.2f\n", magnitude);
if ( magnitude < min_magnitude[i] ) {
right_ascension = starlist[j].x();
declination = starlist[j].y();
count++;
// 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.042);
magnitude = magnitude * 0.9 +
(((FG_STAR_LEVELS - 1) - i) * 0.014);
// 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) );
// read name and first comma
while ( in.get(c) ) {
if ( (c != ' ') && (c != ',') ) {
// push back on the stream
in.putback(c);
break;
}
} // while
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();
FG_LOG( FG_ASTRO, FG_INFO,
" Loading " << count << " stars brighter than "
<< min_magnitude[i] );
}
return 1; // OK, we got here because initialization worked.
}
// Draw the Stars
void fgStarsRender( void ) {
FGInterface *f;
fgLIGHT *l;
FGTime *t;
int i;
f = current_aircraft.fdm_state;
l = &cur_light_params;
t = FGTime::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)
// 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 + 10.0 * DEG_TO_RAD ) ) {
i = 0;
} else if ( l->sun_angle > (FG_PI_2 + 8.8 * DEG_TO_RAD ) ) {
i = 1;
} else if ( l->sun_angle > (FG_PI_2 + 7.5 * DEG_TO_RAD ) ) {
i = 2;
} else if ( l->sun_angle > (FG_PI_2 + 7.0 * DEG_TO_RAD ) ) {
i = 3;
} else if ( l->sun_angle > (FG_PI_2 + 6.5 * DEG_TO_RAD ) ) {
i = 4;
} else if ( l->sun_angle > (FG_PI_2 + 6.0 * DEG_TO_RAD ) ) {
i = 5;
} else if ( l->sun_angle > (FG_PI_2 + 5.5 * DEG_TO_RAD ) ) {
i = 6;
} else {
i = 7;
}
// printf("RENDERING STARS = %d (night)\n", i);
in >> ra;
xglCallList(stars[i]);
} else {
// printf("not RENDERING STARS (day)\n");
// read past optional comma
while ( in.get(c) ) {
if ( (c != ' ') && (c != ',') ) {
// push back on the stream
in.putback(c);
break;
}
}
in >> dec;
// read past optional comma
while ( in.get(c) ) {
if ( (c != ' ') && (c != ',') ) {
// push back on the stream
in.putback(c);
break;
}
}
in >> mag;
// cout << " star data = " << ra << " " << dec << " " << mag << endl;
sgdSetVec3( stars[nstars], ra, dec, mag );
++nstars;
}
cout << " Loaded " << nstars << " stars" << endl;
return true;
}

View File

@ -1,8 +1,8 @@
// stars.hxx -- data structures and routines for managing and rendering stars.
// stars.hxx -- manage star data
//
// Written by Curtis Olson, started August 1997.
// Written by Curtis Olson, started March 2000.
//
// Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
@ -25,23 +25,37 @@
#define _STARS_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#include <plib/sg.h>
#include <Time/fg_time.hxx>
#include <simgear/misc/fgpath.hxx>
#define FG_STAR_LEVELS 8 // how many star transitions
// Initialize the Star Management Subsystem
int fgStarsInit( void );
#define FG_MAX_STARS 3500
// Draw the Stars
void fgStarsRender( void );
// [no longer used?] extern FGTime cur_time_params;
class FGStars {
int nstars;
sgdVec3 *stars;
FGPath data_path;
public:
// Constructor
FGStars();
FGStars( FGPath path );
// Destructor
~FGStars();
// load the stars database
bool load();
// stars
inline int getNumStars() const { return nstars; }
inline sgdVec3 *getStars() { return stars; }
};
#endif // _STARS_HXX