Skip to content

Commit 567ecc9

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 b3b8a85 commit 567ecc9

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
@@ -47,6 +47,7 @@
4747
#include "ConstellationMgr.hpp"
4848
#include "Planet.hpp"
4949
#include "StelUtils.hpp"
50+
#include "SolarSystem.hpp"
5051

5152
#include <QTextStream>
5253
#include <QFile>
@@ -1271,6 +1272,20 @@ void StarMgr::draw(StelCore* core)
12711272

12721273
// Prepare a table for storing precomputed RCMag for all ZoneArrays
12731274
RCMag rcmag_table[RCMAG_TABLE_SIZE];
1275+
1276+
// Try to filter away stars hidden by the Moon!
1277+
bool filterMoon=false;
1278+
PlanetP moon = GETSTELMODULE(SolarSystem)->getMoon();
1279+
Vec3d moonPos=moon->getJ2000EquatorialPos(core);
1280+
const double moonRadius = moon->getEquatorialRadius() * moon->getSphereScale();
1281+
double angularSize = atan2(moonRadius, moonPos.length());
1282+
moonPos.normalize();
1283+
SphericalCap moonCap(moonPos, cos(angularSize));
1284+
for (auto cap : viewportCaps)
1285+
{
1286+
if (cap.intersects(moonCap))
1287+
filterMoon=true;
1288+
}
12741289

12751290
// Draw all the stars of all the selected zones
12761291
for (const auto* z : gridLevels)
@@ -1314,9 +1329,9 @@ void StarMgr::draw(StelCore* core)
13141329
int zone;
13151330

13161331
for (GeodesicSearchInsideIterator it1(*geodesic_search_result,z->level);(zone = it1.next()) >= 0;)
1317-
z->draw(&sPainter, zone, true, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, flagDesignations, viewportCaps, withAberration, velf);
1332+
z->draw(&sPainter, zone, true, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, flagDesignations, viewportCaps, withAberration, velf, filterMoon, moonCap);
13181333
for (GeodesicSearchBorderIterator it1(*geodesic_search_result,z->level);(zone = it1.next()) >= 0;)
1319-
z->draw(&sPainter, zone, false, rcmag_table, limitMagIndex, core, maxMagStarName,names_brightness, flagDesignations, viewportCaps, withAberration, velf);
1334+
z->draw(&sPainter, zone, false, rcmag_table, limitMagIndex, core, maxMagStarName,names_brightness, flagDesignations, viewportCaps, withAberration, velf, filterMoon, moonCap);
13201335
}
13211336
exit_loop:
13221337

src/core/modules/ZoneArray.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ template<class Star>
412412
void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsideViewport, const RCMag* rcmag_table,
413413
int limitMagIndex, StelCore* core, int maxMagStarName, float names_brightness, bool designationUsage,
414414
const QVector<SphericalCap> &boundingCaps,
415-
const bool withAberration, const Vec3f vel) const
415+
const bool withAberration, const Vec3f vel,
416+
const bool filterMoon, SphericalCap moonCap) const
416417
{
417418
StelSkyDrawer* drawer = core->getSkyDrawer();
418419
Vec3f vf;
@@ -478,6 +479,14 @@ void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsid
478479
continue;
479480
}
480481

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

src/core/modules/ZoneArray.hpp

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

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

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

0 commit comments

Comments
 (0)