Modified Files:

ephemeris.cxx ephemeris.hxx stardata.cxx stardata.hxx: Throw out sg.h
This commit is contained in:
frohlich
2007-02-02 18:09:27 +00:00
parent 1bb6c03bd0
commit b13900402d
4 changed files with 28 additions and 51 deletions
+2 -3
View File
@@ -42,9 +42,8 @@ SGEphemeris::SGEphemeris( const string &path ) {
uranus = new Uranus; uranus = new Uranus;
neptune = new Neptune; neptune = new Neptune;
nplanets = 7; nplanets = 7;
for ( int i = 0; i < nplanets; ++i ) { for ( int i = 0; i < nplanets; ++i )
sgdSetVec3( planets[i].sg(), 0.0, 0.0, 0.0 ); planets[i] = SGVec3d::zeros();
}
stars = new SGStarData( SGPath(path) ); stars = new SGStarData( SGPath(path) );
} }
+2 -2
View File
@@ -30,8 +30,6 @@
#define _EPHEMERIS_HXX #define _EPHEMERIS_HXX
#include <plib/sg.h>
#include <simgear/ephemeris/star.hxx> #include <simgear/ephemeris/star.hxx>
#include <simgear/ephemeris/moonpos.hxx> #include <simgear/ephemeris/moonpos.hxx>
#include <simgear/ephemeris/mercury.hxx> #include <simgear/ephemeris/mercury.hxx>
@@ -43,6 +41,8 @@
#include <simgear/ephemeris/neptune.hxx> #include <simgear/ephemeris/neptune.hxx>
#include <simgear/ephemeris/stardata.hxx> #include <simgear/ephemeris/stardata.hxx>
#include <simgear/math/SGMath.hxx>
/** Ephemeris class /** Ephemeris class
* *
+14 -27
View File
@@ -25,6 +25,7 @@
#endif #endif
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/sgstream.hxx> #include <simgear/misc/sgstream.hxx>
#include "stardata.hxx" #include "stardata.hxx"
@@ -34,16 +35,9 @@
#endif #endif
// Constructor // Constructor
SGStarData::SGStarData() : SGStarData::SGStarData( const SGPath& path )
nstars(0)
{ {
} load(path);
SGStarData::SGStarData( SGPath path ) :
nstars(0)
{
data_path = SGPath( path );
load();
} }
@@ -52,31 +46,27 @@ SGStarData::~SGStarData() {
} }
bool SGStarData::load() { bool SGStarData::load( const SGPath& path ) {
// -dw- avoid local data > 32k error by dynamic allocation of the _stars.clear();
// array, problem for some compilers
stars = new SGVec3d[SG_MAX_STARS];
// build the full path name to the stars data base file // build the full path name to the stars data base file
data_path.append( "stars" ); path.append( "stars" );
SG_LOG( SG_ASTRO, SG_INFO, " Loading stars from " << data_path.str() ); SG_LOG( SG_ASTRO, SG_INFO, " Loading stars from " << path.str() );
sg_gzifstream in( data_path.str() ); sg_gzifstream in( path.str() );
if ( ! in.is_open() ) { if ( ! in.is_open() ) {
SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: " SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: "
<< data_path.str() ); << path.str() );
exit(-1); return false;
} }
double ra, dec, mag; double ra, dec, mag;
char c; char c;
string name; string name;
nstars = 0;
// read in each line of the file // read in each line of the file
while ( ! in.eof() && nstars < SG_MAX_STARS ) { while ( ! in.eof() ) {
in >> skipcomment; in >> skipcomment;
getline( in, name, ',' ); getline( in, name, ',' );
@@ -116,13 +106,10 @@ bool SGStarData::load() {
in >> mag; in >> mag;
// cout << " star data = " << ra << " " << dec << " " << mag << endl; // cout << " star data = " << ra << " " << dec << " " << mag << endl;
_stars.push_back(SGVec3d(ra, dec, mag));
sgdSetVec3( stars[nstars].sg(), ra, dec, mag );
++nstars;
} }
SG_LOG( SG_ASTRO, SG_INFO, " Loaded " << nstars << " stars" ); SG_LOG( SG_ASTRO, SG_INFO, " Loaded " << _stars.size() << " stars" );
return true; return true;
} }
+10 -19
View File
@@ -24,37 +24,28 @@
#ifndef _SG_STARDATA_HXX #ifndef _SG_STARDATA_HXX
#define _SG_STARDATA_HXX #define _SG_STARDATA_HXX
#include <vector>
#include <simgear/math/SGMath.hxx>
#include <plib/sg.h> class SGPath;
#include <simgear/misc/sg_path.hxx>
#define SG_MAX_STARS 850
class SGStarData { class SGStarData {
int nstars;
SGVec3d *stars;
SGPath data_path;
public: public:
// Constructor // Constructor
SGStarData(); SGStarData( const SGPath& path );
SGStarData( SGPath path );
// Destructor // Destructor
~SGStarData(); ~SGStarData();
// load the stars database // load the stars database
bool load(); bool load( const SGPath& path );
// stars // stars
inline int getNumStars() const { return nstars; } inline int getNumStars() const { return _stars.size(); }
inline SGVec3d *getStars() { return stars; } inline SGVec3d *getStars() { return &(_stars[0]); }
private:
std::vector<SGVec3d> _stars;
}; };