Skip to content

Commit 0548396

Browse files
committed
Avoid flickering of borderline ellipses
- also docfix - make option immediately permanent
1 parent ec9458e commit 0548396

4 files changed

Lines changed: 21 additions & 18 deletions

File tree

src/core/StelPainter.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,20 +1740,18 @@ void StelPainter::drawCircle(float x, float y, float r)
17401740
// rx: radius in x axis
17411741
// ry: radius in y axis
17421742
// angle rotation (counterclockwise), radians [0..2pi]
1743-
void StelPainter::drawEllipse(float x, float y, float rX, float rY, float angle)
1743+
void StelPainter::drawEllipse(double x, double y, double rX, double rY, double angle)
17441744
{
1745-
if (rX <= 1.0f || rY <= 1.0f)
1745+
if (rX <= 1.0 || rY <= 1.0)
17461746
return;
17471747
// Taken largely from Nebula::renderEllipticMarker()
1748-
// Take into account device pixel density and global scale ratio, as we are drawing 2D stuff.
1749-
//const auto pixelRatio = getProjector()->getDevicePixelsPerPixel();
1750-
const auto scale = StelApp::getInstance().getGlobalScalingRatio();
1748+
const double scale = StelApp::getInstance().getGlobalScalingRatio();
17511749
rX *= scale;
17521750
rY *= scale;
17531751

17541752
//const float radiusY = 0.35 * size;
17551753
//const float radiusX = aspectRatio * radiusY;
1756-
const int numPoints = std::lround(std::clamp(qMax(rX, rY)/3, 32.f, 1024.f));
1754+
const int numPoints = std::lround(std::clamp(qMax(rX, rY)/3, 32., 1024.));
17571755
std::vector<float> vertexData;
17581756
vertexData.reserve(numPoints*2);
17591757
const float*const cossin = StelUtils::ComputeCosSinTheta(numPoints);
@@ -1769,7 +1767,7 @@ void StelPainter::drawEllipse(float x, float y, float rX, float rY, float angle)
17691767
}
17701768
const auto vertCount = vertexData.size() / 2;
17711769
setLineSmooth(true);
1772-
setLineWidth(scale * std::clamp(qMax(rX, rY)/40, 1.f, 2.f));
1770+
setLineWidth(scale * std::clamp(qMax(rX, rY)/40, 1., 2.));
17731771
enableClientStates(true);
17741772
setVertexPointer(2, GL_FLOAT, vertexData.data());
17751773
drawFromArray(StelPainter::LineLoop, vertCount, 0, false);

src/core/StelPainter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class StelPainter : protected QOpenGLFunctions
139139
//! @param rx: radius in x axis
140140
//! @param ry: radius in y axis
141141
//! @param angle: rotation (counterclockwise), radians [0..2pi]
142-
void drawEllipse(float x, float y, float rx, float ry, float angle);
142+
void drawEllipse(double x, double y, double rx, double ry, double angle);
143143

144144
//! Draw a square using the current texture at the given projected 2d position.
145145
//! This method is not thread safe.

src/core/modules/NomenclatureItem.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -392,25 +392,29 @@ void NomenclatureItem::draw(StelCore* core, StelPainter *painter)
392392
const float brightness=(nType>=NomenclatureItem::niSpecialPointPole ? 0.5f : (solarAltitude<0. ? 0.25f : 1.0f));
393393
painter->setColor(color*brightness, labelsFader.getInterstate());
394394
painter->drawCircle(static_cast<float>(srcPos[0]), static_cast<float>(srcPos[1]), 2.f);
395-
if (flagOutlineCraters && (nType==niCrater || nType==niSatelliteFeature)) // probably all satellite features are satellite craters
395+
// Highlight a few mostly circular classes with ellipses:
396+
// - Craters
397+
// - Satellite features (presumably all of these are satellite craters)
398+
// - Lunar Maria. Mare Frigoris is elongated, and an ellipse would extend over the Lunar rim.
399+
if (flagOutlineCraters && (nType==niCrater || nType==niSatelliteFeature || (nType==niMare && englishName!="Mare Frigoris")))
396400
{
397401
// Compute aspectRatio and angle from position of planet and own position, parallactic angle, ...
398-
double ra, de, raPl, dePl;
399-
StelUtils::rectToSphe(&ra, &de, XYZ);
400-
StelUtils::rectToSphe(&raPl, &dePl, equPos);
401-
const double distDegrees=StelLocation::distanceDegrees(raPl*M_180_PIf, dePl*M_180_PIf, ra*M_180_PIf, de*M_180_PIf);
402+
const double distDegrees=equPos.angle(XYZ)*M_180_PI;
402403
const double plRadiusDeg=planet->getAngularRadius(core);
403-
const double sinDistCenter=distDegrees/plRadiusDeg; // 0...1
404-
if (sinDistCenter<1.f)
404+
const double sinDistCenter= distDegrees/plRadiusDeg; // should be 0...1, but 1 causes a flicker
405+
if (sinDistCenter<0.9999)
405406
{
406-
const double angleDistCenterRad=asin(sinDistCenter); // 0..pi/2 on the lunar/planet sphere
407+
const double angleDistCenterRad=asin(qMin(0.9999, sinDistCenter)); // 0..pi/2 on the lunar/planet sphere
407408
const double aspectRatio=cos(angleDistCenterRad);
409+
double ra, de, raPl, dePl;
410+
StelUtils::rectToSphe(&ra, &de, XYZ);
411+
StelUtils::rectToSphe(&raPl, &dePl, equPos);
408412
const double angle=atan2(ra-raPl, de-dePl);
409413
const double par = static_cast<double>(getParallacticAngle(core));
410-
painter->drawEllipse(static_cast<float>(srcPos[0]), static_cast<float>(srcPos[1]), screenRadius, screenRadius*aspectRatio, angle-par );
414+
painter->drawEllipse(srcPos[0], srcPos[1], screenRadius, screenRadius*qMax(0.0001,aspectRatio), angle-par );
411415
}
412416
//else
413-
// qWarning() << "Distance greater 1 encountered for crater " << englishName << "at " << longitude << "/" << latitude;
417+
// qWarning() << "Sine of Distance" << sinDistCenter << ">0.99975 encountered for crater " << englishName << "at " << longitude << "/" << latitude;
414418
}
415419
painter->drawText(static_cast<float>(srcPos[0]), static_cast<float>(srcPos[1]), nameI18n, 0, 5.f, 5.f, false);
416420
}

src/core/modules/NomenclatureMgr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ int NomenclatureMgr::getTerminatorMaxAltitude() const
557557
void NomenclatureMgr::setFlagOutlineCraters(bool b)
558558
{
559559
NomenclatureItem::flagOutlineCraters = b;
560+
conf->setValue("astro/flag_planets_nomenclature_outline_craters", b);
560561
emit flagOutlineCratersChanged(b);
561562
}
562563

0 commit comments

Comments
 (0)