53
52
#include <QMapIterator>
58
SolarSystem::SolarSystem() :sun(NULL),moon(NULL),earth(NULL),selected(NULL), moonScale(1.), fontSize(14.),
59
planetNameFont(StelApp::getInstance().getFontManager().getStandardFont(StelApp::getInstance().getLocaleMgr().getAppLanguage(), fontSize)),
60
flagOrbits(false),flagLightTravelTime(false), lastHomePlanet(NULL)
55
SolarSystem::SolarSystem() : moonScale(1.), flagOrbits(false), flagLightTravelTime(false), lastHomePlanet(NULL)
57
planetNameFont.setPixelSize(14.);
62
58
setObjectName("SolarSystem");
65
61
void SolarSystem::setFontSize(float newFontSize)
67
planetNameFont = StelApp::getInstance().getFontManager().getStandardFont(StelApp::getInstance().getLocaleMgr().getSkyLanguage(), fontSize);
63
planetNameFont.setPixelSize(newFontSize);
70
66
SolarSystem::~SolarSystem()
72
68
// release selected:
74
for(std::vector<Planet*>::iterator iter = systemPlanets.begin(); iter != systemPlanets.end(); ++iter)
76
if (*iter) delete *iter;
79
for(std::vector<Orbit*>::iterator iter = orbits.begin(); iter != orbits.end(); ++iter)
81
if (*iter) delete *iter;
87
Planet::hintCircleTex.reset();
88
Planet::texEarthShadow.reset();
70
foreach (Orbit* orb, orbits)
78
Planet::hintCircleTex.clear();
79
Planet::texEarthShadow.clear();
91
82
/*************************************************************************
119
110
setFlagOrbits(conf->value("astro/flag_planets_orbits").toBool());
120
111
setFlagLightTravelTime(conf->value("astro/flag_light_travel_time", false).toBool());
121
112
setFlagTrails(conf->value("astro/flag_object_trails", false).toBool());
122
startTrails(conf->value("astro/flag_object_trails", false).toBool());
113
startTrails(conf->value("astro/flag_object_trails", false).toBool());
124
115
GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this);
125
StelApp::getInstance().getTextureManager().setDefaultParams();
126
StelApp::getInstance().getTextureManager().setMinFilter(GL_LINEAR);
127
116
texPointer = StelApp::getInstance().getTextureManager().createTexture("pointeur4.png");
128
117
Planet::hintCircleTex = StelApp::getInstance().getTextureManager().createTexture("planet-indicator.png");
142
131
// Compute 2D pos and return if outside screen
143
132
if (!prj->project(pos, screenpos))
147
136
StelPainter sPainter(prj);
148
glColor3f(1.0f,0.3f,0.3f);
137
sPainter.setColor(1.0f,0.3f,0.3f);
150
139
float size = obj->getAngularSize(core)*M_PI/180.*prj->getPixelPerRadAtCenter()*2.;
151
size+=26.f + 10.f*std::sin(2.f * StelApp::getInstance().getTotalRunTime());
140
size+=40.f + 10.f*std::sin(2.f * StelApp::getInstance().getTotalRunTime());
153
142
texPointer->bind();
155
glEnable(GL_TEXTURE_2D);
157
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode
160
glTranslatef(screenpos[0], screenpos[1], 0.0f);
161
glRotatef(StelApp::getInstance().getTotalRunTime()*10.,0,0,-1);
163
glTranslatef(-size/2, -size/2,0.0f);
166
glTexCoord2f(0.0f,0.0f); glVertex3f(-10,-10,0); //Bas Gauche
167
glTexCoord2f(1.0f,0.0f); glVertex3f(10,-10,0); //Bas Droite
168
glTexCoord2f(1.0f,1.0f); glVertex3f(10,10,0); //Haut Droit
169
glTexCoord2f(0.0f,1.0f); glVertex3f(-10,10,0); //Haut Gauche
172
glRotatef(-90,0,0,1);
173
glTranslatef(0,size,0.0f);
175
glTexCoord2f(0.0f,0.0f); glVertex3f(-10,-10,0); //Bas Gauche
176
glTexCoord2f(1.0f,0.0f); glVertex3f(10,-10,0); //Bas Droite
177
glTexCoord2f(1.0f,1.0f); glVertex3f(10,10,0); //Haut Droit
178
glTexCoord2f(0.0f,1.0f); glVertex3f(-10,10,0); //Haut Gauche
181
glRotatef(-90,0,0,1);
182
glTranslatef(0, size,0.0f);
184
glTexCoord2f(0.0f,0.0f); glVertex3f(-10,-10,0); //Bas Gauche
185
glTexCoord2f(1.0f,0.0f); glVertex3f(10,-10,0); //Bas Droite
186
glTexCoord2f(1.0f,1.0f); glVertex3f(10,10,0); //Haut Droit
187
glTexCoord2f(0.0f,1.0f); glVertex3f(-10,10,0); //Haut Gauche
190
glRotatef(-90,0,0,1);
191
glTranslatef(0,size,0);
193
glTexCoord2f(0.0f,0.0f); glVertex3f(-10,-10,0); //Bas Gauche
194
glTexCoord2f(1.0f,0.0f); glVertex3f(10,-10,0); //Bas Droite
195
glTexCoord2f(1.0f,1.0f); glVertex3f(10,10,0); //Haut Droit
196
glTexCoord2f(0.0f,1.0f); glVertex3f(-10,10,0); //Haut Gauche
144
sPainter.enableTexture2d(true);
146
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode
149
const float angleBase = StelApp::getInstance().getTotalRunTime() * 10;
150
// We draw 4 instances of the sprite at the corners of the pointer
151
for (int i = 0; i < 4; ++i)
153
const float angle = angleBase + i * 90;
154
const double x = screenpos[0] + size * cos(angle / 180 * M_PI);
155
const double y = screenpos[1] + size * sin(angle / 180 * M_PI);
156
sPainter.drawSprite2dMode(x, y, 10, angle);
161
void ellipticalOrbitPosFunc(double jd,double xyz[3], void* userDataPtr)
163
static_cast<EllipticalOrbit*>(userDataPtr)->positionAtTimevInVSOP87Coordinates(jd, xyz);
165
void cometOrbitPosFunc(double jd,double xyz[3], void* userDataPtr)
167
static_cast<CometOrbit*>(userDataPtr)->positionAtTimevInVSOP87Coordinates(jd, xyz);
202
170
// Init and load the solar system data
203
171
void SolarSystem::loadPlanets()
223
191
// QSettings does not allow us to say that the sections of the file
224
// will be listed in the same order as in the file like the old
225
// InitParser used to so we can no longer assume that.
192
// will be listed in the same order as in the file like the old
193
// InitParser used to so we can no longer assume that.
227
195
// This means we must first decide what order to read the sections
228
196
// of the file in (each section contains one planet) to avoid setting
229
197
// the parent Planet* to one which has not yet been created.
231
// Stage 1: Make a map of body names back to the section names
232
// which they come from. Also make a map of body name to parent body
233
// name. These two maps can be made in a single pass through the
199
// Stage 1: Make a map of body names back to the section names
200
// which they come from. Also make a map of body name to parent body
201
// name. These two maps can be made in a single pass through the
234
202
// sections of the file.
236
204
// Stage 2: Make an ordered list of section names such that each
237
205
// item is only ever dependent on items which appear earlier in the
239
207
// 2a: Make a QMultiMap relating the number of levels of dependency
240
// to the body name, i.e.
208
// to the body name, i.e.
360
328
period = pd.value(secname+"/orbit_Period",-1e100).toDouble();
361
329
if (period <= -1e100) {
362
330
meanMotion = (eccentricity == 1.0)
363
? 0.01720209895 * (1.5/pericenterDistance)
364
* sqrt(0.5/pericenterDistance)
365
: (semi_major_axis > 0.0)
366
? 0.01720209895 / (semi_major_axis*sqrt(semi_major_axis))
367
: 0.01720209895 / (-semi_major_axis*sqrt(-semi_major_axis));
331
? 0.01720209895 * (1.5/pericenterDistance)
332
* sqrt(0.5/pericenterDistance)
333
: (semi_major_axis > 0.0)
334
? 0.01720209895 / (semi_major_axis*sqrt(semi_major_axis))
335
: 0.01720209895 / (-semi_major_axis*sqrt(-semi_major_axis));
368
336
period = 2.0*M_PI/meanMotion;
370
338
meanMotion = 2.0*M_PI/period;
470
439
// in case of parent=sun: use Gaussian gravitational constant
471
440
// for calculating meanMotion:
472
441
meanMotion = (eccentricity == 1.0)
473
? 0.01720209895 * (1.5/pericenterDistance)
474
* sqrt(0.5/pericenterDistance)
475
: (semi_major_axis > 0.0)
476
? 0.01720209895 / (semi_major_axis*sqrt(semi_major_axis))
477
: 0.01720209895 / (-semi_major_axis*sqrt(-semi_major_axis));
442
? 0.01720209895 * (1.5/pericenterDistance)
443
* sqrt(0.5/pericenterDistance)
444
: (semi_major_axis > 0.0)
445
? 0.01720209895 / (semi_major_axis*sqrt(semi_major_axis))
446
: 0.01720209895 / (-semi_major_axis*sqrt(-semi_major_axis));
480
449
meanMotion = 2.0*M_PI/period;
500
469
const double arg_of_pericenter = pd.value(secname+"/orbit_ArgOfPericenter").toDouble()*(M_PI/180.0);
501
470
const double ascending_node = pd.value(secname+"/orbit_AscendingNode").toDouble()*(M_PI/180.0);
502
471
const double parentRotObliquity = parent->getParent()
503
? parent->getRotObliquity()
472
? parent->getRotObliquity()
505
474
const double parent_rot_asc_node = parent->getParent()
506
? parent->getRotAscendingnode()
475
? parent->getRotAscendingnode()
508
477
double parent_rot_j2000_longitude = 0.0;
509
if (parent->getParent()) {
510
const double c_obl = cos(parentRotObliquity);
511
const double s_obl = sin(parentRotObliquity);
512
const double c_nod = cos(parent_rot_asc_node);
513
const double s_nod = sin(parent_rot_asc_node);
514
const Vec3d OrbitAxis0( c_nod, s_nod, 0.0);
515
const Vec3d OrbitAxis1(-s_nod*c_obl, c_nod*c_obl,s_obl);
516
const Vec3d OrbitPole( s_nod*s_obl,-c_nod*s_obl,c_obl);
478
if (parent->getParent()) {
479
const double c_obl = cos(parentRotObliquity);
480
const double s_obl = sin(parentRotObliquity);
481
const double c_nod = cos(parent_rot_asc_node);
482
const double s_nod = sin(parent_rot_asc_node);
483
const Vec3d OrbitAxis0( c_nod, s_nod, 0.0);
484
const Vec3d OrbitAxis1(-s_nod*c_obl, c_nod*c_obl,s_obl);
485
const Vec3d OrbitPole( s_nod*s_obl,-c_nod*s_obl,c_obl);
517
486
const Vec3d J2000Pole(StelNavigator::matJ2000ToVsop87.multiplyWithoutTranslation(Vec3d(0,0,1)));
518
Vec3d J2000NodeOrigin(J2000Pole^OrbitPole);
519
J2000NodeOrigin.normalize();
520
parent_rot_j2000_longitude = atan2(J2000NodeOrigin*OrbitAxis1,J2000NodeOrigin*OrbitAxis0);
487
Vec3d J2000NodeOrigin(J2000Pole^OrbitPole);
488
J2000NodeOrigin.normalize();
489
parent_rot_j2000_longitude = atan2(J2000NodeOrigin*OrbitAxis1,J2000NodeOrigin*OrbitAxis0);
522
491
CometOrbit *orb = new CometOrbit(pericenterDistance,
531
500
parent_rot_j2000_longitude);
532
501
orbits.push_back(orb);
534
posfunc = posFuncType(orb,&CometOrbit::positionAtTimevInVSOP87Coordinates);
503
posfunc = &cometOrbitPosFunc;
537
506
if (funcName=="sun_special")
538
posfunc = posFuncType(get_sun_helio_coordsv);
507
posfunc = &get_sun_helio_coordsv;
540
509
if (funcName=="mercury_special") {
541
posfunc = posFuncType(get_mercury_helio_coordsv);
510
posfunc = &get_mercury_helio_coordsv;
542
511
osculatingFunc = &get_mercury_helio_osculating_coords;
545
514
if (funcName=="venus_special") {
546
posfunc = posFuncType(get_venus_helio_coordsv);
515
posfunc = &get_venus_helio_coordsv;
547
516
osculatingFunc = &get_venus_helio_osculating_coords;
550
519
if (funcName=="earth_special") {
551
posfunc = posFuncType(get_earth_helio_coordsv);
520
posfunc = &get_earth_helio_coordsv;
552
521
osculatingFunc = &get_earth_helio_osculating_coords;
555
524
if (funcName=="lunar_special")
556
posfunc = posFuncType(get_lunar_parent_coordsv);
525
posfunc = &get_lunar_parent_coordsv;
558
527
if (funcName=="mars_special") {
559
posfunc = posFuncType(get_mars_helio_coordsv);
528
posfunc = &get_mars_helio_coordsv;
560
529
osculatingFunc = &get_mars_helio_osculating_coords;
564
533
posfunc = posFuncType(get_phobos_parent_coordsv);
566
535
if (funcName=="deimos_special")
567
posfunc = posFuncType(get_deimos_parent_coordsv);
536
posfunc = &get_deimos_parent_coordsv;
569
538
if (funcName=="jupiter_special") {
570
posfunc = posFuncType(get_jupiter_helio_coordsv);
539
posfunc = &get_jupiter_helio_coordsv;
571
540
osculatingFunc = &get_jupiter_helio_osculating_coords;
574
543
if (funcName=="europa_special")
575
posfunc = posFuncType(get_europa_parent_coordsv);
544
posfunc = &get_europa_parent_coordsv;
577
546
if (funcName=="calisto_special")
578
posfunc = posFuncType(get_callisto_parent_coordsv);
547
posfunc = &get_callisto_parent_coordsv;
580
549
if (funcName=="io_special")
581
posfunc = posFuncType(get_io_parent_coordsv);
550
posfunc = &get_io_parent_coordsv;
583
552
if (funcName=="ganymede_special")
584
posfunc = posFuncType(get_ganymede_parent_coordsv);
553
posfunc = &get_ganymede_parent_coordsv;
586
555
if (funcName=="saturn_special") {
587
posfunc = posFuncType(get_saturn_helio_coordsv);
556
posfunc = &get_saturn_helio_coordsv;
588
557
osculatingFunc = &get_saturn_helio_osculating_coords;
591
560
if (funcName=="mimas_special")
592
posfunc = posFuncType(get_mimas_parent_coordsv);
561
posfunc = &get_mimas_parent_coordsv;
594
563
if (funcName=="enceladus_special")
595
posfunc = posFuncType(get_enceladus_parent_coordsv);
564
posfunc = &get_enceladus_parent_coordsv;
597
566
if (funcName=="tethys_special")
598
posfunc = posFuncType(get_tethys_parent_coordsv);
567
posfunc = &get_tethys_parent_coordsv;
600
569
if (funcName=="dione_special")
601
posfunc = posFuncType(get_dione_parent_coordsv);
570
posfunc = &get_dione_parent_coordsv;
603
572
if (funcName=="rhea_special")
604
posfunc = posFuncType(get_rhea_parent_coordsv);
573
posfunc = &get_rhea_parent_coordsv;
606
575
if (funcName=="titan_special")
607
posfunc = posFuncType(get_titan_parent_coordsv);
576
posfunc = &get_titan_parent_coordsv;
609
578
if (funcName=="iapetus_special")
610
posfunc = posFuncType(get_iapetus_parent_coordsv);
579
posfunc = &get_iapetus_parent_coordsv;
612
581
if (funcName=="hyperion_special")
613
posfunc = posFuncType(get_hyperion_parent_coordsv);
582
posfunc = &get_hyperion_parent_coordsv;
615
584
if (funcName=="uranus_special") {
616
posfunc = posFuncType(get_uranus_helio_coordsv);
585
posfunc = &get_uranus_helio_coordsv;
617
586
osculatingFunc = &get_uranus_helio_osculating_coords;
620
589
if (funcName=="miranda_special")
621
posfunc = posFuncType(get_miranda_parent_coordsv);
590
posfunc = &get_miranda_parent_coordsv;
623
592
if (funcName=="ariel_special")
624
posfunc = posFuncType(get_ariel_parent_coordsv);
593
posfunc = &get_ariel_parent_coordsv;
626
595
if (funcName=="umbriel_special")
627
posfunc = posFuncType(get_umbriel_parent_coordsv);
596
posfunc = &get_umbriel_parent_coordsv;
629
598
if (funcName=="titania_special")
630
posfunc = posFuncType(get_titania_parent_coordsv);
599
posfunc = &get_titania_parent_coordsv;
632
601
if (funcName=="oberon_special")
633
posfunc = posFuncType(get_oberon_parent_coordsv);
602
posfunc = &get_oberon_parent_coordsv;
635
604
if (funcName=="neptune_special") {
636
605
posfunc = posFuncType(get_neptune_helio_coordsv);
640
609
if (funcName=="pluto_special")
641
posfunc = posFuncType(get_pluto_helio_coordsv);
610
posfunc = &get_pluto_helio_coordsv;
646
615
qWarning() << "ERROR : can't find posfunc " << funcName << " for " << englishName;
650
619
// Create the Planet and add it to the list
651
Planet* p = new Planet(englishName,
620
PlanetP p(new Planet(englishName,
652
621
pd.value(secname+"/lighting").toBool(),
653
622
pd.value(secname+"/radius").toDouble()/AU,
654
623
pd.value(secname+"/oblateness", 0.0).toDouble(),
681
654
Vec3d J2000NPole;
682
655
StelUtils::spheToRect(J2000NPoleRA,J2000NPoleDE,J2000NPole);
684
657
Vec3d vsop87Pole(StelNavigator::matJ2000ToVsop87.multiplyWithoutTranslation(J2000NPole));
687
660
StelUtils::rectToSphe(&ra, &de, vsop87Pole);
689
662
rotObliquity = (M_PI_2 - de);
690
663
rotAscNode = (ra + M_PI_2);
692
665
// qDebug() << "\tCalculated rotational obliquity: " << rotObliquity*180./M_PI << endl;
693
666
// qDebug() << "\tCalculated rotational ascending node: " << rotAscNode*180./M_PI << endl;
696
669
p->setRotationElements(
697
pd.value(secname+"/rot_periode", pd.value(secname+"/orbit_Period", 24.).toDouble()).toDouble()/24.,
698
pd.value(secname+"/rot_rotation_offset",0.).toDouble(),
699
pd.value(secname+"/rot_epoch", J2000).toDouble(),
702
pd.value(secname+"/rot_precession_rate",0.).toDouble()*M_PI/(180*36525),
703
pd.value(secname+"/orbit_visualization_period",0.).toDouble());
670
pd.value(secname+"/rot_periode", pd.value(secname+"/orbit_Period", 24.).toDouble()).toDouble()/24.,
671
pd.value(secname+"/rot_rotation_offset",0.).toDouble(),
672
pd.value(secname+"/rot_epoch", J2000).toDouble(),
675
pd.value(secname+"/rot_precession_rate",0.).toDouble()*M_PI/(180*36525),
676
pd.value(secname+"/orbit_visualization_period",0.).toDouble());
706
679
if (pd.value(secname+"/rings", 0).toBool()) {
728
700
if (flagLightTravelTime)
730
for (std::vector<Planet*>::const_iterator iter(systemPlanets.begin());iter!=systemPlanets.end();iter++)
702
foreach (PlanetP p, systemPlanets)
732
(*iter)->computePositionWithoutOrbits(date);
704
p->computePositionWithoutOrbits(date);
734
for (std::vector<Planet*>::const_iterator iter(systemPlanets.begin());iter!=systemPlanets.end();iter++)
706
foreach (PlanetP p, systemPlanets)
736
const double light_speed_correction = ((*iter)->getHeliocentricEclipticPos()-observerPos).length() * (AU / (SPEED_OF_LIGHT * 86400));
737
(*iter)->computePosition(date-light_speed_correction);
708
const double light_speed_correction = (p->getHeliocentricEclipticPos()-observerPos).length() * (AU / (SPEED_OF_LIGHT * 86400));
709
p->computePosition(date-light_speed_correction);
742
for (std::vector<Planet*>::const_iterator iter(systemPlanets.begin());iter!=systemPlanets.end();iter++)
714
foreach (PlanetP p, systemPlanets)
744
(*iter)->computePosition(date);
716
p->computePosition(date);
747
719
computeTransMatrices(date, observerPos);
754
726
if (flagLightTravelTime)
756
for (std::vector<Planet*>::const_iterator iter(systemPlanets.begin());iter!=systemPlanets.end();iter++)
728
foreach (PlanetP p, systemPlanets)
758
const double light_speed_correction = ((*iter)->getHeliocentricEclipticPos()-observerPos).length() * (AU / (SPEED_OF_LIGHT * 86400));
759
(*iter)->computeTransMatrix(date-light_speed_correction);
730
const double light_speed_correction = (p->getHeliocentricEclipticPos()-observerPos).length() * (AU / (SPEED_OF_LIGHT * 86400));
731
p->computeTransMatrix(date-light_speed_correction);
764
for (std::vector<Planet*>::const_iterator iter(systemPlanets.begin());iter!=systemPlanets.end();iter++)
736
foreach (PlanetP p, systemPlanets)
766
(*iter)->computeTransMatrix(date);
738
p->computeTransMatrix(date);
743
// And sort them from the furthest to the closest to the observer
744
struct biggerDistance : public std::binary_function<PlanetP, PlanetP, bool>
746
bool operator()(PlanetP p1, PlanetP p2)
748
return p1->getDistance() > p2->getDistance();
771
752
// Draw all the elements of the solar system
772
753
// We are supposed to be in heliocentric coordinate
773
754
void SolarSystem::draw(StelCore* core)
778
759
StelNavigator* nav = core->getNavigator();
779
Planet::setFont(&planetNameFont);
781
761
// Compute each Planet distance to the observer
782
762
Vec3d obsHelioPos = nav->getObserverHeliocentricEclipticPos();
784
vector<Planet*>::iterator iter;
785
iter = systemPlanets.begin();
786
while (iter != systemPlanets.end())
764
foreach (PlanetP p, systemPlanets)
788
(*iter)->computeDistance(obsHelioPos);
766
p->computeDistance(obsHelioPos);
792
769
// And sort them from the furthest to the closest
810
785
// Load colors from config file
811
786
QSettings* conf = StelApp::getInstance().getSettings();
812
787
QString section = style.confSectionName;
814
789
QString defaultColor = conf->value(section+"/default_color").toString();
815
790
setLabelsColor(StelUtils::strToVec3f(conf->value(section+"/planet_names_color", defaultColor).toString()));
816
791
setOrbitsColor(StelUtils::strToVec3f(conf->value(section+"/planet_orbits_color", defaultColor).toString()));
817
792
setTrailsColor(StelUtils::strToVec3f(conf->value(section+"/object_trails_color", defaultColor).toString()));
820
Planet* SolarSystem::searchByEnglishName(QString planetEnglishName) const
795
PlanetP SolarSystem::searchByEnglishName(QString planetEnglishName) const
822
vector<Planet*>::const_iterator iter = systemPlanets.begin();
823
while (iter != systemPlanets.end())
797
foreach (const PlanetP& p, systemPlanets)
825
if((*iter)->getEnglishName() == planetEnglishName) return (*iter); // also check standard ini file names
799
if (p->getEnglishName() == planetEnglishName)
832
805
StelObjectP SolarSystem::searchByNameI18n(const QString& planetNameI18) const
834
vector<Planet*>::const_iterator iter = systemPlanets.begin();
835
while (iter != systemPlanets.end())
807
foreach (const PlanetP& p, systemPlanets)
837
if( (*iter)->getNameI18n() == planetNameI18 ) return (*iter); // also check standard ini file names
809
if (p->getNameI18n() == planetNameI18)
810
return qSharedPointerCast<StelObject>(p);
812
return StelObjectP();
844
816
StelObjectP SolarSystem::searchByName(const QString& name) const
846
vector<Planet*>::const_iterator iter = systemPlanets.begin();
847
while (iter != systemPlanets.end())
818
foreach (const PlanetP& p, systemPlanets)
849
if( (*iter)->getEnglishName() == name ) return (*iter);
820
if (p->getEnglishName() == name)
821
return qSharedPointerCast<StelObject>(p);
823
return StelObjectP();
855
826
// Search if any Planet is close to position given in earth equatorial position and return the distance
856
StelObject* SolarSystem::search(Vec3d pos, const StelCore* core) const
827
StelObjectP SolarSystem::search(Vec3d pos, const StelCore* core) const
859
Planet * closest = NULL;
860
831
double cos_angle_closest = 0.;
863
vector<Planet*>::const_iterator iter = systemPlanets.begin();
864
while (iter != systemPlanets.end())
834
foreach (const PlanetP& p, systemPlanets)
866
equPos = (*iter)->getEquinoxEquatorialPos(core->getNavigator());
836
equPos = p->getEquinoxEquatorialPos(core->getNavigator());
867
837
equPos.normalize();
868
double cos_ang_dist = equPos[0]*pos[0] + equPos[1]*pos[1] + equPos[2]*pos[2];
838
double cos_ang_dist = equPos*pos;
869
839
if (cos_ang_dist>cos_angle_closest)
872
842
cos_angle_closest = cos_ang_dist;
877
846
if (cos_angle_closest>0.999)
848
return qSharedPointerCast<StelObject>(closest);
850
else return StelObjectP();
884
853
// Return a stl vector containing the planets located inside the limFov circle around position v
911
878
void SolarSystem::updateI18n()
913
880
StelTranslator& trans = StelApp::getInstance().getLocaleMgr().getSkyTranslator();
914
vector<Planet*>::iterator iter;
915
for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter++ )
917
(*iter)->translateName(trans);
919
planetNameFont = StelApp::getInstance().getFontManager().getStandardFont(trans.getTrueLocaleName(), fontSize);
881
foreach (PlanetP p, systemPlanets)
882
p->translateName(trans);
922
885
QString SolarSystem::getPlanetHashString(void)
925
888
QTextStream oss(&str);
927
vector <Planet *>::iterator iter;
928
for (iter = systemPlanets.begin(); iter != systemPlanets.end(); ++iter)
889
foreach (const PlanetP& p, systemPlanets)
930
if((*iter)->getParent() != NULL && (*iter)->getParent()->getEnglishName() != "Sun")
891
if (!p->getParent().isNull() && p->getParent()->getEnglishName() != "Sun")
932
oss << (*iter)->getParent()->getEnglishName() << " : ";
893
oss << p->getParent()->getEnglishName() << " : ";
935
oss << (*iter)->getEnglishName() << endl;
936
oss << (*iter)->getEnglishName() << endl;
895
oss << p->getEnglishName() << endl;
896
oss << p->getEnglishName() << endl;
941
901
void SolarSystem::startTrails(bool b)
943
vector<Planet*>::iterator iter;
944
for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter++ )
946
(*iter)->startTrail(b);
903
foreach (PlanetP p, systemPlanets)
950
907
void SolarSystem::setFlagTrails(bool b)
952
vector<Planet*>::iterator iter;
953
for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter++ )
955
(*iter)->setFlagTrail(b);
909
foreach (PlanetP p, systemPlanets)
959
913
bool SolarSystem::getFlagTrails(void) const
961
for (std::vector<Planet*>::const_iterator iter = systemPlanets.begin();
962
iter != systemPlanets.end(); iter++ ) {
963
if ((*iter)->getFlagTrail()) return true;
915
foreach (const PlanetP& p, systemPlanets)
917
if (p->getFlagTrail())
968
923
void SolarSystem::setFlagHints(bool b)
970
vector<Planet*>::iterator iter;
971
for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter++ )
973
(*iter)->setFlagHints(b);
925
foreach (PlanetP p, systemPlanets)
977
929
bool SolarSystem::getFlagHints(void) const
979
for (std::vector<Planet*>::const_iterator iter = systemPlanets.begin(); iter != systemPlanets.end(); iter++)
931
foreach (const PlanetP& p, systemPlanets)
981
if ((*iter)->getFlagHints()) return true;
933
if (p->getFlagHints())
986
939
void SolarSystem::setFlagLabels(bool b)
988
vector<Planet*>::iterator iter;
989
for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter++ )
991
(*iter)->setFlagLabels(b);
941
foreach (PlanetP p, systemPlanets)
995
945
bool SolarSystem::getFlagLabels() const
997
for (std::vector<Planet*>::const_iterator iter = systemPlanets.begin(); iter != systemPlanets.end(); iter++)
947
foreach (const PlanetP& p, systemPlanets)
999
if ((*iter)->getFlagLabels()) return true;
949
if (p->getFlagLabels())
1004
955
void SolarSystem::setFlagOrbits(bool b)
1007
if (!b || !selected || selected == sun)
1009
vector<Planet*>::iterator iter;
1010
for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter++ )
958
if (!b || !selected || selected==sun)
960
foreach (PlanetP p, systemPlanets)
965
// If a Planet is selected and orbits are on, fade out non-selected ones
966
foreach (PlanetP p, systemPlanets)
1012
(*iter)->setFlagOrbits(b);
971
p->setFlagOrbits(false);
1017
// if a Planet is selected and orbits are on,
1018
// fade out non-selected ones
1019
vector<Planet*>::iterator iter;
1020
for (iter = systemPlanets.begin();
1021
iter != systemPlanets.end(); iter++ )
1023
if (selected == (*iter)) (*iter)->setFlagOrbits(b);
1024
else (*iter)->setFlagOrbits(false);
1029
976
void SolarSystem::setFlagLightTravelTime(bool b)
1052
999
// Determine if home planet has changed, and restart planet trails
1053
1000
// since the data is no longer useful
1054
if (nav->getHomePlanet() != lastHomePlanet)
1001
if (lastHomePlanet && nav->getCurrentLocation().planetName != lastHomePlanet->getEnglishName())
1056
lastHomePlanet = nav->getHomePlanet();
1003
lastHomePlanet = searchByEnglishName(nav->getCurrentLocation().planetName);
1004
Q_ASSERT(!lastHomePlanet.isNull());
1057
1005
restartTrails = true;
1060
vector<Planet*>::iterator iter = systemPlanets.begin();
1061
while (iter != systemPlanets.end())
1008
foreach (PlanetP p, systemPlanets)
1063
if(restartTrails) (*iter)->startTrail(true);
1064
(*iter)->updateTrail(nav);
1065
(*iter)->update((int)(deltaTime*1000));
1011
p->startTrail(true);
1012
p->updateTrail(nav);
1013
p->update((int)(deltaTime*1000));
1096
1043
QStringList SolarSystem::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const
1098
1045
QStringList result;
1099
if (maxNbItem==0) return result;
1101
1048
QString objw = objPrefix.toUpper();
1103
vector <Planet*>::const_iterator iter;
1104
for (iter=systemPlanets.begin(); iter!=systemPlanets.end(); ++iter)
1049
foreach (const PlanetP& p, systemPlanets)
1106
QString constw = (*iter)->getNameI18n().mid(0, objw.size()).toUpper();
1051
QString constw = p->getNameI18n().mid(0, objw.size()).toUpper();
1107
1052
if (constw==objw)
1109
result << (*iter)->getNameI18n();
1054
result << p->getNameI18n();
1110
1055
if (result.size()==maxNbItem)