SolarSystem.cpp   SolarSystem.cpp 
skipping to change at line 20 skipping to change at line 20
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include <algorithm>
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "StelTexture.hpp" #include "StelTexture.hpp"
#include "stellplanet.h" #include "stellplanet.h"
#include "Orbit.hpp" #include "Orbit.hpp"
#include "StelNavigator.hpp" #include "StelNavigator.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelFontMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelSkyCultureMgr.hpp" #include "StelSkyCultureMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
#include "Planet.hpp" #include "Planet.hpp"
#include "StelNavigator.hpp" #include "StelNavigator.hpp"
#include "StelFont.hpp"
#include "StelSkyDrawer.hpp" #include "StelSkyDrawer.hpp"
#include "StelStyle.hpp" #include "StelStyle.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include <functional>
#include <algorithm>
#include <QTextStream> #include <QTextStream>
#include <QSettings> #include <QSettings>
#include <QVariant> #include <QVariant>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QMap> #include <QMap>
#include <QMultiMap> #include <QMultiMap>
#include <QMapIterator> #include <QMapIterator>
#include <QDebug> #include <QDebug>
using namespace std; SolarSystem::SolarSystem() : moonScale(1.), flagOrbits(false), flagLight
TravelTime(false), lastHomePlanet(NULL)
SolarSystem::SolarSystem() :sun(NULL),moon(NULL),earth(NULL),selected(NULL)
, moonScale(1.), fontSize(14.),
planetNameFont(StelApp::getInstance().getFontManager().getStandardFo
nt(StelApp::getInstance().getLocaleMgr().getAppLanguage(), fontSize)),
flagOrbits(false),flagLightTravelTime(false), lastHomePlanet(NULL)
{ {
planetNameFont.setPixelSize(14.);
setObjectName("SolarSystem"); setObjectName("SolarSystem");
} }
void SolarSystem::setFontSize(float newFontSize) void SolarSystem::setFontSize(float newFontSize)
{ {
planetNameFont = StelApp::getInstance().getFontManager().getStandard Font(StelApp::getInstance().getLocaleMgr().getSkyLanguage(), fontSize); planetNameFont.setPixelSize(newFontSize);
} }
SolarSystem::~SolarSystem() SolarSystem::~SolarSystem()
{ {
// release selected: // release selected:
selected = NULL; selected.clear();
for(std::vector<Planet*>::iterator iter = systemPlanets.begin(); ite foreach (Orbit* orb, orbits)
r != systemPlanets.end(); ++iter)
{ {
if (*iter) delete *iter; delete orb;
*iter = NULL; orb = NULL;
} }
for(std::vector<Orbit*>::iterator iter = orbits.begin(); iter != orb sun.clear();
its.end(); ++iter) moon.clear();
{ earth.clear();
if (*iter) delete *iter; Planet::hintCircleTex.clear();
*iter = NULL; Planet::texEarthShadow.clear();
}
sun = NULL;
moon = NULL;
earth = NULL;
Planet::hintCircleTex.reset();
Planet::texEarthShadow.reset();
} }
/************************************************************************* /*************************************************************************
Reimplementation of the getCallOrder method Reimplementation of the getCallOrder method
*************************************************************************/ *************************************************************************/
double SolarSystem::getCallOrder(StelModuleActionName actionName) const double SolarSystem::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Star Mgr")->getCallOrder(actionName)+10; return StelApp::getInstance().getModuleMgr().getModule("Star Mgr")->getCallOrder(actionName)+10;
return 0; return 0;
skipping to change at line 124 skipping to change at line 116
setFlagPlanets(conf->value("astro/flag_planets").toBool()); setFlagPlanets(conf->value("astro/flag_planets").toBool());
setFlagHints(conf->value("astro/flag_planets_hints").toBool()); setFlagHints(conf->value("astro/flag_planets_hints").toBool());
setFlagLabels(conf->value("astro/flag_planets_labels", true).toBool( )); setFlagLabels(conf->value("astro/flag_planets_labels", true).toBool( ));
setLabelsAmount(conf->value("astro/labels_amount", 3.).toDouble()); setLabelsAmount(conf->value("astro/labels_amount", 3.).toDouble());
setFlagOrbits(conf->value("astro/flag_planets_orbits").toBool()); setFlagOrbits(conf->value("astro/flag_planets_orbits").toBool());
setFlagLightTravelTime(conf->value("astro/flag_light_travel_time", f alse).toBool()); setFlagLightTravelTime(conf->value("astro/flag_light_travel_time", f alse).toBool());
setFlagTrails(conf->value("astro/flag_object_trails", false).toBool( )); setFlagTrails(conf->value("astro/flag_object_trails", false).toBool( ));
startTrails(conf->value("astro/flag_object_trails", false).toBool()) ; startTrails(conf->value("astro/flag_object_trails", false).toBool()) ;
GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this); GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this);
StelApp::getInstance().getTextureManager().setDefaultParams();
StelApp::getInstance().getTextureManager().setMinFilter(GL_LINEAR);
texPointer = StelApp::getInstance().getTextureManager().createTextur e("pointeur4.png"); texPointer = StelApp::getInstance().getTextureManager().createTextur e("pointeur4.png");
Planet::hintCircleTex = StelApp::getInstance().getTextureManager().c reateTexture("planet-indicator.png"); Planet::hintCircleTex = StelApp::getInstance().getTextureManager().c reateTexture("planet-indicator.png");
} }
void SolarSystem::drawPointer(const StelCore* core) void SolarSystem::drawPointer(const StelCore* core)
{ {
const StelNavigator* nav = core->getNavigator(); const StelNavigator* nav = core->getNavigator();
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ; const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ;
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Planet"); const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Planet");
if (!newSelected.empty()) if (!newSelected.empty())
{ {
const StelObjectP obj = newSelected[0]; const StelObjectP obj = newSelected[0];
Vec3d pos=obj->getJ2000EquatorialPos(nav); Vec3d pos=obj->getJ2000EquatorialPos(nav);
Vec3d screenpos; Vec3d screenpos;
// Compute 2D pos and return if outside screen // Compute 2D pos and return if outside screen
if (!prj->project(pos, screenpos)) if (!prj->project(pos, screenpos))
return; return;
StelPainter sPainter(prj); StelPainter sPainter(prj);
glColor3f(1.0f,0.3f,0.3f); sPainter.setColor(1.0f,0.3f,0.3f);
float size = obj->getAngularSize(core)*M_PI/180.*prj->getPix elPerRadAtCenter()*2.; float size = obj->getAngularSize(core)*M_PI/180.*prj->getPix elPerRadAtCenter()*2.;
size+=26.f + 10.f*std::sin(2.f * StelApp::getInstance().getT otalRunTime()); size+=40.f + 10.f*std::sin(2.f * StelApp::getInstance().getT otalRunTime());
texPointer->bind(); texPointer->bind();
glEnable(GL_TEXTURE_2D); sPainter.enableTexture2d(true);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transp glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal
arency mode transparency mode
glPushMatrix(); size*=0.5;
glTranslatef(screenpos[0], screenpos[1], 0.0f); const float angleBase = StelApp::getInstance().getTotalRunTi
glRotatef(StelApp::getInstance().getTotalRunTime()*10.,0,0,-1); me() * 10;
// We draw 4 instances of the sprite at the corners of the p
glTranslatef(-size/2, -size/2,0.0f); ointer
glRotatef(90,0,0,1); for (int i = 0; i < 4; ++i)
glBegin(GL_QUADS ); {
glTexCoord2f(0.0f,0.0f); glVertex3f(-10,-10,0); //Bas G const float angle = angleBase + i * 90;
auche const double x = screenpos[0] + size * cos(angle / 1
glTexCoord2f(1.0f,0.0f); glVertex3f(10,-10,0); //Bas D 80 * M_PI);
roite const double y = screenpos[1] + size * sin(angle / 1
glTexCoord2f(1.0f,1.0f); glVertex3f(10,10,0); //Haut 80 * M_PI);
Droit sPainter.drawSprite2dMode(x, y, 10, angle);
glTexCoord2f(0.0f,1.0f); glVertex3f(-10,10,0); //Haut }
Gauche
glEnd ();
glRotatef(-90,0,0,1);
glTranslatef(0,size,0.0f);
glBegin(GL_QUADS );
glTexCoord2f(0.0f,0.0f); glVertex3f(-10,-10,0); //Bas G
auche
glTexCoord2f(1.0f,0.0f); glVertex3f(10,-10,0); //Bas D
roite
glTexCoord2f(1.0f,1.0f); glVertex3f(10,10,0); //Haut
Droit
glTexCoord2f(0.0f,1.0f); glVertex3f(-10,10,0); //Haut
Gauche
glEnd ();
glRotatef(-90,0,0,1);
glTranslatef(0, size,0.0f);
glBegin(GL_QUADS );
glTexCoord2f(0.0f,0.0f); glVertex3f(-10,-10,0); //Bas G
auche
glTexCoord2f(1.0f,0.0f); glVertex3f(10,-10,0); //Bas D
roite
glTexCoord2f(1.0f,1.0f); glVertex3f(10,10,0); //Haut
Droit
glTexCoord2f(0.0f,1.0f); glVertex3f(-10,10,0); //Haut
Gauche
glEnd ();
glRotatef(-90,0,0,1);
glTranslatef(0,size,0);
glBegin(GL_QUADS );
glTexCoord2f(0.0f,0.0f); glVertex3f(-10,-10,0); //Bas G
auche
glTexCoord2f(1.0f,0.0f); glVertex3f(10,-10,0); //Bas D
roite
glTexCoord2f(1.0f,1.0f); glVertex3f(10,10,0); //Haut
Droit
glTexCoord2f(0.0f,1.0f); glVertex3f(-10,10,0); //Haut
Gauche
glEnd ();
glPopMatrix();
} }
} }
void ellipticalOrbitPosFunc(double jd,double xyz[3], void* userDataPtr)
{
static_cast<EllipticalOrbit*>(userDataPtr)->positionAtTimevInVSOP87C
oordinates(jd, xyz);
}
void cometOrbitPosFunc(double jd,double xyz[3], void* userDataPtr)
{
static_cast<CometOrbit*>(userDataPtr)->positionAtTimevInVSOP87Coordi
nates(jd, xyz);
}
// Init and load the solar system data // Init and load the solar system data
void SolarSystem::loadPlanets() void SolarSystem::loadPlanets()
{ {
qDebug() << "Loading Solar System data ..."; qDebug() << "Loading Solar System data ...";
QString iniFile; QString iniFile;
try try
{ {
iniFile = StelApp::getInstance().getFileMgr().findFile("data /ssystem.ini"); iniFile = StelFileMgr::findFile("data/ssystem.ini");
} }
catch(std::runtime_error& e) catch(std::runtime_error& e)
{ {
qWarning() << "ERROR while loading ssysyem.ini (unable to fi nd data/ssystem.ini): " << e.what() << endl; qWarning() << "ERROR while loading ssysyem.ini (unable to fi nd data/ssystem.ini): " << e.what() << endl;
return; return;
} }
QSettings pd(iniFile, StelIniFormat); QSettings pd(iniFile, StelIniFormat);
if (pd.status() != QSettings::NoError) if (pd.status() != QSettings::NoError)
{ {
qWarning() << "ERROR while parsing ssysyem.ini file"; qWarning() << "ERROR while parsing ssysyem.ini file";
skipping to change at line 304 skipping to change at line 273
// Stage 3 (as described above). // Stage 3 (as described above).
int readOk=0; int readOk=0;
int totalPlanets=0; int totalPlanets=0;
for (int i = 0;i<orderedSections.size();++i) for (int i = 0;i<orderedSections.size();++i)
{ {
totalPlanets++; totalPlanets++;
const QString secname = orderedSections.at(i); const QString secname = orderedSections.at(i);
const QString englishName = pd.value(secname+"/name").toStri ng(); const QString englishName = pd.value(secname+"/name").toStri ng();
const QString strParent = pd.value(secname+"/parent").toStri ng(); const QString strParent = pd.value(secname+"/parent").toStri ng();
Planet *parent = NULL; PlanetP parent;
if (strParent!="none") if (strParent!="none")
{ {
// Look in the other planets the one named with strP arent // Look in the other planets the one named with strP arent
vector<Planet*>::iterator iter = systemPlanets.begin foreach (const PlanetP& p, systemPlanets)
();
while (iter != systemPlanets.end())
{ {
if ((*iter)->getEnglishName()==strParent) if (p->getEnglishName()==strParent)
{ {
parent = (*iter); parent = p;
break;
} }
iter++;
} }
if (parent == NULL) if (parent.isNull())
{ {
qWarning() << "ERROR : can't find parent sol ar system body for " << englishName; qWarning() << "ERROR : can't find parent sol ar system body for " << englishName;
abort(); abort();
continue; continue;
} }
} }
const QString funcName = pd.value(secname+"/coord_func").toS tring(); const QString funcName = pd.value(secname+"/coord_func").toS tring();
posFuncType posfunc; posFuncType posfunc=NULL;
void* userDataPtr=NULL;
OsulatingFunctType *osculatingFunc = 0; OsulatingFunctType *osculatingFunc = 0;
bool closeOrbit = pd.value(secname+"/closeOrbit", true).toBo ol(); bool closeOrbit = pd.value(secname+"/closeOrbit", true).toBo ol();
if (funcName=="ell_orbit") if (funcName=="ell_orbit")
{ {
// Read the orbital elements // Read the orbital elements
const double epoch = pd.value(secname+"/orbit_Epoch" ,J2000).toDouble(); const double epoch = pd.value(secname+"/orbit_Epoch" ,J2000).toDouble();
const double eccentricity = pd.value(secname+"/orbit _Eccentricity").toDouble(); const double eccentricity = pd.value(secname+"/orbit _Eccentricity").toDouble();
if (eccentricity >= 1.0) closeOrbit = false; if (eccentricity >= 1.0) closeOrbit = false;
double pericenterDistance = pd.value(secname+"/orbit _PericenterDistance",-1e100).toDouble(); double pericenterDistance = pd.value(secname+"/orbit _PericenterDistance",-1e100).toDouble();
skipping to change at line 352 skipping to change at line 321
<< ": you must provide orbit _PericenterDistance or orbit_SemiMajorAxis"; << ": you must provide orbit _PericenterDistance or orbit_SemiMajorAxis";
abort(); abort();
} else { } else {
semi_major_axis /= AU; semi_major_axis /= AU;
Q_ASSERT(eccentricity != 1.0); // pa rabolic orbits have no semi_major_axis Q_ASSERT(eccentricity != 1.0); // pa rabolic orbits have no semi_major_axis
pericenterDistance = semi_major_axis * (1.0-eccentricity); pericenterDistance = semi_major_axis * (1.0-eccentricity);
} }
} else { } else {
pericenterDistance /= AU; pericenterDistance /= AU;
semi_major_axis = (eccentricity == 1.0) semi_major_axis = (eccentricity == 1.0)
? 0.0 // parabolic orbits ha ? 0.0 // par
ve no semi_major_axis abolic orbits have no semi_major_axis
: pericenterDistance / (1.0- : pericenter
eccentricity); Distance / (1.0-eccentricity);
} }
double meanMotion = pd.value(secname+"/orbit_MeanMot ion",-1e100).toDouble(); double meanMotion = pd.value(secname+"/orbit_MeanMot ion",-1e100).toDouble();
double period; double period;
if (meanMotion <= -1e100) { if (meanMotion <= -1e100) {
period = pd.value(secname+"/orbit_Period",-1 e100).toDouble(); period = pd.value(secname+"/orbit_Period",-1 e100).toDouble();
if (period <= -1e100) { if (period <= -1e100) {
meanMotion = (eccentricity == 1.0) meanMotion = (eccentricity == 1.0)
? 0.01720209895 * (1.5/p ? 0.01720209
ericenterDistance) 895 * (1.5/pericenterDistance)
* sqrt(0
.5/pericenterDistance) * sqrt(0.5/pericenterDistance)
: (semi_major_axis > 0.0 : (semi_majo
) r_axis > 0.0)
? 0.01720209895 / (semi_ ? 0.01720209
major_axis*sqrt(semi_major_axis)) 895 / (semi_major_axis*sqrt(semi_major_axis))
: 0.01720209895 / (-semi : 0.01720209
_major_axis*sqrt(-semi_major_axis)); 895 / (-semi_major_axis*sqrt(-semi_major_axis));
period = 2.0*M_PI/meanMotion; period = 2.0*M_PI/meanMotion;
} else { } else {
meanMotion = 2.0*M_PI/period; meanMotion = 2.0*M_PI/period;
} }
} else { } else {
period = 2.0*M_PI/meanMotion; period = 2.0*M_PI/meanMotion;
} }
const double inclination = pd.value(secname+"/orbit_ Inclination").toDouble()*(M_PI/180.0); const double inclination = pd.value(secname+"/orbit_ Inclination").toDouble()*(M_PI/180.0);
const double ascending_node = pd.value(secname+"/orb it_AscendingNode").toDouble()*(M_PI/180.0); const double ascending_node = pd.value(secname+"/orb it_AscendingNode").toDouble()*(M_PI/180.0);
double arg_of_pericenter = pd.value(secname+"/orbit_ ArgOfPericenter",-1e100).toDouble(); double arg_of_pericenter = pd.value(secname+"/orbit_ ArgOfPericenter",-1e100).toDouble();
skipping to change at line 396 skipping to change at line 365
if (mean_anomaly <= -1e100) { if (mean_anomaly <= -1e100) {
mean_longitude = pd.value(secname+"/orbit_Me anLongitude").toDouble()*(M_PI/180.0); mean_longitude = pd.value(secname+"/orbit_Me anLongitude").toDouble()*(M_PI/180.0);
mean_anomaly = mean_longitude - long_of_peri center; mean_anomaly = mean_longitude - long_of_peri center;
} else { } else {
mean_anomaly *= (M_PI/180.0); mean_anomaly *= (M_PI/180.0);
mean_longitude = mean_anomaly + long_of_peri center; mean_longitude = mean_anomaly + long_of_peri center;
} }
// when the parent is the sun use ecliptic rathe tha n sun equator: // when the parent is the sun use ecliptic rathe tha n sun equator:
const double parentRotObliquity = parent->getParent( ) const double parentRotObliquity = parent->getParent( )
? parent->getRotOb
liquity() ? parent->getRotObliquity()
: 0.0;
: 0.0;
const double parent_rot_asc_node = parent->getParent () const double parent_rot_asc_node = parent->getParent ()
? parent->getRotAs
cendingnode() ? parent->getRotAscendingnode()
: 0.0;
: 0.0;
double parent_rot_j2000_longitude = 0.0; double parent_rot_j2000_longitude = 0.0;
if (parent->getParent()) { if (parent->getParent()) {
const double c_obl = cos(parentRotObliquity) ; const double c_obl = cos(parentRotObliquity) ;
const double s_obl = sin(parentRotObliquity) ; const double s_obl = sin(parentRotObliquity) ;
const double c_nod = cos(parent_rot_asc_node ); const double c_nod = cos(parent_rot_asc_node );
const double s_nod = sin(parent_rot_asc_node ); const double s_nod = sin(parent_rot_asc_node );
const Vec3d OrbitAxis0( c_nod, s_nod, 0.0); const Vec3d OrbitAxis0( c_nod, s_nod, 0.0);
const Vec3d OrbitAxis1(-s_nod*c_obl, c_nod*c _obl,s_obl); const Vec3d OrbitAxis1(-s_nod*c_obl, c_nod*c _obl,s_obl);
const Vec3d OrbitPole( s_nod*s_obl,-c_nod*s _obl,c_obl); const Vec3d OrbitPole( s_nod*s_obl,-c_nod*s _obl,c_obl);
const Vec3d J2000Pole(StelNavigator::matJ200 0ToVsop87.multiplyWithoutTranslation(Vec3d(0,0,1))); const Vec3d J2000Pole(StelNavigator::matJ200 0ToVsop87.multiplyWithoutTranslation(Vec3d(0,0,1)));
Vec3d J2000NodeOrigin(J2000Pole^OrbitPole); Vec3d J2000NodeOrigin(J2000Pole^OrbitPole);
J2000NodeOrigin.normalize(); J2000NodeOrigin.normalize();
parent_rot_j2000_longitude = atan2(J2000Node Origin*OrbitAxis1,J2000NodeOrigin*OrbitAxis0); parent_rot_j2000_longitude = atan2(J2000Node Origin*OrbitAxis1,J2000NodeOrigin*OrbitAxis0);
} }
// Create an elliptical orbit // Create an elliptical orbit
EllipticalOrbit *orb = new EllipticalOrbit(pericente rDistance, EllipticalOrbit *orb = new EllipticalOrbit(pericente rDistance,
eccentric
ity, eccentricity,
inclinati
on, inclination,
ascending
_node, ascending_node,
arg_of_pe
ricenter, arg_of_pericenter,
mean_anom
aly, mean_anomaly,
period,
epoch, period,
parentRot
Obliquity, epoch,
parent_ro
t_asc_node, parentRotObliquity,
parent_rot_asc_node,
parent_rot_j2000_longitude); parent_rot_j2000_longitude);
orbits.push_back(orb); orbits.push_back(orb);
posfunc = posFuncType(orb, &EllipticalOrbit::positio userDataPtr = orb;
nAtTimevInVSOP87Coordinates); posfunc = &ellipticalOrbitPosFunc;
} }
else if (funcName=="comet_orbit") else if (funcName=="comet_orbit")
{ {
// Read the orbital elements // Read the orbital elements
// orbit_PericenterDistance,orbit_SemiMajorAxis: giv en in AU // orbit_PericenterDistance,orbit_SemiMajorAxis: giv en in AU
// orbit_MeanMotion: given in degrees/day // orbit_MeanMotion: given in degrees/day
// orbit_Period: given in days // orbit_Period: given in days
// orbit_TimeAtPericenter,orbit_Epoch: JD // orbit_TimeAtPericenter,orbit_Epoch: JD
// orbit_MeanAnomaly,orbit_Inclination,orbit_ArgOfPe ricenter,orbit_AscendingNode: given in degrees // orbit_MeanAnomaly,orbit_Inclination,orbit_ArgOfPe ricenter,orbit_AscendingNode: given in degrees
const double eccentricity = pd.value(secname+"/orbit _Eccentricity",0.0).toDouble(); const double eccentricity = pd.value(secname+"/orbit _Eccentricity",0.0).toDouble();
skipping to change at line 456 skipping to change at line 426
if (semi_major_axis <= -1e100) { if (semi_major_axis <= -1e100) {
qWarning() << "ERROR: " << englishNa me qWarning() << "ERROR: " << englishNa me
<< ": you must provide orbit _PericenterDistance or orbit_SemiMajorAxis"; << ": you must provide orbit _PericenterDistance or orbit_SemiMajorAxis";
abort(); abort();
} else { } else {
Q_ASSERT(eccentricity != 1.0); // pa rabolic orbits have no semi_major_axis Q_ASSERT(eccentricity != 1.0); // pa rabolic orbits have no semi_major_axis
pericenterDistance = semi_major_axis * (1.0-eccentricity); pericenterDistance = semi_major_axis * (1.0-eccentricity);
} }
} else { } else {
semi_major_axis = (eccentricity == 1.0) semi_major_axis = (eccentricity == 1.0)
? 0.0 // parabolic orbits ha ? 0.0 // par
ve no semi_major_axis abolic orbits have no semi_major_axis
: pericenterDistance / (1.0- : pericenter
eccentricity); Distance / (1.0-eccentricity);
} }
double meanMotion = pd.value(secname+"/orbit_MeanMot ion",-1e100).toDouble(); double meanMotion = pd.value(secname+"/orbit_MeanMot ion",-1e100).toDouble();
if (meanMotion <= -1e100) { if (meanMotion <= -1e100) {
const double period = pd.value(secname+"/orb it_Period",-1e100).toDouble(); const double period = pd.value(secname+"/orb it_Period",-1e100).toDouble();
if (period <= -1e100) { if (period <= -1e100) {
if (parent->getParent()) { if (parent->getParent()) {
qWarning() << "ERROR: " << e nglishName qWarning() << "ERROR: " << e nglishName
<< ": when the paren t body is not the sun, you must provide " << ": when the paren t body is not the sun, you must provide "
<< "either orbit_Mea nMotion or orbit_Period"; << "either orbit_Mea nMotion or orbit_Period";
} else { } else {
// in case of parent=sun: us e Gaussian gravitational constant // in case of parent=sun: us e Gaussian gravitational constant
// for calculating meanMotio n: // for calculating meanMotio n:
meanMotion = (eccentricity = = 1.0) meanMotion = (eccentricity = = 1.0)
? 0.01720209895 ? 0.
* (1.5/pericenterDistance) 01720209895 * (1.5/pericenterDistance)
* sqrt(0.5/pericenterDistance) * sqrt(0.5/pericenterDistance)
: (semi_major_ax : (s
is > 0.0) emi_major_axis > 0.0)
? 0.01720209895 ? 0.
/ (semi_major_axis*sqrt(semi_major_axis)) 01720209895 / (semi_major_axis*sqrt(semi_major_axis))
: 0.01720209895 : 0.
/ (-semi_major_axis*sqrt(-semi_major_axis)); 01720209895 / (-semi_major_axis*sqrt(-semi_major_axis));
} }
} else { } else {
meanMotion = 2.0*M_PI/period; meanMotion = 2.0*M_PI/period;
} }
} else { } else {
meanMotion *= (M_PI/180.0); meanMotion *= (M_PI/180.0);
} }
double time_at_pericenter = pd.value(secname+"/orbit _TimeAtPericenter",-1e100).toDouble(); double time_at_pericenter = pd.value(secname+"/orbit _TimeAtPericenter",-1e100).toDouble();
if (time_at_pericenter <= -1e100) { if (time_at_pericenter <= -1e100) {
const double epoch = pd.value(secname+"/orbi t_Epoch",-1e100).toDouble(); const double epoch = pd.value(secname+"/orbi t_Epoch",-1e100).toDouble();
skipping to change at line 501 skipping to change at line 471
abort(); abort();
} else { } else {
mean_anomaly *= (M_PI/180.0); mean_anomaly *= (M_PI/180.0);
time_at_pericenter = epoch - mean_an omaly / meanMotion; time_at_pericenter = epoch - mean_an omaly / meanMotion;
} }
} }
const double inclination = pd.value(secname+"/orbit_ Inclination").toDouble()*(M_PI/180.0); const double inclination = pd.value(secname+"/orbit_ Inclination").toDouble()*(M_PI/180.0);
const double arg_of_pericenter = pd.value(secname+"/ orbit_ArgOfPericenter").toDouble()*(M_PI/180.0); const double arg_of_pericenter = pd.value(secname+"/ orbit_ArgOfPericenter").toDouble()*(M_PI/180.0);
const double ascending_node = pd.value(secname+"/orb it_AscendingNode").toDouble()*(M_PI/180.0); const double ascending_node = pd.value(secname+"/orb it_AscendingNode").toDouble()*(M_PI/180.0);
const double parentRotObliquity = parent->getParent( ) const double parentRotObliquity = parent->getParent( )
? parent->getRotOb
liquity() ? parent->getRotObliquity()
: 0.0;
: 0.0;
const double parent_rot_asc_node = parent->getParent () const double parent_rot_asc_node = parent->getParent ()
? parent->getRotAs
cendingnode() ? parent->getRotAscendingnode()
: 0.0;
: 0.0;
double parent_rot_j2000_longitude = 0.0; double parent_rot_j2000_longitude = 0.0;
if (parent->getParent()) { if (parent->getParent()) {
const double c_obl = cos(parentRotObliquity); const double c_obl = cos(
const double s_obl = sin(parentRotObliquity); parentRotObliquity);
const double c_nod = cos(parent_rot_asc_node); const double s_obl = sin(
const double s_nod = sin(parent_rot_asc_node); parentRotObliquity);
const Vec3d OrbitAxis0( c_nod, s_nod, const double c_nod = cos(
0.0); parent_rot_asc_node);
const Vec3d OrbitAxis1(-s_nod*c_obl, c_nod*c_obl const double s_nod = sin(
,s_obl); parent_rot_asc_node);
const Vec3d OrbitPole( s_nod*s_obl,-c_nod*s_obl const Vec3d OrbitAxis0( c
,c_obl); _nod, s_nod, 0.0);
const Vec3d OrbitAxis1(-s
_nod*c_obl, c_nod*c_obl,s_obl);
const Vec3d OrbitPole( s
_nod*s_obl,-c_nod*s_obl,c_obl);
const Vec3d J2000Pole(Ste lNavigator::matJ2000ToVsop87.multiplyWithoutTranslation(Vec3d(0,0,1))); const Vec3d J2000Pole(Ste lNavigator::matJ2000ToVsop87.multiplyWithoutTranslation(Vec3d(0,0,1)));
Vec3d J2000NodeOrigin(J2000Pole^OrbitPole); Vec3d J2000NodeOrigin(J20
J2000NodeOrigin.normalize(); 00Pole^OrbitPole);
parent_rot_j2000_longitude = atan2(J2000NodeOrig J2000NodeOrigin.normalize
in*OrbitAxis1,J2000NodeOrigin*OrbitAxis0); ();
} parent_rot_j2000_longitud
e = atan2(J2000NodeOrigin*OrbitAxis1,J2000NodeOrigin*OrbitAxis0);
}
CometOrbit *orb = new CometOrbit(pericenterDistance, CometOrbit *orb = new CometOrbit(pericenterDistance,
eccentricity,
inclination, eccentricity,
ascending_node,
arg_of_pericenter, inclination,
time_at_pericenter,
meanMotion, ascending_node,
parentRotObliquity,
parent_rot_asc_node arg_of_pericenter,
,
time_at_pericenter,
meanMotion,
parentRotObliquity,
parent_rot_asc_node,
parent_rot_j2000_longitude); parent_rot_j2000_longitude);
orbits.push_back(orb); orbits.push_back(orb);
userDataPtr = orb;
posfunc = posFuncType(orb,&CometOrbit::positionAtTim posfunc = &cometOrbitPosFunc;
evInVSOP87Coordinates);
} }
if (funcName=="sun_special") if (funcName=="sun_special")
posfunc = posFuncType(get_sun_helio_coordsv); posfunc = &get_sun_helio_coordsv;
if (funcName=="mercury_special") { if (funcName=="mercury_special") {
posfunc = posFuncType(get_mercury_helio_coordsv); posfunc = &get_mercury_helio_coordsv;
osculatingFunc = &get_mercury_helio_osculating_coord s; osculatingFunc = &get_mercury_helio_osculating_coord s;
} }
if (funcName=="venus_special") { if (funcName=="venus_special") {
posfunc = posFuncType(get_venus_helio_coordsv); posfunc = &get_venus_helio_coordsv;
osculatingFunc = &get_venus_helio_osculating_coords; osculatingFunc = &get_venus_helio_osculating_coords;
} }
if (funcName=="earth_special") { if (funcName=="earth_special") {
posfunc = posFuncType(get_earth_helio_coordsv); posfunc = &get_earth_helio_coordsv;
osculatingFunc = &get_earth_helio_osculating_coords; osculatingFunc = &get_earth_helio_osculating_coords;
} }
if (funcName=="lunar_special") if (funcName=="lunar_special")
posfunc = posFuncType(get_lunar_parent_coordsv); posfunc = &get_lunar_parent_coordsv;
if (funcName=="mars_special") { if (funcName=="mars_special") {
posfunc = posFuncType(get_mars_helio_coordsv); posfunc = &get_mars_helio_coordsv;
osculatingFunc = &get_mars_helio_osculating_coords; osculatingFunc = &get_mars_helio_osculating_coords;
} }
if (funcName=="phobos_special") if (funcName=="phobos_special")
posfunc = posFuncType(get_phobos_parent_coordsv); posfunc = posFuncType(get_phobos_parent_coordsv);
if (funcName=="deimos_special") if (funcName=="deimos_special")
posfunc = posFuncType(get_deimos_parent_coordsv); posfunc = &get_deimos_parent_coordsv;
if (funcName=="jupiter_special") { if (funcName=="jupiter_special") {
posfunc = posFuncType(get_jupiter_helio_coordsv); posfunc = &get_jupiter_helio_coordsv;
osculatingFunc = &get_jupiter_helio_osculating_coord s; osculatingFunc = &get_jupiter_helio_osculating_coord s;
} }
if (funcName=="europa_special") if (funcName=="europa_special")
posfunc = posFuncType(get_europa_parent_coordsv); posfunc = &get_europa_parent_coordsv;
if (funcName=="calisto_special") if (funcName=="calisto_special")
posfunc = posFuncType(get_callisto_parent_coordsv); posfunc = &get_callisto_parent_coordsv;
if (funcName=="io_special") if (funcName=="io_special")
posfunc = posFuncType(get_io_parent_coordsv); posfunc = &get_io_parent_coordsv;
if (funcName=="ganymede_special") if (funcName=="ganymede_special")
posfunc = posFuncType(get_ganymede_parent_coordsv); posfunc = &get_ganymede_parent_coordsv;
if (funcName=="saturn_special") { if (funcName=="saturn_special") {
posfunc = posFuncType(get_saturn_helio_coordsv); posfunc = &get_saturn_helio_coordsv;
osculatingFunc = &get_saturn_helio_osculating_coords ; osculatingFunc = &get_saturn_helio_osculating_coords ;
} }
if (funcName=="mimas_special") if (funcName=="mimas_special")
posfunc = posFuncType(get_mimas_parent_coordsv); posfunc = &get_mimas_parent_coordsv;
if (funcName=="enceladus_special") if (funcName=="enceladus_special")
posfunc = posFuncType(get_enceladus_parent_coordsv); posfunc = &get_enceladus_parent_coordsv;
if (funcName=="tethys_special") if (funcName=="tethys_special")
posfunc = posFuncType(get_tethys_parent_coordsv); posfunc = &get_tethys_parent_coordsv;
if (funcName=="dione_special") if (funcName=="dione_special")
posfunc = posFuncType(get_dione_parent_coordsv); posfunc = &get_dione_parent_coordsv;
if (funcName=="rhea_special") if (funcName=="rhea_special")
posfunc = posFuncType(get_rhea_parent_coordsv); posfunc = &get_rhea_parent_coordsv;
if (funcName=="titan_special") if (funcName=="titan_special")
posfunc = posFuncType(get_titan_parent_coordsv); posfunc = &get_titan_parent_coordsv;
if (funcName=="iapetus_special") if (funcName=="iapetus_special")
posfunc = posFuncType(get_iapetus_parent_coordsv); posfunc = &get_iapetus_parent_coordsv;
if (funcName=="hyperion_special") if (funcName=="hyperion_special")
posfunc = posFuncType(get_hyperion_parent_coordsv); posfunc = &get_hyperion_parent_coordsv;
if (funcName=="uranus_special") { if (funcName=="uranus_special") {
posfunc = posFuncType(get_uranus_helio_coordsv); posfunc = &get_uranus_helio_coordsv;
osculatingFunc = &get_uranus_helio_osculating_coords ; osculatingFunc = &get_uranus_helio_osculating_coords ;
} }
if (funcName=="miranda_special") if (funcName=="miranda_special")
posfunc = posFuncType(get_miranda_parent_coordsv); posfunc = &get_miranda_parent_coordsv;
if (funcName=="ariel_special") if (funcName=="ariel_special")
posfunc = posFuncType(get_ariel_parent_coordsv); posfunc = &get_ariel_parent_coordsv;
if (funcName=="umbriel_special") if (funcName=="umbriel_special")
posfunc = posFuncType(get_umbriel_parent_coordsv); posfunc = &get_umbriel_parent_coordsv;
if (funcName=="titania_special") if (funcName=="titania_special")
posfunc = posFuncType(get_titania_parent_coordsv); posfunc = &get_titania_parent_coordsv;
if (funcName=="oberon_special") if (funcName=="oberon_special")
posfunc = posFuncType(get_oberon_parent_coordsv); posfunc = &get_oberon_parent_coordsv;
if (funcName=="neptune_special") { if (funcName=="neptune_special") {
posfunc = posFuncType(get_neptune_helio_coordsv); posfunc = posFuncType(get_neptune_helio_coordsv);
osculatingFunc = &get_neptune_helio_osculating_coord s; osculatingFunc = &get_neptune_helio_osculating_coord s;
} }
if (funcName=="pluto_special") if (funcName=="pluto_special")
posfunc = posFuncType(get_pluto_helio_coordsv); posfunc = &get_pluto_helio_coordsv;
if (posfunc.empty()) if (posfunc==NULL)
{ {
qWarning() << "ERROR : can't find posfunc " << funcN ame << " for " << englishName; qWarning() << "ERROR : can't find posfunc " << funcN ame << " for " << englishName;
exit(-1); exit(-1);
} }
// Create the Planet and add it to the list // Create the Planet and add it to the list
Planet* p = new Planet(englishName, PlanetP p(new Planet(englishName,
pd.value(secname+"/lighting").toBool (), pd.value(secname+"/lighting").toBool (),
pd.value(secname+"/radius").toDouble ()/AU, pd.value(secname+"/radius").toDouble ()/AU,
pd.value(secname+"/oblateness", 0.0) .toDouble(), pd.value(secname+"/oblateness", 0.0) .toDouble(),
StelUtils::strToVec3f(pd.value(secna me+"/color").toString()), StelUtils::strToVec3f(pd.value(secna me+"/color").toString()),
pd.value(secname+"/albedo").toDouble (), pd.value(secname+"/albedo").toDouble (),
pd.value(secname+"/tex_map").toStrin g(), pd.value(secname+"/tex_map").toStrin g(),
pd.value(secname+"/tex_halo").toStri ng(), pd.value(secname+"/tex_halo").toStri ng(),
posfunc, posfunc,
userDataPtr,
osculatingFunc, osculatingFunc,
closeOrbit, closeOrbit,
pd.value(secname+"/hidden", 0).toBoo l(), pd.value(secname+"/hidden", 0).toBoo l(),
pd.value(secname+"/atmosphere", fals pd.value(secname+"/atmosphere", fals
e).toBool()); e).toBool()));
if (parent!=NULL) if (!parent.isNull())
p->setParent(parent); {
parent->satellites.append(p);
p->parent = parent;
}
if (secname=="earth") earth = p; if (secname=="earth") earth = p;
if (secname=="sun") sun = p; if (secname=="sun") sun = p;
if (secname=="moon") moon = p; if (secname=="moon") moon = p;
double rotObliquity = pd.value(secname+"/rot_obliquity",0.). toDouble()*(M_PI/180.0); double rotObliquity = pd.value(secname+"/rot_obliquity",0.). toDouble()*(M_PI/180.0);
double rotAscNode = pd.value(secname+"/rot_equator_ascending _node",0.).toDouble()*(M_PI/180.0); double rotAscNode = pd.value(secname+"/rot_equator_ascending _node",0.).toDouble()*(M_PI/180.0);
// Use more common planet North pole data if available // Use more common planet North pole data if available
// NB: N pole as defined by IAU (NOT right hand rotation rul e) // NB: N pole as defined by IAU (NOT right hand rotation rul e)
// NB: J2000 epoch // NB: J2000 epoch
skipping to change at line 694 skipping to change at line 668
StelUtils::rectToSphe(&ra, &de, vsop87Pole); StelUtils::rectToSphe(&ra, &de, vsop87Pole);
rotObliquity = (M_PI_2 - de); rotObliquity = (M_PI_2 - de);
rotAscNode = (ra + M_PI_2); rotAscNode = (ra + M_PI_2);
// qDebug() << "\tCalculated rotational obliquity: " << rotObliquity*180./M_PI << endl; // qDebug() << "\tCalculated rotational obliquity: " << rotObliquity*180./M_PI << endl;
// qDebug() << "\tCalculated rotational ascending no de: " << rotAscNode*180./M_PI << endl; // qDebug() << "\tCalculated rotational ascending no de: " << rotAscNode*180./M_PI << endl;
} }
p->setRotationElements( p->setRotationElements(
pd.value(secname+"/rot_periode", pd.value(secname+"/orbi pd.value(secname+"/rot_periode", pd.value(secname+"/
t_Period", 24.).toDouble()).toDouble()/24., orbit_Period", 24.).toDouble()).toDouble()/24.,
pd.value(secname+"/rot_rotation_offset",0.).toDouble(), pd.value(secname+"/rot_rotation_offset",0.).toDouble
pd.value(secname+"/rot_epoch", J2000).toDouble(), (),
rotObliquity, pd.value(secname+"/rot_epoch", J2000).toDouble(),
rotAscNode, rotObliquity,
pd.value(secname+"/rot_precession_rate",0.).toDouble()*M rotAscNode,
_PI/(180*36525), pd.value(secname+"/rot_precession_rate",0.).toDouble
pd.value(secname+"/orbit_visualization_period",0.).toDou ()*M_PI/(180*36525),
ble()); pd.value(secname+"/orbit_visualization_period",0.).t
oDouble());
if (pd.value(secname+"/rings", 0).toBool()) { if (pd.value(secname+"/rings", 0).toBool()) {
const double rMin = pd.value(secname+"/ring_inner_si ze").toDouble()/AU; const double rMin = pd.value(secname+"/ring_inner_si ze").toDouble()/AU;
const double rMax = pd.value(secname+"/ring_outer_si ze").toDouble()/AU; const double rMax = pd.value(secname+"/ring_outer_si ze").toDouble()/AU;
Ring *r = new Ring(rMin,rMax,pd.value(secname+"/tex_ ring").toString()); Ring *r = new Ring(rMin,rMax,pd.value(secname+"/tex_ ring").toString());
p->setRings(r); p->setRings(r);
} }
systemPlanets.push_back(p); systemPlanets.push_back(p);
readOk++; readOk++;
} }
// special case: load earth shadow texture // special case: load earth shadow texture
StelApp::getInstance().getTextureManager().setDefaultParams();
Planet::texEarthShadow = StelApp::getInstance().getTextureManager(). createTexture("earth-shadow.png"); Planet::texEarthShadow = StelApp::getInstance().getTextureManager(). createTexture("earth-shadow.png");
qDebug() << "Loaded" << readOk << "/" << totalPlanets << "planet orb its"; qDebug() << "Loaded" << readOk << "/" << totalPlanets << "planet orb its";
} }
// Compute the position for every elements of the solar system. // Compute the position for every elements of the solar system.
// The order is not important since the position is computed relatively to the mother body // The order is not important since the position is computed relatively to the mother body
void SolarSystem::computePositions(double date, const Vec3d& observerPos) void SolarSystem::computePositions(double date, const Vec3d& observerPos)
{ {
if (flagLightTravelTime) if (flagLightTravelTime)
{ {
for (std::vector<Planet*>::const_iterator iter(systemPlanets .begin());iter!=systemPlanets.end();iter++) foreach (PlanetP p, systemPlanets)
{ {
(*iter)->computePositionWithoutOrbits(date); p->computePositionWithoutOrbits(date);
} }
for (std::vector<Planet*>::const_iterator iter(systemPlanets .begin());iter!=systemPlanets.end();iter++) foreach (PlanetP p, systemPlanets)
{ {
const double light_speed_correction = ((*iter)->getH const double light_speed_correction = (p->getHelioce
eliocentricEclipticPos()-observerPos).length() * (AU / (SPEED_OF_LIGHT * 86 ntricEclipticPos()-observerPos).length() * (AU / (SPEED_OF_LIGHT * 86400));
400)); p->computePosition(date-light_speed_correction);
(*iter)->computePosition(date-light_speed_correction
);
} }
} }
else else
{ {
for (std::vector<Planet*>::const_iterator iter(systemPlanets .begin());iter!=systemPlanets.end();iter++) foreach (PlanetP p, systemPlanets)
{ {
(*iter)->computePosition(date); p->computePosition(date);
} }
} }
computeTransMatrices(date, observerPos); computeTransMatrices(date, observerPos);
} }
// Compute the transformation matrix for every elements of the solar system . // Compute the transformation matrix for every elements of the solar system .
// The elements have to be ordered hierarchically, eg. it's important to co mpute earth before moon. // The elements have to be ordered hierarchically, eg. it's important to co mpute earth before moon.
void SolarSystem::computeTransMatrices(double date, const Vec3d& observerPo s) void SolarSystem::computeTransMatrices(double date, const Vec3d& observerPo s)
{ {
if (flagLightTravelTime) if (flagLightTravelTime)
{ {
for (std::vector<Planet*>::const_iterator iter(systemPlanets .begin());iter!=systemPlanets.end();iter++) foreach (PlanetP p, systemPlanets)
{ {
const double light_speed_correction = ((*iter)->getH const double light_speed_correction = (p->getHelioce
eliocentricEclipticPos()-observerPos).length() * (AU / (SPEED_OF_LIGHT * 86 ntricEclipticPos()-observerPos).length() * (AU / (SPEED_OF_LIGHT * 86400));
400)); p->computeTransMatrix(date-light_speed_correction);
(*iter)->computeTransMatrix(date-light_speed_correct
ion);
} }
} }
else else
{ {
for (std::vector<Planet*>::const_iterator iter(systemPlanets .begin());iter!=systemPlanets.end();iter++) foreach (PlanetP p, systemPlanets)
{ {
(*iter)->computeTransMatrix(date); p->computeTransMatrix(date);
} }
} }
} }
// And sort them from the furthest to the closest to the observer
struct biggerDistance : public std::binary_function<PlanetP, PlanetP, bool>
{
bool operator()(PlanetP p1, PlanetP p2)
{
return p1->getDistance() > p2->getDistance();
}
};
// Draw all the elements of the solar system // Draw all the elements of the solar system
// We are supposed to be in heliocentric coordinate // We are supposed to be in heliocentric coordinate
void SolarSystem::draw(StelCore* core) void SolarSystem::draw(StelCore* core)
{ {
if (!flagShow) if (!flagShow)
return; return;
StelNavigator* nav = core->getNavigator(); StelNavigator* nav = core->getNavigator();
Planet::setFont(&planetNameFont);
// Compute each Planet distance to the observer // Compute each Planet distance to the observer
Vec3d obsHelioPos = nav->getObserverHeliocentricEclipticPos(); Vec3d obsHelioPos = nav->getObserverHeliocentricEclipticPos();
vector<Planet*>::iterator iter; foreach (PlanetP p, systemPlanets)
iter = systemPlanets.begin();
while (iter != systemPlanets.end())
{ {
(*iter)->computeDistance(obsHelioPos); p->computeDistance(obsHelioPos);
++iter;
} }
// And sort them from the furthest to the closest // And sort them from the furthest to the closest
sort(systemPlanets.begin(),systemPlanets.end(),biggerDistance()); sort(systemPlanets.begin(),systemPlanets.end(),biggerDistance());
// Draw the elements // Draw the elements
float maxMagLabel=core->getSkyDrawer()->getLimitMagnitude()*0.80+(la belsAmount*1.2f)-2.f; float maxMagLabel=core->getSkyDrawer()->getLimitMagnitude()*0.80+(la belsAmount*1.2f)-2.f;
iter = systemPlanets.begin(); foreach (const PlanetP& p, systemPlanets)
while (iter != systemPlanets.end())
{ {
(*iter)->draw(core, maxMagLabel); p->draw(core, maxMagLabel, planetNameFont);
++iter;
} }
if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer()) if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
drawPointer(core); drawPointer(core);
} }
void SolarSystem::setStelStyle(const StelStyle& style) void SolarSystem::setStelStyle(const StelStyle& style)
{ {
// Load colors from config file // Load colors from config file
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
QString section = style.confSectionName; QString section = style.confSectionName;
QString defaultColor = conf->value(section+"/default_color").toStrin g(); QString defaultColor = conf->value(section+"/default_color").toStrin g();
setLabelsColor(StelUtils::strToVec3f(conf->value(section+"/planet_na mes_color", defaultColor).toString())); setLabelsColor(StelUtils::strToVec3f(conf->value(section+"/planet_na mes_color", defaultColor).toString()));
setOrbitsColor(StelUtils::strToVec3f(conf->value(section+"/planet_or bits_color", defaultColor).toString())); setOrbitsColor(StelUtils::strToVec3f(conf->value(section+"/planet_or bits_color", defaultColor).toString()));
setTrailsColor(StelUtils::strToVec3f(conf->value(section+"/object_tr ails_color", defaultColor).toString())); setTrailsColor(StelUtils::strToVec3f(conf->value(section+"/object_tr ails_color", defaultColor).toString()));
} }
Planet* SolarSystem::searchByEnglishName(QString planetEnglishName) const PlanetP SolarSystem::searchByEnglishName(QString planetEnglishName) const
{ {
vector<Planet*>::const_iterator iter = systemPlanets.begin(); foreach (const PlanetP& p, systemPlanets)
while (iter != systemPlanets.end())
{ {
if((*iter)->getEnglishName() == planetEnglishName) return (* if (p->getEnglishName() == planetEnglishName)
iter); // also check standard ini file names return p;
++iter;
} }
return PlanetP();
return NULL;
} }
StelObjectP SolarSystem::searchByNameI18n(const QString& planetNameI18) con st StelObjectP SolarSystem::searchByNameI18n(const QString& planetNameI18) con st
{ {
vector<Planet*>::const_iterator iter = systemPlanets.begin(); foreach (const PlanetP& p, systemPlanets)
while (iter != systemPlanets.end())
{ {
if( (*iter)->getNameI18n() == planetNameI18 ) return (*iter) if (p->getNameI18n() == planetNameI18)
; // also check standard ini file names return qSharedPointerCast<StelObject>(p);
++iter;
} }
return NULL; return StelObjectP();
} }
StelObjectP SolarSystem::searchByName(const QString& name) const StelObjectP SolarSystem::searchByName(const QString& name) const
{ {
vector<Planet*>::const_iterator iter = systemPlanets.begin(); foreach (const PlanetP& p, systemPlanets)
while (iter != systemPlanets.end())
{ {
if( (*iter)->getEnglishName() == name ) return (*iter); if (p->getEnglishName() == name)
++iter; return qSharedPointerCast<StelObject>(p);
} }
return NULL; return StelObjectP();
} }
// Search if any Planet is close to position given in earth equatorial posi tion and return the distance // Search if any Planet is close to position given in earth equatorial posi tion and return the distance
StelObject* SolarSystem::search(Vec3d pos, const StelCore* core) const StelObjectP SolarSystem::search(Vec3d pos, const StelCore* core) const
{ {
pos.normalize(); pos.normalize();
Planet * closest = NULL; PlanetP closest;
double cos_angle_closest = 0.; double cos_angle_closest = 0.;
Vec3d equPos; Vec3d equPos;
vector<Planet*>::const_iterator iter = systemPlanets.begin(); foreach (const PlanetP& p, systemPlanets)
while (iter != systemPlanets.end())
{ {
equPos = (*iter)->getEquinoxEquatorialPos(core->getNavigator ()); equPos = p->getEquinoxEquatorialPos(core->getNavigator());
equPos.normalize(); equPos.normalize();
double cos_ang_dist = equPos[0]*pos[0] + equPos[1]*pos[1] + equPos[2]*pos[2]; double cos_ang_dist = equPos*pos;
if (cos_ang_dist>cos_angle_closest) if (cos_ang_dist>cos_angle_closest)
{ {
closest = *iter; closest = p;
cos_angle_closest = cos_ang_dist; cos_angle_closest = cos_ang_dist;
} }
iter++;
} }
if (cos_angle_closest>0.999) if (cos_angle_closest>0.999)
{ {
return closest; return qSharedPointerCast<StelObject>(closest);
} }
else return NULL; else return StelObjectP();
} }
// Return a stl vector containing the planets located inside the limFov cir cle around position v // Return a stl vector containing the planets located inside the limFov cir cle around position v
QList<StelObjectP> SolarSystem::searchAround(const Vec3d& vv, double limitF ov, const StelCore* core) const QList<StelObjectP> SolarSystem::searchAround(const Vec3d& vv, double limitF ov, const StelCore* core) const
{ {
QList<StelObjectP> result; QList<StelObjectP> result;
if (!getFlagPlanets()) if (!getFlagPlanets())
return result; return result;
Vec3d v = core->getNavigator()->j2000ToEquinoxEqu(vv); Vec3d v = core->getNavigator()->j2000ToEquinoxEqu(vv);
v.normalize(); v.normalize();
double cosLimFov = cos(limitFov * M_PI/180.); double cosLimFov = std::cos(limitFov * M_PI/180.);
Vec3d equPos; Vec3d equPos;
vector<Planet*>::const_iterator iter = systemPlanets.begin(); foreach (const PlanetP& p, systemPlanets)
while (iter != systemPlanets.end())
{ {
equPos = (*iter)->getEquinoxEquatorialPos(core->getNavigator ()); equPos = p->getEquinoxEquatorialPos(core->getNavigator());
equPos.normalize(); equPos.normalize();
if (equPos[0]*v[0] + equPos[1]*v[1] + equPos[2]*v[2]>=cosLim Fov) if (equPos*v>=cosLimFov)
{ {
result.push_back(*iter); result.append(qSharedPointerCast<StelObject>(p));
} }
iter++;
} }
return result; return result;
} }
// Update i18 names from english names according to passed translator // Update i18 names from english names according to passed translator
void SolarSystem::updateI18n() void SolarSystem::updateI18n()
{ {
StelTranslator& trans = StelApp::getInstance().getLocaleMgr().getSky Translator(); StelTranslator& trans = StelApp::getInstance().getLocaleMgr().getSky Translator();
vector<Planet*>::iterator iter; foreach (PlanetP p, systemPlanets)
for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter+ p->translateName(trans);
+ )
{
(*iter)->translateName(trans);
}
planetNameFont = StelApp::getInstance().getFontManager().getStandard
Font(trans.getTrueLocaleName(), fontSize);
} }
QString SolarSystem::getPlanetHashString(void) QString SolarSystem::getPlanetHashString(void)
{ {
QString str; QString str;
QTextStream oss(&str); QTextStream oss(&str);
foreach (const PlanetP& p, systemPlanets)
vector <Planet *>::iterator iter;
for (iter = systemPlanets.begin(); iter != systemPlanets.end(); ++it
er)
{ {
if((*iter)->getParent() != NULL && (*iter)->getParent()->get EnglishName() != "Sun") if (!p->getParent().isNull() && p->getParent()->getEnglishNa me() != "Sun")
{ {
oss << (*iter)->getParent()->getEnglishName() << " : "; oss << p->getParent()->getEnglishName() << " : ";
} }
oss << p->getEnglishName() << endl;
oss << (*iter)->getEnglishName() << endl; oss << p->getEnglishName() << endl;
oss << (*iter)->getEnglishName() << endl;
} }
return str; return str;
} }
void SolarSystem::startTrails(bool b) void SolarSystem::startTrails(bool b)
{ {
vector<Planet*>::iterator iter; foreach (PlanetP p, systemPlanets)
for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter+ p->startTrail(b);
+ )
{
(*iter)->startTrail(b);
}
} }
void SolarSystem::setFlagTrails(bool b) void SolarSystem::setFlagTrails(bool b)
{ {
vector<Planet*>::iterator iter; foreach (PlanetP p, systemPlanets)
for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter+ p->setFlagTrail(b);
+ )
{
(*iter)->setFlagTrail(b);
}
} }
bool SolarSystem::getFlagTrails(void) const bool SolarSystem::getFlagTrails(void) const
{ {
for (std::vector<Planet*>::const_iterator iter = systemPlanets.begin foreach (const PlanetP& p, systemPlanets)
(); {
iter != systemPlanets.end(); iter++ ) { if (p->getFlagTrail())
if ((*iter)->getFlagTrail()) return true; return true;
} }
return false; return false;
} }
void SolarSystem::setFlagHints(bool b) void SolarSystem::setFlagHints(bool b)
{ {
vector<Planet*>::iterator iter; foreach (PlanetP p, systemPlanets)
for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter+ p->setFlagHints(b);
+ )
{
(*iter)->setFlagHints(b);
}
} }
bool SolarSystem::getFlagHints(void) const bool SolarSystem::getFlagHints(void) const
{ {
for (std::vector<Planet*>::const_iterator iter = systemPlanets.begin (); iter != systemPlanets.end(); iter++) foreach (const PlanetP& p, systemPlanets)
{ {
if ((*iter)->getFlagHints()) return true; if (p->getFlagHints())
return true;
} }
return false; return false;
} }
void SolarSystem::setFlagLabels(bool b) void SolarSystem::setFlagLabels(bool b)
{ {
vector<Planet*>::iterator iter; foreach (PlanetP p, systemPlanets)
for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter+ p->setFlagLabels(b);
+ )
{
(*iter)->setFlagLabels(b);
}
} }
bool SolarSystem::getFlagLabels() const bool SolarSystem::getFlagLabels() const
{ {
for (std::vector<Planet*>::const_iterator iter = systemPlanets.begin (); iter != systemPlanets.end(); iter++) foreach (const PlanetP& p, systemPlanets)
{ {
if ((*iter)->getFlagLabels()) return true; if (p->getFlagLabels())
return true;
} }
return false; return false;
} }
void SolarSystem::setFlagOrbits(bool b) void SolarSystem::setFlagOrbits(bool b)
{ {
flagOrbits = b; flagOrbits = b;
if (!b || !selected || selected == sun) if (!b || !selected || selected==sun)
{ {
vector<Planet*>::iterator iter; foreach (PlanetP p, systemPlanets)
for( iter = systemPlanets.begin(); iter < systemPlanets.end( p->setFlagOrbits(b);
); iter++ )
{
(*iter)->setFlagOrbits(b);
}
} }
else else
{ {
// if a Planet is selected and orbits are on, // If a Planet is selected and orbits are on, fade out non-s
// fade out non-selected ones elected ones
vector<Planet*>::iterator iter; foreach (PlanetP p, systemPlanets)
for (iter = systemPlanets.begin();
iter != systemPlanets.end(); iter++ )
{ {
if (selected == (*iter)) (*iter)->setFlagOrbits(b); if (selected == p)
else (*iter)->setFlagOrbits(false); p->setFlagOrbits(b);
else
p->setFlagOrbits(false);
} }
} }
} }
void SolarSystem::setFlagLightTravelTime(bool b) void SolarSystem::setFlagLightTravelTime(bool b)
{ {
flagLightTravelTime = b; flagLightTravelTime = b;
} }
void SolarSystem::setSelected(StelObject* obj) void SolarSystem::setSelected(PlanetP obj)
{ {
if (obj && obj->getType() == "Planet") if (obj && obj->getType() == "Planet")
selected = obj; selected = obj;
else else
selected = NULL; selected.clear();;
// Undraw other objects hints, orbit, trails etc.. // Undraw other objects hints, orbit, trails etc..
setFlagHints(getFlagHints()); setFlagHints(getFlagHints());
setFlagOrbits(getFlagOrbits()); setFlagOrbits(getFlagOrbits());
setFlagTrails(getFlagTrails()); setFlagTrails(getFlagTrails());
} }
void SolarSystem::update(double deltaTime) void SolarSystem::update(double deltaTime)
{ {
bool restartTrails = false; bool restartTrails = false;
StelNavigator* nav = StelApp::getInstance().getCore()->getNavigator( ); StelNavigator* nav = StelApp::getInstance().getCore()->getNavigator( );
// Determine if home planet has changed, and restart planet trails // Determine if home planet has changed, and restart planet trails
// since the data is no longer useful // since the data is no longer useful
if (nav->getHomePlanet() != lastHomePlanet) if (lastHomePlanet && nav->getCurrentLocation().planetName != lastHo mePlanet->getEnglishName())
{ {
lastHomePlanet = nav->getHomePlanet(); lastHomePlanet = searchByEnglishName(nav->getCurrentLocation
().planetName);
Q_ASSERT(!lastHomePlanet.isNull());
restartTrails = true; restartTrails = true;
} }
vector<Planet*>::iterator iter = systemPlanets.begin(); foreach (PlanetP p, systemPlanets)
while (iter != systemPlanets.end())
{ {
if(restartTrails) (*iter)->startTrail(true); if (restartTrails)
(*iter)->updateTrail(nav); p->startTrail(true);
(*iter)->update((int)(deltaTime*1000)); p->updateTrail(nav);
iter++; p->update((int)(deltaTime*1000));
} }
} }
// is a lunar eclipse close at hand? // is a lunar eclipse close at hand?
bool SolarSystem::nearLunarEclipse() bool SolarSystem::nearLunarEclipse()
{ {
// TODO: could replace with simpler test // TODO: could replace with simpler test
Vec3d e = getEarth()->getEclipticPos(); Vec3d e = getEarth()->getEclipticPos();
Vec3d m = getMoon()->getEclipticPos(); // relative to earth Vec3d m = getMoon()->getEclipticPos(); // relative to earth
skipping to change at line 1092 skipping to change at line 1040
Vec3d mdist = shadow - mh; Vec3d mdist = shadow - mh;
if(mdist.length() > r_penumbra + 2000/AU) return 0; // not visible so don't bother drawing if(mdist.length() > r_penumbra + 2000/AU) return 0; // not visible so don't bother drawing
return 1; return 1;
} }
//! Find and return the list of at most maxNbItem objects auto-completing t he passed object I18n name //! Find and return the list of at most maxNbItem objects auto-completing t he passed object I18n name
QStringList SolarSystem::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const QStringList SolarSystem::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (maxNbItem==0)
return result;
QString objw = objPrefix.toUpper(); QString objw = objPrefix.toUpper();
foreach (const PlanetP& p, systemPlanets)
vector <Planet*>::const_iterator iter;
for (iter=systemPlanets.begin(); iter!=systemPlanets.end(); ++iter)
{ {
QString constw = (*iter)->getNameI18n().mid(0, objw.size()). toUpper(); QString constw = p->getNameI18n().mid(0, objw.size()).toUppe r();
if (constw==objw) if (constw==objw)
{ {
result << (*iter)->getNameI18n(); result << p->getNameI18n();
if (result.size()==maxNbItem) if (result.size()==maxNbItem)
return result; return result;
} }
} }
return result; return result;
} }
void SolarSystem::selectedObjectChangeCallBack(StelModuleSelectAction actio n) void SolarSystem::selectedObjectChangeCallBack(StelModuleSelectAction actio n)
{ {
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Planet"); const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Planet");
if (!newSelected.empty()) if (!newSelected.empty())
setSelected(newSelected[0].get()); setSelected(qSharedPointerCast<Planet>(newSelected[0]));
} }
// Activate/Deactivate planets display // Activate/Deactivate planets display
void SolarSystem::setFlagPlanets(bool b) void SolarSystem::setFlagPlanets(bool b)
{ {
flagShow=b; flagShow=b;
} }
bool SolarSystem::getFlagPlanets(void) const {return flagShow;} bool SolarSystem::getFlagPlanets(void) const {return flagShow;}
skipping to change at line 1159 skipping to change at line 1105
if (flagMoonScale) if (flagMoonScale)
getMoon()->setSphereScale(moonScale); getMoon()->setSphereScale(moonScale);
} }
// Set selected planets by englishName // Set selected planets by englishName
void SolarSystem::setSelected(const QString& englishName) void SolarSystem::setSelected(const QString& englishName)
{ {
setSelected(searchByEnglishName(englishName)); setSelected(searchByEnglishName(englishName));
} }
bool SolarSystem::biggerDistance::operator()(Planet* p1, Planet* p2)
{
return p1->getDistance() > p2->getDistance();
}
// Get the list of all the planet english names // Get the list of all the planet english names
QStringList SolarSystem::getAllPlanetEnglishNames() const QStringList SolarSystem::getAllPlanetEnglishNames() const
{ {
QStringList res; QStringList res;
for (std::vector<Planet*>::const_iterator iter(systemPlanets.begin() foreach (const PlanetP& p, systemPlanets)
);iter!=systemPlanets.end();iter++) res.append(p->englishName);
{
res.append((*iter)->englishName);
}
return res; return res;
} }
 End of changes. 144 change blocks. 
393 lines changed or deleted 322 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/