Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify gridline intersect callbacks #3792

Merged
merged 5 commits into from
Sep 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 47 additions & 77 deletions src/core/modules/GridLinesMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ struct ViewportEdgeIntersectCallbackData
Vec4f textColor;
QString text; // Label to display at the intersection of the lines and screen side
double raAngle; // Used for meridians
double gridStepMeridianRad; // used as rounding threshold
StelCore::FrameType frameType;
};

Expand All @@ -255,7 +256,7 @@ void viewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& directio
const Vec4f tmpColor = d->sPainter->getColor();
d->sPainter->setColor(d->textColor);
const bool withDecimalDegree = StelApp::getInstance().getFlagShowDecimalDegrees();
const bool useOldAzimuth = StelApp::getInstance().getFlagSouthAzimuthUsage();
const bool useSouthAzimuth = StelApp::getInstance().getFlagSouthAzimuthUsage();
const float ppx = static_cast<float>(d->sPainter->getProjector()->getDevicePixelsPerPixel());

const int viewportWidth = d->sPainter->getProjector()->getViewportWidth();
Expand Down Expand Up @@ -288,7 +289,7 @@ void viewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& directio
if (qFuzzyCompare(raAngle, 2*M_PI) && qFuzzyCompare(delta, -M_PI))
textAngle = 0;

if (useOldAzimuth)
if (useSouthAzimuth)
textAngle += M_PI;

if (withDecimalDegree)
Expand All @@ -298,19 +299,12 @@ void viewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& directio

break;
}
case StelCore::FrameObservercentricEclipticJ2000:
case StelCore::FrameObservercentricEclipticOfDate:
case StelCore::FrameGalactic:
case StelCore::FrameSupergalactic:
default:
{
raAngle = d->raAngle;
if (raAngle<0.)
raAngle += 2.*M_PI;
raAngle = StelUtils::fmodpos(d->raAngle, 2.*M_PI);
lon = StelUtils::fmodpos(lon, 2.*M_PI);

if (lon<0.)
lon += 2*M_PI;

if (std::fabs(2.*M_PI-lon)<0.001) // We are at meridian 0
if (std::fabs(2.*M_PI-lon)<d->gridStepMeridianRad/250.) // We are at meridian 0
lon = 0.;

const double delta = raAngle<M_PI ? M_PI : -M_PI;
Expand All @@ -322,42 +316,21 @@ void viewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& directio
if (qFuzzyCompare(raAngle, 2*M_PI) && qFuzzyCompare(delta, -M_PI))
textAngle = 0;

if (withDecimalDegree)
text = StelUtils::radToDecDegStr(textAngle, 4, false, true);
else
text = StelUtils::radToDmsStrAdapt(textAngle);

break;
}
default:
{
raAngle = M_PI-d->raAngle;
lon = M_PI-lon;

if (raAngle<0)
raAngle+=2.*M_PI;

if (lon<0)
lon+=2.*M_PI;

if (std::fabs(2.*M_PI-lon)<0.01) // We are at meridian 0
lon = 0.;

if (std::fabs(lon-raAngle) < 0.01)
textAngle = -raAngle+M_PI;
else
{
const double delta = raAngle<M_PI ? M_PI : -M_PI;
textAngle = -raAngle-delta+M_PI;
}

if (d->frameType==StelCore::FrameFixedEquatorial)
textAngle=2.*M_PI-textAngle;


textAngle=StelUtils::fmodpos(textAngle, 2.*M_PI);
if (withDecimalDegree)
text = StelUtils::radToDecDegStr(textAngle, 4, false, true);
else
text = StelUtils::radToHmsStrAdapt(textAngle);
{
if (QList<StelCore::FrameType>{StelCore::FrameObservercentricEclipticJ2000, StelCore::FrameObservercentricEclipticOfDate,
StelCore::FrameGalactic, StelCore::FrameSupergalactic}.contains(d->frameType))
text = StelUtils::radToDmsStrAdapt(textAngle);
else
text = StelUtils::radToHmsStrAdapt(textAngle);
}
}
}
}
Expand Down Expand Up @@ -408,13 +381,9 @@ void SkyGrid::draw(const StelCore* core) const

// Look for all meridians and parallels intersecting with the disk bounding the viewport
// Check whether the pole are in the viewport
bool northPoleInViewport = false;
bool southPoleInViewport = false;
Vec3f win;
if (prj->project(Vec3f(0,0,1), win) && prj->checkInViewport(win))
northPoleInViewport = true;
if (prj->project(Vec3f(0,0,-1), win) && prj->checkInViewport(win))
southPoleInViewport = true;
const bool northPoleInViewport = (prj->project(Vec3f(0,0,1), win) && prj->checkInViewport(win));
const bool southPoleInViewport = (prj->project(Vec3f(0,0,-1), win) && prj->checkInViewport(win));
// Get the longitude and latitude resolution at the center of the viewport
Vec3d centerV;
prj->unProject(prj->getViewportPosX()+prj->getViewportWidth()/2., prj->getViewportPosY()+prj->getViewportHeight()/2.+1., centerV);
Expand Down Expand Up @@ -461,6 +430,7 @@ void SkyGrid::draw(const StelCore* core) const
ViewportEdgeIntersectCallbackData userData(&sPainter);
userData.textColor = textColor;
userData.frameType = frameType;
userData.gridStepMeridianRad = gridStepMeridianRad;

/////////////////////////////////////////////////
// Draw all the meridians (great circles)
Expand All @@ -473,7 +443,7 @@ void SkyGrid::draw(const StelCore* core) const
for (i=0; i<maxNbIter; ++i)
{
StelUtils::rectToSphe(&lon2, &lat2, fpt);
userData.raAngle = lon2;
userData.raAngle = fabs(lon2)<1.e-12 ? 0. : lon2; // Get rid of stupid noise

meridianSphericalCap.n = fpt^Vec3d(0,0,1);
meridianSphericalCap.n.normalize();
Expand All @@ -487,9 +457,9 @@ void SkyGrid::draw(const StelCore* core) const
rotFpt.transfo4d(rotLon120);
Vec3d rotFpt2=rotFpt;
rotFpt2.transfo4d(rotLon120);
sPainter.drawGreatCircleArc(fpt, rotFpt, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(rotFpt, rotFpt2, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(rotFpt2, fpt, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(fpt, rotFpt, nullptr, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(rotFpt, rotFpt2, nullptr, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(rotFpt2, fpt, nullptr, viewportEdgeIntersectCallback, &userData);
fpt.transfo4d(rotLon);
continue;
}
Expand All @@ -503,8 +473,8 @@ void SkyGrid::draw(const StelCore* core) const
middlePoint*=-1.;

// Draw the arc in 2 sub-arcs to avoid lengths > 180 deg
sPainter.drawGreatCircleArc(p1, middlePoint, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(p2, middlePoint, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(p1, middlePoint, nullptr, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(p2, middlePoint, nullptr, viewportEdgeIntersectCallback, &userData);

fpt.transfo4d(rotLon);
}
Expand All @@ -517,7 +487,7 @@ void SkyGrid::draw(const StelCore* core) const
for (int j=0; j<maxNbIter-i; ++j)
{
StelUtils::rectToSphe(&lon2, &lat2, fpt);
userData.raAngle = lon2;
userData.raAngle = fabs(lon2)<1.e-12 ? 0. : lon2; // Get rid of stupid noise

meridianSphericalCap.n = fpt^Vec3d(0,0,1);
meridianSphericalCap.n.normalize();
Expand All @@ -529,8 +499,8 @@ void SkyGrid::draw(const StelCore* core) const
if (!viewPortSphericalCap.contains(middlePoint))
middlePoint*=-1;

sPainter.drawGreatCircleArc(p1, middlePoint, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(p2, middlePoint, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(p1, middlePoint, nullptr, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(p2, middlePoint, nullptr, viewportEdgeIntersectCallback, &userData);

fpt.transfo4d(rotLon);
}
Expand Down Expand Up @@ -745,9 +715,9 @@ void SkyLine::setSolarSystem(SolarSystem* ss)

void SkyLine::deinit()
{
earth = Q_NULLPTR;
sun = Q_NULLPTR;
moon = Q_NULLPTR;
earth = nullptr;
sun = nullptr;
moon = nullptr;
}

SkyLine::~SkyLine()
Expand Down Expand Up @@ -1014,7 +984,7 @@ void SkyLine::draw(StelCore *core) const
{
ptTgt=part1000; ptTgt.transfo4d(Mat4d::rotation(partZAxis, tickAngle));
if (viewPortSphericalCap.contains(pt0) || viewPortSphericalCap.contains(ptTgt))
sPainter.drawGreatCircleArc(pt0, ptTgt, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR);
sPainter.drawGreatCircleArc(pt0, ptTgt, nullptr, nullptr, nullptr);
if (showLabel)
{
Vec3d ptTgtL=part1000l; ptTgtL.transfo4d(Mat4d::rotation(partZAxis, tickAngle));
Expand All @@ -1036,7 +1006,7 @@ void SkyLine::draw(StelCore *core) const
ptTgt=(y%500 == 0 ? part500 : part100);
ptTgt.transfo4d(Mat4d::rotation(partZAxis, tickAngle));
if (viewPortSphericalCap.contains(pt0) || viewPortSphericalCap.contains(ptTgt))
sPainter.drawGreatCircleArc(pt0, ptTgt, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR);
sPainter.drawGreatCircleArc(pt0, ptTgt, nullptr, nullptr, nullptr);
}
}

Expand Down Expand Up @@ -1071,7 +1041,7 @@ void SkyLine::draw(StelCore *core) const
{
ptTgt=part1000; ptTgt.transfo4d(Mat4d::rotation(partZAxis, tickAngle));
if (viewPortSphericalCap.contains(pt0) || viewPortSphericalCap.contains(ptTgt))
sPainter.drawGreatCircleArc(pt0, ptTgt, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR);
sPainter.drawGreatCircleArc(pt0, ptTgt, nullptr, nullptr, nullptr);
if (showLabel)
{
Vec3d ptTgtL=part1000l; ptTgtL.transfo4d(Mat4d::rotation(partZAxis, tickAngle));
Expand All @@ -1093,7 +1063,7 @@ void SkyLine::draw(StelCore *core) const
ptTgt=(y%500 == 0 ? part500 : part100);
ptTgt.transfo4d(Mat4d::rotation(partZAxis, tickAngle));
if (viewPortSphericalCap.contains(pt0) || viewPortSphericalCap.contains(ptTgt))
sPainter.drawGreatCircleArc(pt0, ptTgt, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR);
sPainter.drawGreatCircleArc(pt0, ptTgt, nullptr, nullptr, nullptr);
}
}

Expand Down Expand Up @@ -1248,7 +1218,7 @@ void SkyLine::draw(StelCore *core) const
end.transfo4d(rotDay);
end10.transfo4d(rotDay);

sPainter.drawGreatCircleArc(start, end, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR);
sPainter.drawGreatCircleArc(start, end, nullptr, nullptr, nullptr);

if (!label.isEmpty() && (
currentFoV<60. // all labels
Expand All @@ -1274,7 +1244,7 @@ void SkyLine::draw(StelCore *core) const
{
if (i%30 == 0 && (viewPortSphericalCap.contains(part0) || viewPortSphericalCap.contains(part30)))
{
sPainter.drawGreatCircleArc(part0, part30, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR);
sPainter.drawGreatCircleArc(part0, part30, nullptr, nullptr, nullptr);

if (showLabel)
{
Expand Down Expand Up @@ -1382,11 +1352,11 @@ void SkyLine::draw(StelCore *core) const
}

else if (i%10 == 0 && (viewPortSphericalCap.contains(part0) || viewPortSphericalCap.contains(part10)))
sPainter.drawGreatCircleArc(part0, part10, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR);
sPainter.drawGreatCircleArc(part0, part10, nullptr, nullptr, nullptr);
else if (i%5 == 0 && (viewPortSphericalCap.contains(part0) || viewPortSphericalCap.contains(part5)))
sPainter.drawGreatCircleArc(part0, part5, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR);
sPainter.drawGreatCircleArc(part0, part5, nullptr, nullptr, nullptr);
else if( viewPortSphericalCap.contains(part0) || viewPortSphericalCap.contains(part1))
sPainter.drawGreatCircleArc(part0, part1, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR);
sPainter.drawGreatCircleArc(part0, part1, nullptr, nullptr, nullptr);
}
part0.transfo4d(rotZ1);
part1.transfo4d(rotZ1);
Expand Down Expand Up @@ -1431,8 +1401,8 @@ void SkyLine::draw(StelCore *core) const
}
}
// Now draw through a middle point.
sPainter.drawGreatCircleArc(p1, pHori, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(p2, pHori, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(p1, pHori, nullptr, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(p2, pHori, nullptr, viewportEdgeIntersectCallback, &userData);
}
else if (line_type!=ECLIPTIC_WITH_DATE) // Exclude the pseudo-line ecliptic with date marks: This has only partitions!
{
Expand All @@ -1447,9 +1417,9 @@ void SkyLine::draw(StelCore *core) const
rotFpt.transfo4d(rotLon120);
Vec3d rotFpt2=rotFpt;
rotFpt2.transfo4d(rotLon120);
sPainter.drawGreatCircleArc(fpt, rotFpt, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(rotFpt, rotFpt2, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(rotFpt2, fpt, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(fpt, rotFpt, nullptr, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(rotFpt, rotFpt2, nullptr, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(rotFpt2, fpt, nullptr, viewportEdgeIntersectCallback, &userData);
}
}
else
Expand All @@ -1460,8 +1430,8 @@ void SkyLine::draw(StelCore *core) const
middlePoint*=-1.;

// Draw the arc in 2 sub-arcs to avoid lengths > 180 deg
sPainter.drawGreatCircleArc(p1, middlePoint, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(p2, middlePoint, Q_NULLPTR, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(p1, middlePoint, nullptr, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(p2, middlePoint, nullptr, viewportEdgeIntersectCallback, &userData);
}
}

Expand Down
Loading