From 94f6bd583121323fa3fa381b87bb5f5c5822a9cc Mon Sep 17 00:00:00 2001 From: Georg Zotti Date: Sat, 9 Oct 2021 15:34:37 +0200 Subject: [PATCH] Attempt to filter away occulted stars. - does not work properly: tessellated Moon sphere is often smaller than its computed radius! --- src/core/modules/StarMgr.cpp | 19 +++++++++++++++++-- src/core/modules/ZoneArray.cpp | 11 ++++++++++- src/core/modules/ZoneArray.hpp | 6 ++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/core/modules/StarMgr.cpp b/src/core/modules/StarMgr.cpp index e7b06027718eba..337636b5655016 100644 --- a/src/core/modules/StarMgr.cpp +++ b/src/core/modules/StarMgr.cpp @@ -47,6 +47,7 @@ #include "ConstellationMgr.hpp" #include "Planet.hpp" #include "StelUtils.hpp" +#include "SolarSystem.hpp" #include #include @@ -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) @@ -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: diff --git a/src/core/modules/ZoneArray.cpp b/src/core/modules/ZoneArray.cpp index 233e9eead948c0..44119b933b754d 100644 --- a/src/core/modules/ZoneArray.cpp +++ b/src/core/modules/ZoneArray.cpp @@ -412,7 +412,8 @@ template void SpecialZoneArray::draw(StelPainter* sPainter, int index, bool isInsideViewport, const RCMag* rcmag_table, int limitMagIndex, StelCore* core, int maxMagStarName, float names_brightness, bool designationUsage, const QVector &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; @@ -478,6 +479,14 @@ void SpecialZoneArray::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) diff --git a/src/core/modules/ZoneArray.hpp b/src/core/modules/ZoneArray.hpp index 811e0d4dffc40d..49a94dfbc5a951 100644 --- a/src/core/modules/ZoneArray.hpp +++ b/src/core/modules/ZoneArray.hpp @@ -103,7 +103,8 @@ class ZoneArray const RCMag* rcmag_table, int limitMagIndex, StelCore* core, int maxMagStarName, float names_brightness, bool designationUsage, const QVector& 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 @@ -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& 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,