Skip to content

Commit

Permalink
Attempt to filter away occulted stars.
Browse files Browse the repository at this point in the history
- does not work properly: tessellated Moon sphere is often smaller than its computed radius!
  • Loading branch information
gzotti committed Oct 9, 2021
1 parent 2648302 commit 94f6bd5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
19 changes: 17 additions & 2 deletions src/core/modules/StarMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "ConstellationMgr.hpp"
#include "Planet.hpp"
#include "StelUtils.hpp"
#include "SolarSystem.hpp"

#include <QTextStream>
#include <QFile>
Expand Down Expand Up @@ -1271,6 +1272,20 @@ void StarMgr::draw(StelCore* core)

// Prepare a table for storing precomputed RCMag for all ZoneArrays
RCMag rcmag_table[RCMAG_TABLE_SIZE];

// Try to filter away stars hidden by the Moon!
bool filterMoon=false;
PlanetP moon = GETSTELMODULE(SolarSystem)->getMoon();
Vec3d moonPos=moon->getJ2000EquatorialPos(core);
const double moonRadius = moon->getEquatorialRadius() * moon->getSphereScale();
double angularSize = atan2(moonRadius, moonPos.length());
moonPos.normalize();
SphericalCap moonCap(moonPos, cos(angularSize));
for (auto cap : viewportCaps)
{
if (cap.intersects(moonCap))
filterMoon=true;
}

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

for (GeodesicSearchInsideIterator it1(*geodesic_search_result,z->level);(zone = it1.next()) >= 0;)
z->draw(&sPainter, zone, true, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, flagDesignations, viewportCaps, withAberration, velf);
z->draw(&sPainter, zone, true, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, flagDesignations, viewportCaps, withAberration, velf, filterMoon, moonCap);
for (GeodesicSearchBorderIterator it1(*geodesic_search_result,z->level);(zone = it1.next()) >= 0;)
z->draw(&sPainter, zone, false, rcmag_table, limitMagIndex, core, maxMagStarName,names_brightness, flagDesignations, viewportCaps, withAberration, velf);
z->draw(&sPainter, zone, false, rcmag_table, limitMagIndex, core, maxMagStarName,names_brightness, flagDesignations, viewportCaps, withAberration, velf, filterMoon, moonCap);
}
exit_loop:

Expand Down
11 changes: 10 additions & 1 deletion src/core/modules/ZoneArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ template<class Star>
void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsideViewport, const RCMag* rcmag_table,
int limitMagIndex, StelCore* core, int maxMagStarName, float names_brightness, bool designationUsage,
const QVector<SphericalCap> &boundingCaps,
const bool withAberration, const Vec3f vel) const
const bool withAberration, const Vec3f vel,
const bool filterMoon, SphericalCap moonCap) const
{
StelSkyDrawer* drawer = core->getSkyDrawer();
Vec3f vf;
Expand Down Expand Up @@ -478,6 +479,14 @@ void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsid
continue;
}

// If the star is covered by the Moon, don't draw (avoid displaying part of halo of occulted star!)
// TODO: This is a bad test. We should draw the moon into a stencil buffer and check that.
if (filterMoon)
{
if (moonCap.contains(vf))
continue;
}

int extinctedMagIndex = s->getMag();
float twinkleFactor=1.0f; // allow height-dependent twinkle.
if (withExtinction)
Expand Down
6 changes: 4 additions & 2 deletions src/core/modules/ZoneArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class ZoneArray
const RCMag* rcmag_table, int limitMagIndex, StelCore* core,
int maxMagStarName, float names_brightness, bool designationUsage,
const QVector<SphericalCap>& boundingCaps,
const bool withAberration, const Vec3f vel) const = 0;
const bool withAberration, const Vec3f vel,
const bool filterMoon, SphericalCap moonCap) const = 0;

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

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

0 comments on commit 94f6bd5

Please sign in to comment.