Skip to content

Commit e96d56a

Browse files
committed
Attempt to filter away occulted stars.
- does not work properly: tessellated Moon sphere is often smaller than its computed radius!
1 parent 0b75928 commit e96d56a

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

src/core/modules/StarMgr.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "ConstellationMgr.hpp"
4545
#include "Planet.hpp"
4646
#include "StelUtils.hpp"
47+
#include "SolarSystem.hpp"
4748

4849
#include <QTextStream>
4950
#include <QFile>
@@ -1312,6 +1313,20 @@ void StarMgr::draw(StelCore* core)
13121313

13131314
// Prepare a table for storing precomputed RCMag for all ZoneArrays
13141315
RCMag rcmag_table[RCMAG_TABLE_SIZE];
1316+
1317+
// Try to filter away stars hidden by the Moon!
1318+
bool filterMoon=false;
1319+
PlanetP moon = GETSTELMODULE(SolarSystem)->getMoon();
1320+
Vec3d moonPos=moon->getJ2000EquatorialPos(core);
1321+
const double moonRadius = moon->getEquatorialRadius() * moon->getSphereScale();
1322+
double angularSize = atan2(moonRadius, moonPos.norm());
1323+
moonPos.normalize();
1324+
SphericalCap moonCap(moonPos, cos(angularSize));
1325+
for (auto cap : viewportCaps)
1326+
{
1327+
if (cap.intersects(moonCap))
1328+
filterMoon=true;
1329+
}
13151330

13161331
// Draw all the stars of all the selected zones
13171332
for (const auto* z : qAsConst(gridLevels))
@@ -1355,9 +1370,9 @@ void StarMgr::draw(StelCore* core)
13551370
int zone;
13561371

13571372
for (GeodesicSearchInsideIterator it1(*geodesic_search_result,z->level);(zone = it1.next()) >= 0;)
1358-
z->draw(&sPainter, zone, true, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, velf);
1373+
z->draw(&sPainter, zone, true, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, velf, filterMoon, moonCap);
13591374
for (GeodesicSearchBorderIterator it1(*geodesic_search_result,z->level);(zone = it1.next()) >= 0;)
1360-
z->draw(&sPainter, zone, false, rcmag_table, limitMagIndex, core, maxMagStarName,names_brightness, viewportCaps, withAberration, velf);
1375+
z->draw(&sPainter, zone, false, rcmag_table, limitMagIndex, core, maxMagStarName,names_brightness, viewportCaps, withAberration, velf, filterMoon, moonCap);
13611376
}
13621377
exit_loop:
13631378

src/core/modules/ZoneArray.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ template<class Star>
408408
void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsideViewport, const RCMag* rcmag_table,
409409
int limitMagIndex, StelCore* core, int maxMagStarName, float names_brightness,
410410
const QVector<SphericalCap> &boundingCaps,
411-
const bool withAberration, const Vec3f vel) const
411+
const bool withAberration, const Vec3f vel,
412+
const bool filterMoon, SphericalCap moonCap) const
412413
{
413414
StelSkyDrawer* drawer = core->getSkyDrawer();
414415
Vec3f vf;
@@ -474,6 +475,14 @@ void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsid
474475
continue;
475476
}
476477

478+
// If the star is covered by the Moon, don't draw (avoid displaying part of halo of occulted star!)
479+
// TODO: This is a bad test. We should draw the moon into a stencil buffer and check that.
480+
if (filterMoon)
481+
{
482+
if (moonCap.contains(vf))
483+
continue;
484+
}
485+
477486
int extinctedMagIndex = s->getMag();
478487
float twinkleFactor=1.0f; // allow height-dependent twinkle.
479488
if (withExtinction)

src/core/modules/ZoneArray.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ class ZoneArray
102102
const RCMag* rcmag_table, int limitMagIndex, StelCore* core,
103103
int maxMagStarName, float names_brightness,
104104
const QVector<SphericalCap>& boundingCaps,
105-
const bool withAberration, const Vec3f vel) const = 0;
105+
const bool withAberration, const Vec3f vel,
106+
const bool filterMoon, SphericalCap moonCap) const = 0;
106107

107108
//! Get whether or not the catalog was successfully loaded.
108109
//! @return @c true if at least one zone was loaded, otherwise @c false
@@ -186,7 +187,8 @@ class SpecialZoneArray : public ZoneArray
186187
const RCMag *rcmag_table, int limitMagIndex, StelCore* core,
187188
int maxMagStarName, float names_brightness,
188189
const QVector<SphericalCap>& boundingCaps,
189-
const bool withAberration, const Vec3f vel) const Q_DECL_OVERRIDE;
190+
const bool withAberration, const Vec3f vel,
191+
const bool filterMoon, SphericalCap moonCap) const Q_DECL_OVERRIDE;
190192

191193
virtual void scaleAxis() Q_DECL_OVERRIDE;
192194
virtual void searchAround(const StelCore* core, int index,const Vec3d &v,double cosLimFov,

0 commit comments

Comments
 (0)