Skip to content

Commit 26fd52b

Browse files
committed
add initial support for parallax effect
1 parent a672f74 commit 26fd52b

9 files changed

Lines changed: 100 additions & 8 deletions

File tree

src/core/StelCore.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ StelCore::StelCore()
8282
, flagUseNutation(true)
8383
, flagUseAberration(true)
8484
, aberrationFactor(1.0)
85+
, flagUseParallax(true)
86+
, parallaxFactor(1.0)
8587
, flagUseTopocentricCoordinates(true)
8688
, timeSpeed(JD_SECOND)
8789
, JD(0.,0.)
@@ -141,6 +143,8 @@ StelCore::StelCore()
141143
flagUseNutation=conf->value("astro/flag_nutation", true).toBool();
142144
flagUseAberration=conf->value("astro/flag_aberration", true).toBool();
143145
aberrationFactor=conf->value("astro/aberration_factor", 1.0).toDouble();
146+
flagUseParallax=conf->value("astro/flag_parallax", true).toBool();
147+
parallaxFactor=conf->value("astro/parallax_factor", 1.0).toDouble();
144148
flagUseTopocentricCoordinates=conf->value("astro/flag_topocentric_coordinates", true).toBool();
145149
flagUseDST=conf->value("localization/flag_dst", true).toBool();
146150

src/core/StelCore.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class StelCore : public QObject
5555
Q_PROPERTY(bool flagUseNutation READ getUseNutation WRITE setUseNutation NOTIFY flagUseNutationChanged)
5656
Q_PROPERTY(bool flagUseAberration READ getUseAberration WRITE setUseAberration NOTIFY flagUseAberrationChanged)
5757
Q_PROPERTY(double aberrationFactor READ getAberrationFactor WRITE setAberrationFactor NOTIFY aberrationFactorChanged)
58+
Q_PROPERTY(bool flagUseParallax READ getUseParallax WRITE setUseParallax NOTIFY flagUseParallaxChanged)
59+
Q_PROPERTY(double parallaxFactor READ getParallaxFactor WRITE setParallaxFactor NOTIFY parallaxFactorChanged)
5860
Q_PROPERTY(bool flagUseTopocentricCoordinates READ getUseTopocentricCoordinates WRITE setUseTopocentricCoordinates NOTIFY flagUseTopocentricCoordinatesChanged)
5961
Q_PROPERTY(ProjectionType currentProjectionType READ getCurrentProjectionType WRITE setCurrentProjectionType NOTIFY currentProjectionTypeChanged)
6062
//! This is just another way to access the projection type, by string instead of enum
@@ -551,6 +553,16 @@ public slots:
551553
QByteArray getAberrationShader() const;
552554
void setAberrationUniforms(QOpenGLShaderProgram& program) const;
553555

556+
//! @return whether parallax effect is currently used.
557+
bool getUseParallax() const {return flagUseParallax;}
558+
//! Set whether you want computation and simulation of parallax effect.
559+
void setUseParallax(bool use) { if (flagUseParallax != use) { flagUseParallax=use; StelApp::immediateSave("astro/flag_parallax", use); emit flagUseParallaxChanged(use); }}
560+
561+
//! @return parallax factor. 1 is realistic simulation, but higher values may be useful for didactic purposes.
562+
double getParallaxFactor() const {return parallaxFactor;}
563+
//! Set aberration factor. Values are clamped to 0...5. (Values above 5 cause graphical problems.)
564+
void setParallaxFactor(double factor) { if (!fuzzyEquals(parallaxFactor, factor)) { parallaxFactor=qBound(0.,factor, 1000.); StelApp::immediateSave("astro/parallax_factor", parallaxFactor); emit parallaxFactorChanged(factor); }}
565+
554566
//! @return whether topocentric coordinates are currently used.
555567
bool getUseTopocentricCoordinates() const {return flagUseTopocentricCoordinates;}
556568
//! Set whether you want topocentric or planetocentric data
@@ -862,6 +874,10 @@ public slots:
862874
void flagUseAberrationChanged(bool b);
863875
//! This signal indicates a change in aberration exaggeration factor
864876
void aberrationFactorChanged(double val);
877+
//! This signal indicates a switch in use of parallax
878+
void flagUseParallaxChanged(bool b);
879+
//! This signal indicates a change in parallax exaggeration factor
880+
void parallaxFactorChanged(double val);
865881
//! This signal indicates a switch in use of topocentric coordinates
866882
void flagUseTopocentricCoordinatesChanged(bool b);
867883
//! Emitted whenever the projection type changes
@@ -943,6 +959,10 @@ private slots:
943959
bool flagUseAberration;
944960
// value to allow exaggerating aberration effects. 1 is natural value, stretching to e.g. 1000 may be useful for explanations.
945961
double aberrationFactor;
962+
// flag to indicate we want to include parallax effect
963+
bool flagUseParallax;
964+
// value to allow exaggerating parallax effects. 1 is natural value, stretching to e.g. 1000 may be useful for explanations.
965+
double parallaxFactor;
946966
// flag to indicate that we show topocentrically corrected coordinates. (Switching to false for planetocentric coordinates is new for 0.14)
947967
bool flagUseTopocentricCoordinates;
948968

src/core/modules/Star.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,18 @@ struct Star
235235
DE = getX1() + dyrs * getDx1() * MAS2RAD;
236236
}
237237
}
238+
239+
//to get new 3D cartesian position for parallax effect given current star 3D cartesian position, planet orbital period and radius and current delta time from catalog epoch
240+
inline void getPlxEffect(double plx, Vec3f& bS, double operiod, double oradius, double dyrs) const {
241+
if (plx <= 0) return;
242+
Vec3d bSd(bS[0], bS[1], bS[2]);
243+
bSd.normalize();
244+
bSd *= 1000./ plx;
245+
// remainder of dt in dyrs divided by period
246+
double dt = fmod(dyrs, operiod); // to get phase of the orbit
247+
Vec3d b0Ecl(oradius * cos(2 * M_PI / operiod * dt), oradius * sin(2 * M_PI / operiod * dt), 0.);
248+
bS = (bSd + b0Ecl * MAS2RAD * 1000.).toVec3f();
249+
}
238250
};
239251

240252
struct Star1 : public Star<Star1>

src/core/modules/StarMgr.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,12 +1242,16 @@ void StarMgr::draw(StelCore* core)
12421242
maxMagStarName = x;
12431243
}
12441244
int zone;
1245+
const double withParallax = core->getUseParallax() * core->getParallaxFactor();
1246+
double orbital_period = core->getCurrentPlanet()->getSiderealPeriod() / 365.25; // in earth years
1247+
// get orbital_radius in AU using Kepler's third law
1248+
double orbital_radius = pow(orbital_period, 2.0/3.0);
12451249
for (GeodesicSearchInsideIterator it1(*geodesic_search_result,z->level);(zone = it1.next()) >= 0;)
1246-
z->draw(&sPainter, zone, true, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, velf);
1250+
z->draw(&sPainter, zone, true, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, velf, withParallax, orbital_period, orbital_radius);
12471251
for (GeodesicSearchBorderIterator it1(*geodesic_search_result,z->level);(zone = it1.next()) >= 0;)
1248-
z->draw(&sPainter, zone, false, rcmag_table, limitMagIndex, core, maxMagStarName,names_brightness, viewportCaps, withAberration, velf);
1252+
z->draw(&sPainter, zone, false, rcmag_table, limitMagIndex, core, maxMagStarName,names_brightness, viewportCaps, withAberration, velf, withParallax, orbital_period, orbital_radius);
12491253
// always check the last zone because it is a global zone
1250-
z->draw(&sPainter, (20<<(z->level<<1)), false, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, velf);
1254+
z->draw(&sPainter, (20<<(z->level<<1)), false, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, velf, withParallax, orbital_period, orbital_radius);
12511255
}
12521256
exit_loop:
12531257

src/core/modules/StarWrapper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ QString StarWrapper1::getInfoString(const StelCore *core, const InfoStringGroup&
383383
{
384384
if (Plx!=0)
385385
{
386+
// get orbital_radius in AU using Kepler's third law, in case we are not on Earth
387+
if (core->getCurrentPlanet()->getID() != "earth") {
388+
double orbital_radius = pow(core->getCurrentPlanet()->getSiderealPeriod() / 365.25, 2.0/3.0); // in AU
389+
Plx *= orbital_radius;
390+
PlxErr *= orbital_radius;
391+
}
392+
386393
QString plx = q_("Parallax");
387394
if (PlxErr>0.f)
388395
oss << QString("%1: %2%3%4 ").arg(plx, QString::number(Plx, 'f', 3), QChar(0x00B1), QString::number(PlxErr, 'f', 3));

src/core/modules/ZoneArray.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ template<class Star>
425425
void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsideViewport, const RCMag* rcmag_table,
426426
int limitMagIndex, StelCore* core, int maxMagStarName, float names_brightness,
427427
const QVector<SphericalCap> &boundingCaps,
428-
const bool withAberration, const Vec3f vel) const
428+
const bool withAberration, const Vec3f vel, const double withParallax, double operiod, double oradius) const
429429
{
430430
StelSkyDrawer* drawer = core->getSkyDrawer();
431431
Vec3f vf;
@@ -466,16 +466,17 @@ void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsid
466466

467467
// only recompute if has time dependence and time is far away
468468
bool recomputeMag = (s->getPreciseAstrometricFlag() && (fabs(dyrs) > 5000.));
469+
double Plx = s->getPlx();
469470
if (recomputeMag) {
470471
// don't do full solution, can be very slow, just estimate here
471472
// estimate parallax from radial velocity and total proper motion
472-
double Plx = s->getPlx();
473473
double vr = s->getRV();
474474
Vec3d pmvec0(s->getDx0(), s->getDx1(), s->getDx2());
475475
pmvec0 = pmvec0 * MAS2RAD;
476476
double pmr0 = vr * Plx / (AU / JYEAR_SECONDS) * MAS2RAD;
477477
double pmtotsqr = (pmvec0[0] * pmvec0[0] + pmvec0[1] * pmvec0[1] + pmvec0[2] * pmvec0[2]);
478478
double f = 1. / sqrt(1. + 2. * pmr0 * dyrs + (pmtotsqr + pmr0*pmr0)*dyrs*dyrs);
479+
Plx *= f;
479480
float magOffset = 5.f * log10(1/f);
480481
starMag += magOffset * 1000.;
481482
// if we reach here we might as well compute the position too
@@ -498,6 +499,10 @@ void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsid
498499
s->getJ2000Pos(dyrs, vf);
499500
}
500501

502+
if (withParallax) {
503+
s->getPlxEffect(withParallax * Plx, vf, operiod, oradius, dyrs);
504+
}
505+
501506
// Aberration: vf contains Equatorial J2000 position.
502507
if (withAberration)
503508
{

src/core/modules/ZoneArray.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class ZoneArray
110110
const RCMag* rcmag_table, int limitMagIndex, StelCore* core,
111111
int maxMagStarName, float names_brightness,
112112
const QVector<SphericalCap>& boundingCaps,
113-
const bool withAberration, const Vec3f vel) const = 0;
113+
const bool withAberration, const Vec3f vel, const double withParallax, double operiod, double oradius) const = 0;
114114

115115
//! Get whether or not the catalog was successfully loaded.
116116
//! @return @c true if at least one zone was loaded, otherwise @c false
@@ -182,7 +182,7 @@ class SpecialZoneArray : public ZoneArray
182182
const RCMag *rcmag_table, int limitMagIndex, StelCore* core,
183183
int maxMagStarName, float names_brightness,
184184
const QVector<SphericalCap>& boundingCaps,
185-
const bool withAberration, const Vec3f vel) const override;
185+
const bool withAberration, const Vec3f vel, const double withParallax, double operiod, double oradius) const override;
186186

187187
void searchAround(const StelCore* core, int index,const Vec3d &v,double cosLimFov,
188188
QList<StelObjectP > &result) override;

src/gui/ConfigurationDialog.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ void ConfigurationDialog::createDialogContent()
209209
connectBoolProperty(ui->nutationCheckBox, "StelCore.flagUseNutation");
210210
connectBoolProperty(ui->aberrationCheckBox, "StelCore.flagUseAberration");
211211
connectDoubleProperty(ui->aberrationSpinBox, "StelCore.aberrationFactor");
212+
connectBoolProperty(ui->parallaxCheckBox, "StelCore.flagUseParallax");
213+
connectDoubleProperty(ui->parallaxSpinBox, "StelCore.parallaxFactor");
212214
connectBoolProperty(ui->topocentricCheckBox, "StelCore.flagUseTopocentricCoordinates");
213215

214216
// Additional settings for selected object info
@@ -1088,6 +1090,8 @@ void ConfigurationDialog::saveAllSettings()
10881090
conf->setValue("astro/flag_nutation", core->getUseNutation());
10891091
conf->setValue("astro/flag_aberration", core->getUseAberration());
10901092
conf->setValue("astro/aberration_factor", core->getAberrationFactor());
1093+
conf->setValue("astro/flag_parallax", core->getUseParallax());
1094+
conf->setValue("astro/parallax_factor", core->getParallaxFactor());
10911095
conf->setValue("astro/flag_topocentric_coordinates", core->getUseTopocentricCoordinates());
10921096
conf->setValue("astro/solar_system_threads", propMgr->getStelPropertyValue("SolarSystem.extraThreads").toInt());
10931097

src/gui/configurationDialog.ui

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2203,11 +2203,47 @@
22032203
</property>
22042204
</widget>
22052205
</item>
2206-
<item row="0" column="3" rowspan="2">
2206+
<item row="0" column="3" rowspan="3">
22072207
<layout class="QGridLayout" name="gridLayoutInclude">
22082208
<property name="spacing">
22092209
<number>0</number>
22102210
</property>
2211+
<item row="2" column="1">
2212+
<layout class="QHBoxLayout" name="horizontalLayout_IncludeParallax">
2213+
<item>
2214+
<widget class="QCheckBox" name="parallaxCheckBox">
2215+
<property name="toolTip">
2216+
<string>Parallax is the apparent shift in the position of an object when viewed from two different points.</string>
2217+
</property>
2218+
<property name="text">
2219+
<string>Parallax</string>
2220+
</property>
2221+
</widget>
2222+
</item>
2223+
<item>
2224+
<widget class="QDoubleSpinBox" name="parallaxSpinBox">
2225+
<property name="toolTip">
2226+
<string>Exaggerate parallax (for didactic explanations)</string>
2227+
</property>
2228+
<property name="decimals">
2229+
<number>1</number>
2230+
</property>
2231+
<property name="minimum">
2232+
<double>1.000000000000000</double>
2233+
</property>
2234+
<property name="maximum">
2235+
<double>1000.000000000000000</double>
2236+
</property>
2237+
<property name="singleStep">
2238+
<double>1.000000000000000</double>
2239+
</property>
2240+
<property name="value">
2241+
<double>1.000000000000000</double>
2242+
</property>
2243+
</widget>
2244+
</item>
2245+
</layout>
2246+
</item>
22112247
<item row="1" column="2">
22122248
<layout class="QHBoxLayout" name="horizontalLayout_IncludeNutAberr">
22132249
<item>

0 commit comments

Comments
 (0)